Numeric Functions

Integer Functions

The following standard functions operate on integers only.

FunctionDescription
is_odd method and propertyreturns true if the value is an odd number, otherwise false
is_even method and propertyreturns true if the value is an even number, otherwise false
to_floatconvert the value into f64 (f32 under 32-bit)
to_decimalconvert the value into decimal

Signed Numeric Functions

The following standard functions operate on signed integers and decimal numbers only.

FunctionDescription
absabsolute value
signreturns −1 if negative, +1 if positive, 0 if zero
is_zero method and propertyreturns true if the value is zero, otherwise false

Floating-Point Functions

The following standard functions operate on floating-point and decimal numbers only.

CategoryDecimal?Functions
Trigonometryyessin, cos, tan
Trigonometrynosinh, cosh, tanh in radians, hypot(x,y)
Arc-trigonometrynoasin, acos, atan(v), atan(x,y), asinh, acosh, atanh in radians
Square rootyessqrt
Exponentialyesexp (base e)
Logarithmicyesln (base e), log (base 10)
Logarithmicnolog(x,base)
Roundingyesfloor, ceiling, round, int, fraction methods and properties
Conversionyesto_int, to_decimal, to_float
Conversionnoto_degrees, to_radians
Testingnois_nan, is_finite, is_infinite methods and properties

Decimal Rounding Functions

The following rounding methods operate on decimal numbers only.

Rounding typeBehaviorMethods
Nonefloor, ceiling, int, fraction methods and properties
Banker’s roundinground to integerround method and property
Banker’s roundinground to specified number of decimal pointsround(decimal points)
Round upaway from zeroround_up(decimal points)
Round downtowards zeroround_down(decimal points)
Round half-upmid-point away from zeroround_half_up(decimal points)
Round half-downmid-point towards zeroround_half_down(decimal points)

Parsing Functions

The following standard functions parse numbers.

FunctionDescription
parse_intconverts a string to integer with an optional radix
parse_floatconverts a string to floating-point
parse_decimalconverts a string to decimal

Formatting Functions

The following standard functions convert integer numbers into a string of hex, octal or binary representations.

FunctionDescription
to_binaryconverts an integer number to binary
to_octalconverts an integer number to octal
to_hexconverts an integer number to hex

Floating-point Constants

The following functions return standard mathematical constants.

FunctionDescription
PIreturns the value of π
Ereturns the value of e