X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fstlplus%2Fstrings%2Fstring_float.hpp;fp=src%2Fstlplus%2Fstrings%2Fstring_float.hpp;h=797d4a4d04014b930c003185b2ffcf6c05ed7d2f;hb=6b0a0d0efafe34d48ab344fca3b479553bd4e62c;hp=0000000000000000000000000000000000000000;hpb=85783316365181491a3e3c0c63659972477cebba;p=chaz%2Fyoink diff --git a/src/stlplus/strings/string_float.hpp b/src/stlplus/strings/string_float.hpp new file mode 100644 index 0000000..797d4a4 --- /dev/null +++ b/src/stlplus/strings/string_float.hpp @@ -0,0 +1,55 @@ +#ifndef STLPLUS_STRING_FLOAT +#define STLPLUS_STRING_FLOAT +//////////////////////////////////////////////////////////////////////////////// + +// Author: Andy Rushton +// Copyright: (c) Southampton University 1999-2004 +// (c) Andy Rushton 2004-2009 +// License: BSD License, see ../docs/license.html + +// Convert a float/double to/from string + +//////////////////////////////////////////////////////////////////////////////// +#include "strings_fixes.hpp" +#include "format_types.hpp" +#include +#include + +namespace stlplus +{ + + //////////////////////////////////////////////////////////////////////////////// + // convert a real type to string + //////////////////////////////////////////////////////////////////////////////// + + // Only decimal radix is supported + + // The way in which the number is displayed is defined in radix_types.hpp + // Using any other value for the display type causes std::invalid_argument to be thrown + + std::string float_to_string(float f, + real_display_t display = display_mixed, + unsigned width = 0, + unsigned precision = 6) + throw(std::invalid_argument); + + std::string double_to_string(double f, + real_display_t display = display_mixed, + unsigned width = 0, + unsigned precision = 6) + throw(std::invalid_argument); + + //////////////////////////////////////////////////////////////////////////////// + // Convert a string to a floating-point type + + float string_to_float(const std::string& value) + throw(std::invalid_argument); + + double string_to_double(const std::string& value) + throw(std::invalid_argument); + + //////////////////////////////////////////////////////////////////////////////// + +} // end namespace stlplus + +#endif