Bug 35556 - problem with log10 and arch x86_64
Summary: problem with log10 and arch x86_64
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2008-03-12 16:57 UTC by Laura Amos
Modified: 2009-05-17 13:40 UTC (History)
3 users (show)

See Also:
Host: i686-apple-darwin9
Target: i686-apple-darwin9
Build: i686-apple-darwin9
Known to work:
Known to fail:
Last reconfirmed:

output from building with -save_temps (6.92 KB, text/plain)
2008-03-12 16:59 UTC, Laura Amos

Note You need to log in before you can comment on or make changes to this bug.
Description Laura Amos 2008-03-12 16:57:24 UTC
log10 in a 64 bit Intel build on OS X sometimes returns a result of 0, no matter what the argument.

gcc version:

Using built-in specs.
Target: i686-apple-darwin9
Configured with: /var/tmp/gcc/gcc-5465~16/src/configure --disable-checking -enable-werror --prefix=/usr --mandir=/sh
are/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.0/ --with-gxx-include-di
r=/include/c++/4.0.0 --with-slibdir=/usr/lib --build=i686-apple-darwin9 --with-arch=apple --with-tune=generic --host
=i686-apple-darwin9 --target=i686-apple-darwin9
Thread model: posix
gcc version 4.0.1 (Apple Inc. build 5465)

The program is compiled using g++ -arch x86_64 bug_check.cpp

There are no compiler warnings.
When run (no arguments on the command line), the first loop produces correct values, but the second produces all 0 results.

double broken_log10(double val)
    return log10(val);

double working_log10(double val)
    double t = log10(val);
    printf("%g\n", val);
    return t;

int main(int argc, char **argv)
    int n;
    int len = 10;

    for (n = 1; n < len; n++)
 printf("%d: %g\n", n, working_log10((double)n/(double)len));
    for (n = 1; n < len; n++)
 printf("%d: %g\n", n, broken_log10((double)n/(double)len));
    return 0;
Comment 1 Laura Amos 2008-03-12 16:59:05 UTC
Created attachment 15304 [details]
output from building with -save_temps
Comment 2 Dominique d'Humieres 2008-03-12 20:47:47 UTC
This is known bug of OSX 10.5.2 (radar 5782719). The only thing we can do is wait for Apple to fix it.
See pr35285 for fortran examples.

Comment 3 Hans van der Voort 2008-03-14 11:28:48 UTC
We encountered similar problems with Apple gcc 4.2.1 in statements like:
x = log10(MY_CONSTANT);
in combination with -fast compiler option.
With option -O2 there were no problems.
When 'x' is printed like reporter earlier the problem does not occur.
The workaround x = log(MY_CONSTANT) / log(10); works as expected.
Comment 4 David Fang 2008-03-22 23:35:07 UTC
Comment 5 Francois-Xavier Coudert 2009-05-17 13:40:24 UTC
This was an Apple bug; furthermore, it seems to have been fixed somewhere between 10.5.2 and 10.5.7.