4 ms·
Wait, now I'm confused. If what you want is reproducibility, why does it matter that the rounding be correct? It seems to me that what matters in this case is
by lisper 4y ago
Wait, now I'm confused. If what you want is reproducibility, why does it matter that the rounding be correct? It seems to me that what matters in this case is that the rounding conform to some standard or specification. Why should it matter what that standard actually is?
- MauranKilom 4y agoSure, you could invent a different standard, but what are you going to write into it? "If you input 0.1 into atan, the result should round up when outputting 5 digits, down with 8 digits and up with 12 digits"? Also, "round up" is not any easier than "round correctly" if you require it to be consistent. Say you compute a result like 9.004 and want to round to two digits - if the exact result would have been 8.991, then rounding your computation as 9.01 is different from the standard-specified result of 9.00. So your standard would literally have to specify the desired output for every combination of operation, input, and output precision - obviously impossible.
- jabl 4y agoOne usecase, for instance, is if you're writing a compiler and you want to constant propagate floating point operations, and the compile host doesn't necessarily support the same FP formats the target hardware does. But you still want the results to be the same as if you compute it on the target HW at runtime (barring usage of a "damn-IEEE754-just-go-faster" compile option). This, FWIW, is what GCC uses MPFR for.
- adgjlsfhk1 4y agoNote that GCC actually has a bunch of bugs related to this where it will give you different results depending on whether a value gets computed at compile time or runtime.
- jabl 4y agoBeen a while since I was actively involved in GCC development, but back then most issues like this AFAIR were due to math functions and not basic arithmetic. GCC doesn't control the target libm, and correctly rounded libm's are rare and much slower than ones which permit a bit more slop in the results.