When estimating the hyperbolic tangent in Windows using the R base function tanh
for large (real, with 0 imaginary part) values the function returns 'NaN':
tanh(356 + 0i)
> NaN + 0i
However, in Mac the same value returns 1 (coinciding with the "real" mathematical value should be close to 1):
tanh(356 + 0i)
> 1 + 0i
Question 1: Does anybody have a clue on why is this happening?
Extra info
This seems not a floating point problem because it seems that Mac's tanh
returns 1 for arbitrarily large values:
tanh(999999677873648767519238192348124812341234182374817239847812738481234871823+0i)
> 1 + 0i
The problem seems to be related with the imaginary part as:
tanh(356)
> 1
in both Windows and Mac. The issue seems to be system (or processor?)-specific as we have tried it in:
- Mac with El Capitan v 10.11.6 processor: 2.7 GHz Intel Core i5
- Mac with Sierra v 10.12.3 processor: 3.2 GHz Intel Core i5
- Windows 10 Home v 1607 processor: Intel Core m3-SY30 CPU@ 0.90 GHz 1.51 GHz
- Windows 7 Home Premium Service Pack 1 processor: Intel Core i5-2410M CPU @2.30 GHz 2.30GHz.
These Windows machines throw NaN
, the Mac's 1 + 0i
.
In all cases we are using R version 3.3.3 the "newest" (64 bit).