NaN(), Infinity()

Blitz3D Forums/Blitz3D Programming/NaN(), Infinity()

Function NaN#()
Return 0.0/a
End Function

Function Infinity#()
Return 1.0/a
End Function

I give you 10 points for imagination.

Lol.

HEy, this is useful for catching bugs. Thanks.

You can make them constants like this:

Const NaN# = (-1.0)^(0.5)
Const Infinity# = 99999.0^99999.0

Now I want to open a new thread with the title:

NaN and the Wisdom of ZeN - or: Quantum Physics in the 21st century

because you can do this funny thing:

zero#=0.0
NaN#=zero#/zero#
a#=3.14
if a# = NaN#
 print "a# is "+a#+" as well as NaN!"
endif


And therefor a variable that is NaN could not be used to catch NaNs trough comparing.

How about this:

Function NaN%(value#)
If 1=value And 2=value Return True
End Function

this returns zero. did you actually test your application before you released it? ;P

It tells you whether a value equals nan or not. I don't need to test things, I can see the code right in front of me.

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.

This is confusing me, but I like the sound of "-infinity"

'ere, How can Infinity be zero? ;)