commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Juan Barandiaran <barandiaran.j...@gmail.com>
Subject [math] Complex Tanh for "big" numbers
Date Fri, 09 Dec 2011 07:51:55 GMT
Hi,

In Complex.java the tanh is computed with the following formula:

tanh(a + bi) = sinh(2a)/(cosh(2a)+cos(2b)) + [sin(2b)/(cosh(2a)+cos(2b))]i

The problem that I'm finding is that as soon as "a" is a "big" number,
both sinh(2a) and cosh(2a) are infinity and then the method tanh returns in
the real part NaN (infinity/infinity) when it should return 1.0.

Wouldn't it be appropiate to add something as in the FastMath library??:

if (real>20.0){
      return createComplex(1.0, 0.0);
}
if (real<-20.0){
      return createComplex(-1.0, 0.0);
}


Best regards,

JBB

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message