Numeric Functions
Integer Functions
The following standard functions are defined.
| Function | Not available under | Package | Description | 
|---|---|---|---|
| is_oddmethod and property | ArithmeticPackage | returns trueif the value is an odd number, otherwisefalse | |
| is_evenmethod and property | ArithmeticPackage | returns trueif the value is an even number, otherwisefalse | |
| min | LogicPackage | returns the smaller of two numbers | |
| max | LogicPackage | returns the larger of two numbers | |
| to_float | no_float | BasicMathPackage | convert the value into f64(f32underf32_float) | 
| to_decimal | non- decimal | BasicMathPackage | convert the value into Decimal | 
Signed Numeric Functions
The following standard functions are defined in the ArithmeticPackage
(excluded when using a raw Engine) and operate on i8, i16, i32, i64, f32, f64 and
Decimal (requires decimal) only.
| Function | Description | 
|---|---|
| abs | absolute value | 
| sign | returns ( INT) −1 if negative, +1 if positive, 0 if zero | 
| is_zeromethod and property | returns trueif the value is zero, otherwisefalse | 
Floating-Point Functions
The following standard functions are defined in the BasicMathPackage
(excluded when using a raw Engine) and operate on f64 (f32 under f32_float) and
Decimal (requires decimal) only.
| Category | Supports Decimal | Functions | 
|---|---|---|
| Trigonometry | yes | sin,cos,tan | 
| Trigonometry | no | sinh,cosh,tanhin radians,hypot(x,y) | 
| Arc-trigonometry | no | asin,acos,atan(v),atan(x,y),asinh,acosh,atanhin radians | 
| Square root | yes | sqrt | 
| Exponential | yes | exp(base e) | 
| Logarithmic | yes | ln(base e) | 
| Logarithmic | yes | log(base 10) | 
| Logarithmic | no | log(x,base) | 
| Rounding | yes | floor,ceiling,round,int,fractionmethods and properties | 
| Conversion | yes | to_int,to_decimal(requiresdecimal),to_float(not underno_float) | 
| Conversion | no | to_degrees,to_radians | 
| Comparison | yes | min,max(also inter-operates with integers) | 
| Testing | no | is_nan,is_finite,is_infinitemethods and properties | 
Decimal Rounding Functions
The following rounding methods are defined in the BasicMathPackage
(excluded when using a raw Engine) and operate on Decimal only,
which requires the decimal feature.
| Rounding type | Behavior | Methods | 
|---|---|---|
| None | floor,ceiling,int,fractionmethods and properties | |
| Banker’s rounding | round to integer | roundmethod and property | 
| Banker’s rounding | round to specified number of decimal points | round(decimal points) | 
| Round up | away from zero | round_up(decimal points) | 
| Round down | towards zero | round_down(decimal points) | 
| Round half-up | mid-point away from zero | round_half_up(decimal points) | 
| Round half-down | mid-point towards zero | round_half_down(decimal points) | 
Parsing Functions
The following standard functions are defined in the BasicMathPackage
(excluded when using a raw Engine) to parse numbers.
| Function | No available under | Description | 
|---|---|---|
| parse_int | converts a string to INTwith an optional radix | |
| parse_float | no_floatand non-decimal | converts a string to FLOAT(Decimalunderno_floatanddecimal) | 
| parse_decimal | non- decimal | converts a string to Decimal | 
Formatting Functions
The following standard functions are defined in the BasicStringPackage
(excluded when using a raw Engine) to convert integer numbers into a string of hex, octal
or binary representations.
| Function | Description | 
|---|---|
| to_binary | converts an integer number to binary | 
| to_octal | converts an integer number to octal | 
| to_hex | converts an integer number to hex | 
These formatting functions are defined for all available integer numbers – i.e. INT, u8,
i8, u16, i16, u32, i32, u64, i64, u128 and i128 unless disabled by feature flags.
Floating-point Constants
The following functions return standard mathematical constants.
| Function | Description | 
|---|---|
| PI | returns the value of π | 
| E | returns the value of e | 
Numerical Functions for Scientific Computing
Check out the rhai-sci crate for more numerical functions.