[Bug c/48140] fmod() not accurate to double precision?

albertmcchan at yahoo dot com gcc-bugzilla@gcc.gnu.org
Sat Dec 9 02:19:00 GMT 2017


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48140

Albert Chan <albertmcchan at yahoo dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |albertmcchan at yahoo dot com

--- Comment #4 from Albert Chan <albertmcchan at yahoo dot com> ---
I think fmod is accurate
Gcc cannot do exact fmod(1e9, 2*pi)

it can only do fmod(1e9, 0x1.921f54442d18p+2) = 0.57739546248310347

which is exactly what gcc returns

in fact, it is VERY accurate
If we do remainder calculation in steps:

quotient = floor(1e9 / (2 pi)) = 159154943
remainder = 1e9 - quotient * 0x1.921f54442d18p+2
                = 0.57739543914794922

doing in steps under-counted 210,184,384 ULP


More information about the Gcc-bugs mailing list