I cant seem to find the functions to do this.
Could someone tell me how to floor and ceil in FB pls?
Sorry, there's no fb commands for that.
Adding or subtracting 0.5 then converting to an int (and back if you need the result in a float) is what I've been doing although sometimes with unwanted results (try it with an odd whole number and an even whole number to see) so I find a value like 0.4999 to be a bit better.
Actually, if you use the lua headers in your program you might be able use a pcall to access lua's math library, which does have those functions.
ok, thanks guys for the info :)
Use the ones in the C runtime library, crt.bi.
Jim
thanx Jim, good idea.
I've also had a go at coding the functions too :D
Declare Function Floor( value as double )
Declare Function Ceil( value as double )
Function Floor( value as double )
dim newValue as integer
If ( value < 0 ) then
newValue = value - ( 1.0 - Abs(value Mod 1) )
Return newValue
Else
newValue = value - (value Mod 1)
Return newValue
EndIf
End Function
Function Ceil( value as double )
dim newValue as integer
If ( value > 0 ) then
newValue = value + ( 1.0 - Abs(value Mod 1) )
Return newValue
Else
newValue = value - (value Mod 1)
Return newValue
EndIf
End Function