Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Floating point odd issue #68

Open
karlglazebrook opened this issue Jan 3, 2025 · 1 comment
Open

Floating point odd issue #68

karlglazebrook opened this issue Jan 3, 2025 · 1 comment

Comments

@karlglazebrook
Copy link

I found a curious bug when trying to use gcc 14.2 from here to build GSL on an Intel Sonoma iMac.

I was able to make this standalone code that reproduces the bug on the machine:

#include <stdio.h>
#include <math.h>

/* f(x) = sin(x) */
double f_sin(double x)
{
    return sin(x);
}

// Main function: entry point for execution
int main() {

    double x,y;

    x = sin(7.0);
    printf("%20.17f \n",x);
    y = f_sin(7.0);
    printf("%20.17f \n",y);
    printf("%20.17f \n",x-y);

    return 0;
}

Here is the output:

 0.65698659871878906 
 0.65698659871878917 
-0.00000000000000011 

So calling the same function directly vs indirectly produces a different value! (Even with no optimisation -O0).

Very odd! (For those interested the equivalent of this code was executing at line 2236 of gsl-2.7.1/integration/test.c and failing the test).

Works fine on Apple Silicon.

Works fine if you change the value to 2.0 or 5.0.

Works fine if you put '7.0' in to a variable and use that!

Not sure if this is easy to fix, probably obscure and particular compiler boojums, but sharing for fun & giggles, and the public record.

% gcc -v 
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/gfortran/libexec/gcc/x86_64-apple-darwin23/14.2.0/lto-wrapper
Target: x86_64-apple-darwin23
Configured with: /Users/fx/gcc-14-branch/configure --prefix=/usr/local/gfortran --with-gmp=/Users/fx/build_package/deps --enable-languages=c,c++,fortran,objc,obj-c++,m2 --build=x86_64-apple-darwin23 --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.2.0 (GCC) 

XCode 16.2 installed.

@karlglazebrook
Copy link
Author

karlglazebrook commented Jan 3, 2025

PS found this when I was building a complex set of libraries (incl. GSL) some with c and some with fortran hence was trying to use consistent gcc and gfortran throughout. Have used this distribution for a while - keep up the good work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant