lua-users home
lua-l archive

Re: Why do some math functions return -0

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Tony Finch <dot@dotat.at> writes:
> It looks like gcc on the powerpc isn't implementing IEEE 754 rounding
> modes correctly or consistently with -O2. If I recompile Lua without
> optimisation then the negative zeroes go away.
I tried your prog on an x86-64 system, with a recent trunk version of
gcc, and also using clang/llvm... :) All showed the same behavior
("correct" with no optimization flags, "incorrect" with -O2).
The gcc devs seem to be aware of the issue anyway:
`-frounding-math'
 Disable transformations and optimizations that assume default
 floating point rounding behavior. This is round-to-zero for all
 floating point to integer conversions, and round-to-nearest for
 all other arithmetic truncations. This option should be specified
 for programs that change the FP rounding mode dynamically, or that
 may be executed with a non-default rounding mode. This option
 disables constant folding of floating point expressions at
 compile-time (which may be affected by rounding mode) and
 arithmetic transformations that are unsafe in the presence of
 sign-dependent rounding modes.
 The default is `-fno-rounding-math'.
 This option is experimental and does not currently guarantee to
 disable all GCC optimizations that are affected by rounding mode.
 Future versions of GCC may provide finer control of this setting
 using C99's `FENV_ACCESS' pragma. This command line option will
 be used to specify the default state for `FENV_ACCESS'.
[If you think it's really a bug, I guess a bug report might help...
you've already got a nice small test case! :]
-Miles
-- 
[|nurgle|] ddt- demonic? so quake will have an evil kinda setting? one that
 will make every christian in the world foamm at the mouth?
[iddt] nurg, that's the goal

AltStyle によって変換されたページ (->オリジナル) /