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; }
Created attachment 15304 [details] output from building with -save_temps
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.
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.
yikes!
This was an Apple bug; furthermore, it seems to have been fixed somewhere between 10.5.2 and 10.5.7.