Skip to content

Math Functions

Abs

returns the absolute value of a number

Syntax:

Abs(x: int | float) -> int | float

Examples:

Abs(-6) = 6
Abs(-5.5) = 5.5
Abs(2) = 2

Acos

returns the arccosine, in radians, of x.

Syntax:

Acos(x: float) -> float

Examples:

Acos(1) = 0
Abs(Acos(0) - Pi()/2) < 1e-12

Asin

returns the arcsine, in radians, of x.

Syntax:

Asin(x: float) -> float

Examples:

Asin(0) = 0
Asin(1) = Pi()/2

Atan

returns the arctangent, in radians, of x.

Syntax:

Atan(x: float) -> float

Examples:

Atan(0) = 0
Atan(1) = Pi()/4

Ceil

returns the smallest integer greater than or equal to the argument

Syntax:

Ceil(x: float) -> float

Examples:

Ceil(4.1) = 5
Ceil(8.0) = 8
Ceil(-3.5) = -3.0

Cos

returns the cosine of the radian argument x

Syntax:

Cos(x: float) -> float

Examples:

Cos(0) = 1
Abs(Cos(Pi()/2)) < 1e-12

Exp

returns the base-e exponential of x

Syntax:

Exp(x: float) -> float

Examples:

Exp(Log(0.5)) = 0.5
Exp(1) = 2.718281828459045

Float

converts argument to a floating point number

Syntax:

Float(x: any) -> float?

Examples:

Float("1.2") = 1.2
Float(5) = 5.0
Float(false) = 0.0

Floor

returns the smallest integer less than or equal to the argument

Syntax:

Floor(x: float) -> float

Examples:

Floor(4.9) = 4
Floor(8.0) = 8.0
Floor(-3.5) = -4.0

Int

converts argument to an integer

Syntax:

Int(x: any) -> int?

Examples:

Int("14") = 14
Int(5.9) = 5
Int(true) = 1

IsCloseTo

returns true if values x and y are close to each other in absolute terms. May optionally specify tolerance [default: 1e-9]. For relative comparison of values close to zero, use IsRelativelyCloseTo.

Syntax:

IsCloseTo(x: float, y: float, <abs_tol: float>) -> bool?

Examples:

(0.1 + 0.2).IsCloseTo(0.3)
IsCloseTo(3, 3.01, 0.1) is true
IsCloseTo(3, 3.01, 0.001) is false
1 - 0.1 ~= 0.9

IsRelativelyCloseTo

returns true if values x and y are close to each other in relative terms. May optionally specify tolerance [default: 1e-9].

Syntax:

IsRelativelyCloseTo(x: float, y: float, <rel_tol: float>) -> bool?

Examples:

(12e-20 - 9e-20).IsRelativelyCloseTo(3e-20)
IsRelativelyCloseTo(1e-15, 9e-15) is false
IsRelativelyCloseTo(1e-30, 1.1e-30, 0.15) is true
IsRelativelyCloseTo(1e-30, 1.1e-30, 0.05) is false

Log

returns the natural logarithm of x

Syntax:

Log(x: float) -> float?

Examples:

Log(Exp(5.4)) = 5.4
Log(1) = 0

Log10

returns the base 10 logarithm of x

Syntax:

Log10(x: float) -> float?

Examples:

Log10(1000) = 3
Log10(10.0) = 1

Maximum

returns the maximum of the set of values

Syntax:

Maximum(values: ...int | float) -> int? | float?

Examples:

Maximum(2, 3, 1.0) = 3
Maximum(5) = 5
Maximum() is null

Minimum

returns the minimum of the set of values

Syntax:

Minimum(values: ...int | float) -> int? | float?

Examples:

Minimum(2, 1, 3.0) = 1
Minimum(5) = 5
Minimum() is null

Pi

returns the constant value of pi: 3.14159...

Syntax:

Pi() -> float

Examples:

Pi() > 3.1 and Pi() < 3.2
Cos(Pi()) = -1

Pow

returns x to the y power

Syntax:

Pow(x: int | float, y: int | float) -> int | float

Examples:

Pow(2, 6) = 64
Pow(-5, 3) = -125
Pow(9, 0.5) = 3

Round

rounds number to nearest integer

Syntax:

Round(x: float) -> float

Examples:

Round(3.6) = 4.0
Round(-2.0) = -2.0

Sign

returns the sign of a number, indicating if it is positive, negative, or zero.

Syntax:

Sign(x: int | float) -> int | float

Examples:

Sign(3.4) = 1
Sign(-2) = -1
Sign(0) = 0

Sin

returns the sine of the radian argument x

Syntax:

Sin(x: float) -> float

Examples:

Sin(0) = 0
Sin(Pi()/2) = 1

Tan

returns the tangent of the radian argument x

Syntax:

Tan(x: float) -> float

Examples:

Tan(0) = 0
Tan(Pi()/4) = 1