I'm working on a cross-platform app for Windows and Mac OS X, and I have a problem with two standard C library functions:
strtod()
- string-to-double conversionsprintf()
- when used for outputting double-precision floating point numbers)
Their GCC and MSVC versions return different results, in some digits of mantissa. But it plays a cruicial role if the exponent value is large. An example:
MSVC: 9,999999999999999500000000000000e+032
GCC: 9,999999999999999455752309870428e+32
MSVC: 9,999999999999999500000000000000e+033
GCC: 9,999999999999999455752309870428e+33
MSVC: 9,999999999999999700000000000000e+034
GCC: 9,999999999999999686336610791798e+34
The input test numbers have an identical binary representation under MSVC and GCC.
I'm looking for a well-tested cross-platform open-source implementation of those functions, or just for a pair of functions that would correctly and consistently convert double to string and back.
I've already tried the clib GCC implementation, but the code is too long and too dependent on other source files, so I expect the adaptation to be difficult.
What implementations of string-to-double and double-to-string functions would you recommend?