i'm compiling , running following program in 32 , 64 bit platforms:
int main() { double y = 8.34214e08; double z = 1.25823e45; return y * z == 8.34214e08 * 1.25823e45; } while in 64bit result expected (the values same , exit code non-zero) in 32bit seems there little difference between value calculated @ compile time, right hand side of comparison, , left side computed @ runtime.
is bug in compiler or there logical explanation?
edit: different why comparing double , float leads unexpected result? because here values double.
ieee-754 allows intermediate computations done in greater precision (emphasis mine).
(ieee-754:2008) "a language standard should define, , require implementations provide, attributes allow , disallow value-changing optimizations, separately or collectively, block. these optimizations might include, not limited to: [...] use of wider intermediate results in expression evaluation."
in case example on ia-32, double values stored in x87 fpu registers greater precision (80-bit instead of 64). comparing multiplication done on double precision multiplication done on double-extended precision.
for example, on x64 result 1 (the x87 fpu not used sse used instead), adding gcc option -mfpmath=387 use x87 makes result change 0 on machine.
and if wonder if allowed c, is:
(c99, 6.3.1.p8) "the values of floating operands , of results of floating expressions may represented in greater precision , range required type;"
Comments
Post a Comment