Should rand() return a RAND_MAX value for 32 bit target?
Liu Hao
lh_mouse@126.com
Sat Sep 22 13:52:00 GMT 2018
在 2018/9/22 18:08, Vincent Lefevre 写道:
> Bug reported here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87390
> (note that the tests do not involve constants, these are just about
> implicit type conversions).
>
That's about contraction. The behavior in the OP can only be observed
when no optimization is enabled (i.e. with `-O0`) or when strict
standard compliance is requested (i.e. with `-std=c99` or `-ansi`) and
no `-ffp-contract=fast` is in effect.
It is irrelevant to this issue. Contraction is about what happens within
a floating-point operation, but in your program (the standard says)
`2147483647` is converted to type `float` before the floating-point
comparison, so it behaves as if you had added a cast like `f ==
(float)2147483647`. This implicit conversion can be observed by
compiling the program in question with `-Wconversion`. You already had
precision loss BEFORE the comparison which is irrecoverable by any
evaluation method.
--
Best regards,
LH_Mouse
More information about the Gcc-help
mailing list