public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/48140] New: fmod() not accurate to double precision?
@ 2011-03-15 20:38 sdedeo at post dot harvard.edu
2011-03-15 20:48 ` [Bug c/48140] " sdedeo at post dot harvard.edu
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: sdedeo at post dot harvard.edu @ 2011-03-15 20:38 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48140
Summary: fmod() not accurate to double precision?
Product: gcc
Version: 4.5.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: sdedeo@post.harvard.edu
Created attachment 23670
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=23670
c code to produce the output above
I am not sure if this is a "good" bug to submit to gcc, since it involves the
math library. I have found it occurs on my own machine (Intel Core i7) with
gcc4.5 and gcc4.6, as well as on other machines I have access to that use gcc.
Again, I apologize if this is either not a real error, or if it is related to
other floating point errors that people report. I have tried to look through
the database. The error below appears even without optimization flags.
In any case, I am finding that fmod, given a double precision set of inputs,
produces answers that are only good to (approximately) single precision. In
other words, the output of fmod is a double, but the answer is not accurate. It
seems to show up for large values of x in fmod(x,y).
Below I compare the outputs to Mathematica (which can handle arbitrary
precision.)
10^9 mod 2pi: 0.5773954624831035
Mathematica value: 0.5773954235013852
[this is accurate only to 10^-8]
sin(10^9 mod 2pi): 0.5458434821109812
sin(10^9): 0.5458434494486994
Mathematica value: 0.5458434494486996
[the sin function handles the large number gracefully to give standard 10^-16
precision]
#include <stdio.h>
#include <math.h>
#define TWOPI 6.2831853071795864769252867665590057683943387987502
int main() {
double big, twopi;
big=1000000000.0;
printf("10^9 mod 2pi: %#17.16g\n", fmod(big, TWOPI));
printf("Mathematica value: 0.5773954235013852\n");
printf("\n");
printf("sin(10^9 mod 2pi): %#17.16g\nsin(10^9): %#17.16g\n",
sin(fmod(big, TWOPI)), sin(big));
printf("Mathematica value: 0.5458434494486996\n");
}
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/48140] fmod() not accurate to double precision?
2011-03-15 20:38 [Bug c/48140] New: fmod() not accurate to double precision? sdedeo at post dot harvard.edu
@ 2011-03-15 20:48 ` sdedeo at post dot harvard.edu
2011-03-15 20:57 ` sdedeo at post dot harvard.edu
2011-03-16 10:54 ` rguenth at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: sdedeo at post dot harvard.edu @ 2011-03-15 20:48 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48140
--- Comment #1 from Simon DeDeo <sdedeo at post dot harvard.edu> 2011-03-15 20:46:55 UTC ---
Created attachment 23671
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=23671
.i file (Intel Core i7, gcc 4.5.2)
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/48140] fmod() not accurate to double precision?
2011-03-15 20:38 [Bug c/48140] New: fmod() not accurate to double precision? sdedeo at post dot harvard.edu
2011-03-15 20:48 ` [Bug c/48140] " sdedeo at post dot harvard.edu
@ 2011-03-15 20:57 ` sdedeo at post dot harvard.edu
2011-03-16 10:54 ` rguenth at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: sdedeo at post dot harvard.edu @ 2011-03-15 20:57 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48140
--- Comment #2 from Simon DeDeo <sdedeo at post dot harvard.edu> 2011-03-15 20:48:28 UTC ---
Created attachment 23672
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=23672
.i file (Different system, gcc 4.1.2 (Gentoo 4.1.2 p1.1))
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/48140] fmod() not accurate to double precision?
2011-03-15 20:38 [Bug c/48140] New: fmod() not accurate to double precision? sdedeo at post dot harvard.edu
2011-03-15 20:48 ` [Bug c/48140] " sdedeo at post dot harvard.edu
2011-03-15 20:57 ` sdedeo at post dot harvard.edu
@ 2011-03-16 10:54 ` rguenth at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-03-16 10:54 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48140
Richard Guenther <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
--- Comment #3 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-03-16 10:53:42 UTC ---
This is at most a bug in the C library. Note that CPUs do not have native
support for fmod or remainder so the implementations need to weight speed
against precision.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-03-16 10:53 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-15 20:38 [Bug c/48140] New: fmod() not accurate to double precision? sdedeo at post dot harvard.edu
2011-03-15 20:48 ` [Bug c/48140] " sdedeo at post dot harvard.edu
2011-03-15 20:57 ` sdedeo at post dot harvard.edu
2011-03-16 10:54 ` rguenth at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).