Null default float parameters?

BlitzMax Forums/BlitzMax Programming/Null default float parameters?

JoshK(Posted 2008) [#1]
Here is what I want:

vec3(1,2,3)

Creates a vector with:

x=1.0
y=2.0
z=3.0

vec3(4.0)

Creates a vector with:

x=4.0
y=4.0
z=4.0

Is there any way this can be done?:

Function Vec3:TVec3(x#=0.0,y#=Nan,z#=Nan)
Local t:TVec2=New TVec2
If IsNan(y) y=x
If IsNan(z) z=y
t.x=x
t.y=y
t.z=z
Return t
EndFunction


Perturbatio(Posted 2008) [#2]


?


REDi(Posted 2008) [#3]
Perturbatio, Null is Just zero for ints/float ect.

AFAIK its not possible as things stand ATM, this is the best I can come up with to fake it....

SuperStrict 

Local Vec:TVec3 = TVec3.Create(4.0)
Print Vec.ToString()

Type TVec3

	Const Nill# = %01111111111111111111111111111111

	Field x:Float, y:Float, z:Float

	Function Create:TVec3(x#=0.0,y#=nill,z#=nill)
		Local t:TVec3=New TVec3
		t.x=x
		t.y=y
		t.z=z
		If y=nill
			t.y=x
			t.z=x
		EndIf
		Return t
	EndFunction

	Method ToString$()
		Return x+", "+y+", "+z
	EndMethod

EndType


It defines Nill as the largest possible float, which is far from ideal.


Perturbatio(Posted 2008) [#4]
Is there some way that NaN can be brought in from C?


Who was John Galt?(Posted 2008) [#5]
Weird, isNan() doesn't seem to work, but 'if x=Nan' works as expected. Just replace isNan() with a direct comparison.


REDi(Posted 2008) [#6]
actually would be better to define Nill as infinity...
	Const Nill# = 10^39



REDi(Posted 2008) [#7]
John, AFAIK Nan is also just zero


Azathoth(Posted 2008) [#8]
0.0/0.0 could be used.

Function Vec3:TVec3(x#=0.0,y#=0.0/0.0,z#=0.0/0.0)
	Local t:TVec2=New TVec2
	If IsNan(y) y=x
	If IsNan(z) z=y
	t.x=x
	t.y=y
	t.z=z
	Return t
EndFunction