JFK, As you say you can not do an equality test on NaN which I was forgetting, so...
zero#=0.0
Infinity#=1.0/zero
a#=3.14
if a#>Infinity
print "a# can now only be NaN!"
endif
Consequently there is not much point in defining NaN at all (other than for testing purposes), all you need to define is Infinity.
If you are thinking of combining the tests for NaN and Infinity do not do If a#>=Infinity because you can also have -Infinity so instead do If Abs(a#)>=Infinity (actually you could just do If Abs(a#)=Infinity since NaN equates to everything !)
For instance...
zero#=0
Infinity# = 1/zero ; alternatively Const Infinity# = 99999.0^99999.0
For i = 0 To 3
Select i
Case 0 a#=Pi
Case 1 a#=-(1/zero)
Case 2 a#= (1/zero)
Case 3 a#= zero/zero
End Select
If Abs(a#)>=Infinity Then ; test for NaN or Infinity
Write "a# is "+a#
; To then determine the nature of the beast if this is important to you...
If Abs(a#)<=Infinity Then ; this test will exclude NaN
If a>0 Then
Print " (Positive Infinity)"
Else
Print " (Negative Infinity)"
EndIf
Else
Print " (Not a Number)"
EndIf
Else
Print "a# is "+a#+" and good to go"
EndIf
Next
WaitKey()
Halo's amended NaN function works just as well BTW, and Michaels constant definition for Infinity works for me anyway.
|