Skip to content

relationalai.std.math.ceil()

ceil(number: Number|Producer) -> Expression

Calculates the ceiling of a number, which is the smallest whole number greater than or equal to the number. If number is a Producer, ceil() acts as a filter and removes any non-numeric values from the producer. Must be called in a rule or query context.

NameTypeDescription
numberProducer or Python Number objectThe number to calculate the ceiling of.

An Expression object.

Use ceil() to calculate the ceiling of a number:

import relationalai as rai
from relationalai.std import math
# =====
# SETUP
# =====
model = rai.Model("MyModel")
Person = model.Type("Person")
with model.rule():
Person.add(id=1).set(height_cm=170.1)
Person.add(id=2).set(height_cm=180.9)
Person.add(id=3).set(height_cm="INVALID") # Non-numeric height
# =======
# EXAMPLE
# =======
# Set a height_rounded property to the ceiling of each person’s height.
with model.rule():
person = Person()
person.set(height_rounded=math.ceil(person.height_cm))
# Since ceil() filters out non-numeric values, the height_rounded property is not
# set for the person with id=3.
with model.query() as select:
person = Person()
response = select(person.id, person.height_rounded)
print(response.results)
# id height_rounded
# 0 1 171.0
# 1 2 181.0
# 2 3 NaN

For negative numbers, ceil() rounds towards zero:

with model.query() as select:
response = select(math.ceil(-5.5))
print(response.results)
# v
# 0 -5.0