What'is the floor function
BlitzMax Forums/BlitzMax Beginners Area/What'is the floor function
| ||
Hi ! i don't understand what is the job of the 'flloor' function ? Somebody could post an example ? thx |
| ||
If Floor(1.3)=1.0 then Print "Wow, I got it!" if Ceil(1.7)=2.0 then Print "Rounded Up!" |
| ||
In case you don't get that: Floor rounds a float down to the nearest whole number. Ceil rounds a float up to the nearest whole number. |
| ||
The diff with int(value) and int(value)+1 is that floor and ceil also work correctly with negative numbers. Floor(-1.2) gives -2, while Int(-1.2) gives 1 Best way to explain it is by using a ruler or something, the floor value is the first int value at the left of that value, and ceil is the first int value at the right of that value, no matter whether the value is positive or negative. |
| ||
The diff with int(value) and int(value)+1 is that floor and ceil also work correctly with negative numbers INT also works correctly with negative numbers, just differently to Floor ;)(If floor was the "correct" way, it would be int that needed explaining) Floor rounds down towards -inf, next int below (But returns a double?????) Ceil rounds up towards inf, next int up, (But returns a double?????) Int Rounds towards 0, so ABS is always a lower value (Because 5 is really smaller than -6) |