This is the mail archive of the
mailing list for the GCC project.
Re: Weird constant folding of __builtin_remainder() with -frounding-math
- From: Marc Glisse <marc dot glisse at inria dot fr>
- To: GCC Development <gcc at gcc dot gnu dot org>
- Cc: FX <fxcoudert at gmail dot com>
- Date: Wed, 20 Nov 2013 16:51:10 +0100 (CET)
- Subject: Re: Weird constant folding of __builtin_remainder() with -frounding-math
- Authentication-results: sourceware.org; auth=none
- References: <B599187D-FA4E-4FC4-BE3F-9A92AD5326DC at gmail dot com> <alpine dot DEB dot 2 dot 10 dot 1311201639590 dot 4576 at stedding dot saclay dot inria dot fr>
- Reply-to: gcc at gcc dot gnu dot org
On Wed, 20 Nov 2013, Marc Glisse wrote:
On Wed, 20 Nov 2013, FX wrote:
I reduced my problem to the following code:
int main (void)
x = 1 / 3.;
__builtin_printf ("%.30lg %.30lg\n", __builtin_remainder(1., 1/3.), 1/3.);
__builtin_printf ("%.30lg %.30lg\n", __builtin_remainder(1., x), x);
This calls __builtin_remainder() twice, once with constant arguments, once
with a variable. Without rounding math, the two results agree (5.55e-17),
but with -frounding-math, the constant case changes (-2.71e-20).
On x86_64-apple-darwin, things are even weirder than x86_64-linux (the
above): constant-case with -frounding-math -m64 is unchanged, while
constant case with -frounding-math -m32 follows the linux results.
I donât think this is right, since remainder() is supposed to be unaffected
by the rounding mode. Yet, before I open a PR, I wanted to see if someone
understands whatâs going onâ
Did you really test on x86_64-linux? I am only seeing this -2.71e-20 when
Oups, didn't finish my email.
So 1./3 is computed with 80 bits, the first computation is very nice, then
the call to printf forces that number to memory where it is rounded to 64
bits (anything can randomly cause that rounding at any time), and that is
then used for the second computation.
-frounding-math is a red herring, -O0 could have disabled the constant