Github user ozymaxx commented on a diff in the pull request: https://github.com/apache/thrift/pull/1496#discussion_r175284886 --- Diff: compiler/cpp/src/thrift/generate/t_generator.h --- @@ -268,6 +271,30 @@ class t_generator { return out.str(); } + const std::string emit_double_as_string(const double value) { + std::stringstream double_output_stream; + // sets the maximum precision: http://en.cppreference.com/w/cpp/io/manip/setprecision + // sets the output format to fixed: http://en.cppreference.com/w/cpp/io/manip/fixed (not in scientific notation) + double_output_stream << std::setprecision(std::numeric_limits<double>::digits10 + 1); + + #ifdef _MSC_VER + // strtod is broken in MSVC compilers older than 2015, so std::fixed fails to format a double literal. + // more details: https://blogs.msdn.microsoft.com/vcblog/2014/06/18/ + // c-runtime-crt-features-fixes-and-breaking-changes-in-visual-studio-14-ctp1/ + // and + // http://www.exploringbinary.com/visual-c-plus-plus-strtod-still-broken/ + #if _MSC_VER >= MSC_2015_VER + double_output_stream << std::fixed; + #endif + #else + double_output_stream << std::fixed; --- End diff -- No, in both cases it should use `std::fixed`, that outputs the fixed floating point representation of the number. But if the MSVC compiler is older than 2015, that function is broken, and should not be called. In short, we want the compiler to generate the doubles in the fixed floating point representation if possible. On the Erlang side, if the compiler is older than 2015, we want the compiler to use `std::scientific` since there can be cases where the mantissa is being output as integer, which is illegal. `std::scientific` always outputs the floating points numbers with a floating point mantissa. But if it is 2015 or later, `std::fixed` works correctly and can be used to get rid of the exponent representation.
---