Quirrel4.41.0

math.ceil

Defined in module "math"
from "math" import ceil
pure fastcall ceil(x: number): float

Rounds x upward to the nearest integer

Parameters

xnumberthe number to round

Return value

The smallest integer value that is not less than x.

Notes

The result is always a float, even when x is already an integer. For a negative x, "upward" moves toward zero, not away from it: ceil(-3.2) is -3.

Example

examples/math/ceil.nut
from "math" import ceil

println("ceil(3.2) =", ceil(3.2))
println("ceil(-3.2) =", ceil(-3.2))

// upward means toward positive infinity, so a negative x moves toward zero
println("type(ceil(3.2)) =", type(ceil(3.2)))
Output:
ceil(3.2) = 4
ceil(-3.2) = -3
type(ceil(3.2)) = float

See also

floorRounds x downward to the nearest integer
roundRounds x to the nearest integer
absReturns the absolute value of x
mathmodule index