Null default float parameters?
BlitzMax Forums/BlitzMax Programming/Null default float parameters?
| ||
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, 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. |
| ||
Is there some way that NaN can be brought in from C? |
| ||
Weird, isNan() doesn't seem to work, but 'if x=Nan' works as expected. Just replace isNan() with a direct comparison. |
| ||
actually would be better to define Nill as infinity...Const Nill# = 10^39 |
| ||
John, AFAIK Nan is also just zero |
| ||
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 |