Should rand() return a RAND_MAX value for 32 bit target?
Vincent Lefevre
vincent+gcc@vinc17.org
Thu Sep 20 15:05:00 GMT 2018
Actually, there may be a bug with -m32:
#include <stdio.h>
#include <float.h>
int main (void)
{
float f = 2147483646;
printf ("FLT_EVAL_METHOD = %d\n", (int) FLT_EVAL_METHOD);
if (f == 2147483647)
{
printf("%.20g\n", (double) f);
}
return 0;
}
$ gcc -std=c99 -m32 -O tst.c -o tst
$ ./tst
FLT_EVAL_METHOD = 2
2147483648
Since FLT_EVAL_METHOD = 2, float_t is long double, thus shouldn't
2147483647 be converted to long double directly (as f is regarded
as an operand of type long double), so that the result of the
equality test should be false?
The C standard says for FLT_EVAL_METHOD = 2: "evaluate all operations
and constants to the range and precision of the long double type".
^^^^^^^^^^^^^
Converting f first to float is contrary to the idea behind
FLT_EVAL_METHOD = 2, which is to avoid loss of precision in
intermediate operations.
--
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
More information about the Gcc-help
mailing list