diff options
author | Jude Melton-Houghton <jwmhjwmh@gmail.com> | 2023-01-12 14:12:31 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-12 14:12:31 -0500 |
commit | 5f2925c59cb3b6fa580e565e2d5a4dad3c400eeb (patch) | |
tree | fda5e57028a5f47f2914ad6670c1d765638e8c47 /src/util | |
parent | 956026bb6b20b8f4810404aaa373abb746f73910 (diff) | |
download | minetest-5f2925c59cb3b6fa580e565e2d5a4dad3c400eeb.tar.xz |
Increase `ftos` precision (#13141)
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/string.h | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/src/util/string.h b/src/util/string.h index 2f3c2615b..27e2f094d 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include <string> #include <cstring> #include <vector> +#include <limits> #include <map> #include <sstream> #include <iomanip> @@ -429,14 +430,11 @@ inline std::string itos(s32 i) { return std::to_string(i); } /// Returns a string representing the decimal value of the 64-bit value \p i. inline std::string i64tos(s64 i) { return std::to_string(i); } -// std::to_string uses the '%.6f' conversion, which is inconsistent with -// std::ostream::operator<<() and impractical too. ftos() uses the -// more generic and std::ostream::operator<<()-compatible '%G' format. -/// Returns a string representing the decimal value of the float value \p f. +/// Returns a string representing the exact decimal value of the float value \p f. inline std::string ftos(float f) { std::ostringstream oss; - oss << f; + oss << std::setprecision(std::numeric_limits<float>::max_digits10) << f; return oss.str(); } |