tan()#
relationalai.std.math
#tan(number: Number|Producer) -> Expression
Calculates the tangent of number
, where number
is specified in radians.
If number
is a Producer
, tan()
filters out any non-numeric values from the producer.
Must be called in a rule or query context.
Parameters#
Name | Type | Description |
---|---|---|
number | Producer or Python Number object | The angle in radians to calculate the tangent of. |
Returns#
An Expression
object.
Example#
Use tan()
to calculate the tangent of an angle in radians:
##
import relationalai as rai
from relationalai.std import math
# =====
# SETUP
# =====
model = rai.Model("MyModel")
Angle = model.Type("Angle")
with model.rule():
Angle.add(id=1).set(value=0)
Angle.add(id=2).set(value=3.14159 / 4) # Approximately π/4
Angle.add(id=3).set(value="INVALID") # Non-numeric value
# =======
# EXAMPLE
# =======
# Set a tan_value property to the tangent of each angle's value.
with model.rule():
angle = Angle()
angle.set(tan_value=math.tan(angle.value))
# Since tan() filters out non-numeric values, the tan_value property
# is not set for the angle with ID 3.
with model.query() as select:
angle = Angle()
response = select(angle.id, angle.tan_value)
print(response.results)
# id tan_value
# 0 1 0.000000
# 1 2 0.999999
# 2 3 NaN