Re: Should rand() return a RAND_MAX value for 32 bit target?

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

 



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@xxxxxxxxxx> - 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)



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux