customizing the number of digits in exponent in boost multiprecision

338 Views Asked by At

We've just migrated to Visual Studio 2017 and due to the change described here the serialized output of a double value using std::scientific does not carry anymore 2 digits in the exponent but only one.

 BEOFRE: 5.49000000000000000e+002
 NOW   : 5.49000000000000000e+02

We use boost::serialization to serialize to XML.

We were thinking to switch to boost::multiprecision to handle bigger number, but still we have to fix this issue with the digits in the exponent.

Is there any way to get back to the old notation 'e+002' or even customize it with boost::multiprecision ?

1

There are 1 best solutions below

1
On

Reading the relevant section, it appears that _set_output_format with not _TWO_DIGIT_EXPONENT might give the old behaviour?

Exponent formatting The %e and %E format specifiers format a floating point number as a decimal mantissa and exponent. The %g and %G format specifiers also format numbers in this form in some cases. In previous versions, the CRT would always generate strings with three-digit exponents. For example, printf("%e\n", 1.0) would print 1.000000e+000. This was incorrect: C requires that if the exponent is representable using only one or two digits, then only two digits are to be printed.

In Visual Studio 2005 a global conformance switch was added: _set_output_format. A program could call this function with the argument _TWO_DIGIT_EXPONENT, to enable conforming exponent printing. The default behavior has been changed to the standards-conforming exponent printing mode.