-1

I can't figure out why tanh calculation has higher accuracy in tensorflow-2.2.0 as compare to numpy. Please have a look at example below.

tanh(0.963801444)

I appreciate your time and reply.

Thanks,

Robin Sharma
  • 181
  • 2
  • 11

1 Answers1

1

The NumPy result is more accurate. For comparision, Wolfram Alpha gives the result 0.745967716740428007413668705771485305302298638189343426746...

NumPy uses 64 bit floating point (i.e. double precision) by default, while tensorflow uses 32 bit floating point (i.e. single precision).

Warren Weckesser
  • 110,654
  • 19
  • 194
  • 214
  • Re “Tensorflow uses 32 bit floating point”: This alone does not explain the result. Converting .963801444 to IEEE-754 binary 32 and calculating tanh should yield 0.74596774578094482421875, not .7459678053855896. It is only an ULP difference, but it suggests Tensorflow’s `tanh` is inaccurate beyond what is necessitated by the format. – Eric Postpischil Jul 21 '20 at 14:02