You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Juan Barandiaran <ba...@gmail.com> on 2011/12/09 08:51:55 UTC

[math] Complex Tanh for "big" numbers

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

Re: [math] Complex Tanh for "big" numbers

Posted by Juan Barandiaran <ba...@gmail.com>.
Hi,

I have opened a Jira issue.

Thanks again Luc for your continuous support to us, ocasional users who
don't know about the details and procedures of the Commons project.

The Math Commons library is really useful, but the structure of the Apache
Commons Web is anti-user-friendly ... at least if you only visit it from
time to time.
It truly takes some time to learn how to find or report things.

Best Regards,

JBB


2011/12/9 Juan Barandiaran <ba...@gmail.com>

> 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
>
>
>

Re: [math] Complex Tanh for "big" numbers

Posted by Luc Maisonobe <Lu...@free.fr>.
Le 09/12/2011 08:51, Juan Barandiaran a écrit :
> Hi,

Hi Juan,

> 
> 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);
> }

Yes, this does make sense. Could you open a Jira issue with this request ?

Thanks,
Luc

> 
> 
> Best regards,
> 
> JBB
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org