Compilling octave I discovered an issue in my system.
The bug seems to be in tanh() function inside libstdc++.
I have now gcc-4.2.2. I tested this also with gcc-3.3.6 and the result
is correct.
It seems to be an old bug which reappeared.
Please comment.
Here is how the problem can be confirmed:
[EMAIL PROTECTED]:~/download/numerics/test$ cat tanh.cc
#include <complex>
#include <iostream>
int main()
{
std::complex<double> x,y,ch,sh,z,z2;
x=std::complex<double>(0,M_PI*0.5);
y=std::tanh(x);
ch=std::cosh(x);
sh=std::sinh(x);
z=sh/ch;
z2=sh; z2/=ch;
std::cout<<"x="<<x<<", tanh(x) = "<<y<<std::endl;
std::cout<<"x="<<x<<", sinh(x) = "<<sh<<std::endl;
std::cout<<"x="<<x<<", cosh(x) = "<<ch<<std::endl;
std::cout<<"x="<<x<<", sinh/cosh= "<<z<<std::endl;
std::cout<<"x="<<x<<", sh/=ch = "<<z2<<std::endl;
std::cout<<"x="<<x<<", sh/ch2 = "<<(sinh(x)/cosh(x))<<std::endl;
return 0;
}
[EMAIL PROTECTED]:~/download/numerics/test$
The results when compiling with gcc-4.2.2:
[EMAIL PROTECTED]:~/download/numerics/test$ gcc -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.2.2/configure --prefix=/usr
--libexecdir=/usr/lib --enable-shared --enable-threads=posix
--enable-__cxa_atexit --enable-clocale=gnu
--enable-languages=c,c++,ada,fortran,java,objc
Thread model: posix
gcc version 4.2.2
[EMAIL PROTECTED]:~/download/numerics/test$ g++ tanh.cc -o tanh-422
[EMAIL PROTECTED]:~/download/numerics/test$ ./tanh-422
x=(0,1.5708), tanh(x) = (nan,inf)
x=(0,1.5708), sinh(x) = (0,1)
x=(0,1.5708), cosh(x) = (6.12303e-17,0)
x=(0,1.5708), sinh/cosh= (0,1.63318e+16)
x=(0,1.5708), sh/=ch = (0,1.63318e+16)
x=(0,1.5708), sh/ch2 = (0,1.63318e+16)
[EMAIL PROTECTED]:~/download/numerics/test$
The result is obviously wrong ! tanh(x), for x=pi/2 should be (0,inf)
Correct result was generated by the old gcc-3.3.6:
[EMAIL PROTECTED]:~/download/numerics/test$ which g++
/opt/gcc-3.3.6/bin/g++
[EMAIL PROTECTED]:~/download/numerics/test$ g++ -v
Reading specs from /opt/gcc-3.3.6/lib/gcc-lib/i686-pc-linux-gnu/3.3.6/specs
Configured with: ../gcc-3.3.6/configure --prefix=/opt/gcc-3.3.6
--enable-shared --enable-languages=c,c++ --enable-threads=posix
Thread model: posix
gcc version 3.3.6
[EMAIL PROTECTED]:~/download/numerics/test$ g++ tanh.cc -o tanh-336
[EMAIL PROTECTED]:~/download/numerics/test$ ./tanh-336
x=(0,1.5708), tanh(x) = (0,1.63318e+16)
x=(0,1.5708), sinh(x) = (0,1)
x=(0,1.5708), cosh(x) = (6.12303e-17,0)
x=(0,1.5708), sinh/cosh= (0,1.63318e+16)
x=(0,1.5708), sh/=ch = (0,1.63318e+16)
x=(0,1.5708), sh/ch2 = (0,1.63318e+16)
[EMAIL PROTECTED]:~/download/numerics/test$ ldd tanh-336
linux-gate.so.1 => (0xffffe000)
libstdc++.so.5 => /usr/lib/libstdc++.so.5 (0xb7e0c000)
libm.so.6 => /lib/libm.so.6 (0xb7de7000)
libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0xb7ddc000)
libc.so.6 => /lib/libc.so.6 (0xb7cbb000)
/lib/ld-linux.so.2 (0xb7eeb000)
By the way:
[EMAIL PROTECTED]:~/download/numerics/test$ ldd tanh-422
linux-gate.so.1 => (0xffffe000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0xb7e44000)
libm.so.6 => /lib/libm.so.6 (0xb7e1f000)
libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0xb7e14000)
libc.so.6 => /lib/libc.so.6 (0xb7cf3000)
/lib/ld-linux.so.2 (0xb7f53000)
Regards,
juras
--
http://linuxfromscratch.org/mailman/listinfo/blfs-support
FAQ: http://www.linuxfromscratch.org/blfs/faq.html
Unsubscribe: See the above information page