FP Errors or a bug? Trig functions

Archives Forums/Blitz3D Bug Reports/FP Errors or a bug? Trig functions

_PJ_(Posted 2011) [#1]
Print Tan(90)
Print Tan(-90)
Print Tan(270)
Print Tan(-270)


In theory, these should not only be identical, but should fail too. Interestingly, I tried them on a scientific calculator program and got some completely different and irrational results.

function(90)
-0.27660581972021794930258464116975
function(-90)
0.27660581972021794930258464116975
function(270)
2.0092393838644816111277940996467
function(-270)
-2.0092393838644816111277940996467


Perhaps This is an inbuilt processor trap designed to prevent against infinities, despite IEEE convention such as Blitz does with Div/0 or NaN etc, should result in infinity?


Floyd(Posted 2011) [#2]
It's just the approximate nature of floating point.

Under the hood 90 degrees is converted to 90*(Pi/180) radians. You would like this to be exactly Pi/2, but it isn't.

What you end up with is Tan( 90 + VerySmallError ). You can tell the error is positive because Tan has become negative.

In fact it is about Tan(90.0000025044817).


_PJ_(Posted 2011) [#3]
Thanks Floyd!