0

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 ?

Abruzzo Forte e Gentile
  • 14,423
  • 28
  • 99
  • 173
  • quote: "C requires that if the exponent is representable using only one or two digits, then only two digits are to be printed." - the number of digits in the exponent varies anyway on the size of the number. maybe you try to solve a problem on the wrong side. what is the reason for requireing 2 digits? – skeller Aug 07 '18 at 17:50
  • What happens when the exponent is bigger , e+20 (2^70) or e+200 (2^700)? I assume it works correctly? Does your xml really care, or are you trying to preserve your regression test cases? – Gem Taylor Aug 07 '18 at 19:21
  • Could you provide a minimal working example? –  Aug 07 '18 at 20:35
  • for big numbers works fine. I was just trying to find an easy way to continue supporting the old way of outputting doubles with e+002 – Abruzzo Forte e Gentile Aug 08 '18 at 09:03

1 Answers1

0

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.

Community
  • 1
  • 1
Gem Taylor
  • 5,381
  • 1
  • 9
  • 27
  • what you are saying is correct. I read the same..problem is that I can't find neither _set_output_format nor _TWO_DIGIT_EXPONENT anywhere in Visual Studio 2017...though given the name it seems that this function was put in place to go fom e+003 to +002.. What I need is possibly the old behavior. – Abruzzo Forte e Gentile Aug 08 '18 at 12:46