Mail Archives: djgpp/1994/01/10/05:21:11
>I've found a problem with the tanh function in djgpp 1.11. As x gets
>bigger, tanh(x) should approach 1.0. e.g. running a trivial program on
>a Sun yields:
>
>tanh(2.71828) = 0.991329
>tanh(7.38906) = 0.999999
>tanh(20.0855) = 1
...
>tanh(22026.5) = 1
>Running the same problem on djgpp generates a fp exception as it
>calculates the last line.
The problem you are having is with fp overflow. Recall that tanh is
defined in terms of e^x and e^(-x). Now, while e^(-x) approaches 0,
e^x diverges rapidly. e^22026 is about 10^9565, so your fix is to
write a wrapper function that returns 1.0 if x is greater than about 20.
Andy
- Raw text -