Ceil# ( float# )
Parameters
| float - the number to round up |
Description
|
Rounds a number up towards plus infinity and returns it as a float. Ceil( 1.75 ) is 2.0 and Ceil( -1.75 ) is -1.0. As with Floor, the negative case is the one that surprises people: rounding "up" means towards zero when the number is negative. Ceil is the command for "how many do I need". How many rows of 32-pixel tiles cover a 500-pixel screen? Ceil( 500/32.0 ) is 16, where flooring would leave a strip uncovered. The same trick sizes texture atlases, inventory pages and progress-bar segments. The result is a float, so put it in a # variable. Remember to force a float division first: 500/32 is integer division and gives 15 before Ceil ever sees it, so write 500/32.0 instead. See also: Floor, Int, Float, Sgn. |
Example
; Ceil Example ; ------------ ; Ceil rounds UP to the next whole number, and returns it as a float. ; Compare Floor (always rounds down) and Int (rounds to the nearest ; integer) - negative values are where the three differ most. Print " value Ceil Floor Int" Print "------------------------------------" ; Each Read pulls the next sample value from the Data line below For i=1 To 6 Read v# Print RSet(v,10)+RSet(Ceil(v),10)+RSet(Floor(v),10)+RSet(Int(v),6) Next Data 2.3,2.7,2.5,-2.3,-2.7,-2.5 Print "" Print "Ceil(2.3) goes up to 3.0, but Ceil(-2.3) goes UP to -2.0:" Print "up always means towards positive infinity." Print "" Print "Press any key to close the example" WaitKey End
Index