This is the mail archive of the
mailing list for the GCC project.
Re: Bug in std::floor?
On Fri, 10 Nov 2017, Nil Geisweiller wrote:
On 11/09/2017 05:53 PM, Vincent Lefevre wrote:> For instance:
int main (void)
double x = 1.7;
printf ("%.30g\n", x);
printf ("%.30g\n", 100 * x);
printf ("%.30g\n", floor (100 * x));
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.