"%e" floating point format and exponent digits

David Nadlinger see at klickverbot.at
Wed Feb 20 14:04:31 PST 2013


In Phobos, there are quite a few unit tests (std.format, 
std.json, ...) which assume that the %e floating point format 
zero-pads the exponent to (at least) two digits.

However, the printf-family functions in the MSVC and MinGW 
runtimes pad the exponent to *three* digits. For example, 
1.223e+24 is printed as "1.223e+024".

By extension, this also applies to the std.format (and thus 
std.stdio) floating point code, which relies on snprintf.

What is the correct fix here? Adjusting those unit tests? Doing 
something crazy along the lines of "if (result[$-4] == 'e' && 
result[$-3] == '0') { /+ trim zero +/ }"? (How) Is this handled 
on DMD/Win64?

The best way would probably be to just implement floating point 
printing in D as well, to isolate our code from such C runtime 
implementation differences.

David


More information about the Digitalmars-d mailing list