Re: Bug in std::floor?

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

 



On Fri, 10 Nov 2017, Nil Geisweiller wrote:

On 11/09/2017 05:53 PM, Vincent Lefevre wrote:> For instance:

#include <stdio.h>
#include <math.h>

int main (void)
{
   double x = 1.7;

   printf ("%.30g\n", x);
   printf ("%.30g\n", 100 * x);
   printf ("%.30g\n", floor (100 * x));
   return 0;
}

outputs:

1.69999999999999995559107901499
170
170

Indeed! I would really like to have a look at the floor implementation, but it has proven difficult. It calls __builtin_floor, that is no where to be found. It seems to be implemented in gcc/builtins.c but it's too obfuscated for me to understand.

Look at the generated asm? Here, it is a single instruction: roundsd.
For constant folding, you would want to look at real.c.
builtins.c essentially delegates the work to each target to specify how floor should be expanded, and generates a call to the system's C library when that's not specified.

--
Marc Glisse



[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