This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Tanh<complex> Returns Incorrect Value
- From: "Thomas D. Dean" <tomdean at speakeasy dot org>
- To: libstdc++ at gcc dot gnu dot org
- Date: Sun, 18 Apr 2010 22:08:30 -0700
- Subject: Tanh<complex> Returns Incorrect Value
- Reply-to: tomdean at speakeasy dot org
tanh(complex) returns incorrect value. See the code at the bottom.
limit(tanh(n*(1+I)),n=infinity) is 1.
Build the application with: g++ trig.cc -o trig
>g++ --version
g++ (GCC) 4.4.1
>./trig 5678 ## returns correct value of tanh(5678 + 5678I)
libc version 2.10.1
arg (5678,5678)
sinh(arg) (-1.74513e+2465,-3.81804e+2465)
cosh(arg) (-1.74513e+2465,-3.81804e+2465)
s/c (1,-0)
tanh(arg) (1,2.14543e-4932)
>./trig 5679 ## returns incorrect value.
libc version 2.10.1
arg (5679,5679)
sinh(arg) (6.17015e+2465,-9.59925e+2465)
cosh(arg) (6.17015e+2465,-9.59925e+2465)
s/c (1,-0)
tanh(arg) (nan,-0)
Note: s/c is still correct, but, tanh is not.
As arg increases, s/c is incorrect and tanh remains incorrect.
>more trig.cc
// trig.cc - test hyperbolic trig functions
//
// 20100417 tomdean - initial version
//
// copyright 2010 Thomas D. Dean tomdean@speakeasy.org
// This code is GPL
#include <iostream>
#include <complex>
#include <gnu/libc-version.h>
#include <stdlib.h> // atol
using namespace std;
int main(int argc, char **argv) {
long mult;
if (argc == 2) {
mult = atol(argv[1]);
} else {
mult = 50000L;
}
complex<long double> arg(1,1);
arg *= mult;
complex<long double> s,c,r,t;
s=sinh(arg);
c=cosh(arg);
r=s/c;
t=tanh(arg);
cout << "libc version " << gnu_get_libc_version() << endl;
cout << "arg " << arg << endl;
cout << "sinh(arg) " << s << endl;
cout << "cosh(arg) " << c << endl;
cout << "s/c " << r << endl;
cout << "tanh(arg) " << t << endl;
return 0;
}