From: Peter R. <pe...@ly...> - 2013-12-10 09:16:26
|
On 2013-12-09 16:32, Keith Marshall wrote: > On 09/12/13 13:50, Peter Rosin wrote: >> Relying on GCC and the MS runtime to agree on rounding >> rules in every possible combination seems fragile, no? >> >> I don't know if the rounding rule is standardized in the relevant >> contexts. I don't know if strtod is required to round correctly >> down to the last bit. > > AIUI, it is not; I don't even think that IEEE 754 requires an input > routine to choose the best approximation -- exact representations are > comparatively rare. The best we can hope for is +/- 1 variation in the > least significant bit of the mantissa representation. Such variations > are not a bug, and OP should desist in his effort to classify them as such. I completely agree that you should expect to be disappointed if you expect anything better than that. However, are you sure it is not a bug? Consider this quote from [1]: If the subject sequence has the decimal form and at most DECIMAL_DIG (defined in <float.h>) significant digits, the result should be correctly rounded. (DECIMAL_DIG has to be 10 or higher, it is probably 15) The "subject sequence" in the given example is 95e20, and I see only two significant decimal digits, i.e. 95. That's nowhere near 15, or even 10 for that matter. So, this looks suspiciously like buggy behaviour to me, assuming everything is set to round to nearest (which seems plausible). Cheers, Peter [1] http://pubs.opengroup.org/onlinepubs/009695299/functions/strtod.html |