http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49010
kargl at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |kargl at gcc dot gnu.org
--- Comment #2 from kargl at gcc dot gnu.org 2011-05-16 20:44:08 UTC ---
This appears to be caused by the use of __builtin_fmod in
trans-intrinsic.c (gfc_conv_intrinsic_mod). By hacking
the code to disallow the use of the builtin, one uses
the fallback code (which implements the simply code).
program foo
real a, p, m1, m2
a = -4.
p = 2.
m1 = mod(a, p)
m2 = a - int(a / p) * p
print *, m1, m2
end program foo
troutmask:sgk[239] gfc4x -o z t.f90 && ./z
0.00000000 0.00000000
Thus, one gets the right answer. Also, note
#include <stdio.h>
#include <math.h>
int
main(void)
{
float a, p, m1, m2;
a = -4.f;
p = 2.f;
m1 = fmodf(a, p);
m2 = a - (int)(a / p) * p;
printf("%f %f\n", m1, m2);
return 0;
}
troutmask:sgk[241] cc -o z t.c -lm && ./z
-0.000000 0.000000
which probably means that we either want to not
use the __builtin_fmod() (which is probably some
optimized bit twiddling routine).