The built-in functions in the Math Package allow mathematical operations to be performed upon integer and real number data. Note: All integers automatically convert to Reals with no data loss. All Reals automatically convert to Integers by being truncated.
The Math Package offers the following functionality:
Error E_Overflow
Overflow range error -- i.e. math.power( 10, 1000 )
Error E_Singularity
Argument singularity -- i.e. math.power( 0, -2 )
Error E_StackFault
Floating point unit stack overflow.
Error E_Underflow
Underflow range error -- i.e. math.power( 10, -1000 )
AbsReal Abs( Real number )
Returns the absolute value of the specified number.
number | - | An Integer or a Real to be evaluated. |
Real Ceil( Real number )
Returns a Real number corresponding to the smallest Integer value that is not smaller than the specified number.
number | - | A Real number. |
Here is an example showing the effect of various truncation-related Math functions:
Real num = 3.14159 Echo( num ) Echo( Math.Floor( num ) ) Echo( Math.Ceil( num ) ) Echo( Math.Round( num ) ) Echo( Math.Trunc( num ) ) Echo( Math.TruncLeft( num ) )
The output of the example is:
3.14159 3 4 3 3 0.14159
Real Floor( Real number )
Returns a Real number corresponding to the largest Integer value that is not larger than the specified number.
number | - | A Real number. |
See Ceil() for an example.
Real Log( Real number )
Computes the natural logarithm of the specified number.
number | - | Specifies an Integer or a Real which should be non-zero and positive. |
Real Log10( Real number )
Computes the base-10 logarithm of the specified number.
number | - | An Integer or Real which should be non-zero and positive. |
This short example demonstrates how logarithms can be used to calculate the square root of two:
Echo( Math.Power( 10, Math.Log10( 2 ) / 2 ) ) Echo( Math.Sqrt( 2 ) )
The output of the example is:
1.4142135623731 1.4142135623731
Real Max( Real number1, Real number2 )
Returns the larger of two given numbers.
number1 | - | An Integer or a Real which is one number to be compared. |
number2 | - | An Integer or a Real which is compared to number1. |
Real Min( Real number1, Real number2 )
Returns the smaller of two given numbers.
number1 | - | An Integer or a Real which is one number to be compared. |
number2 | - | An Integer or a Real which is compared to number1. |
Real Power( Real base, Real exponent )
Raises the specified base number to the specified exponent power.
base | - | A Real or Integer. |
exponent | - | A Real or Integer. |
See Log10() for an example.
Integer Random( Integer range, [Integer seed] )
Generates and returns a pseudo-random Integer within the specified range.
range | - | A positive Integer which is the upper limit for the generated random number, all generated random integers will be less than range. |
seed | - | An optional Integer indicating a seed for the set of random numbers from which the returned random number is selected. Defaults to a random seed if not specified. |
Note: Successive execution of the Math.Random function results in a pseudo-random sequence of numbers. Therefore, seed should only be specified once per sequence of random numbers. Specifying the same seed for successive calls to the Math.Random function always generates the same set of numbers.
Real Round( Real number )
Rounds the specified number up or down to the next closest Integer.
number | - | A Real indicating the number to round. |
See Ceil() for an example.
Integer RoundSignificant( Real number, Integer digits )
Rounds the specified number to the specified number of significant digits
number | - | A Real indicating the number to round. |
digits | - | The number of significant digits to round to. |
Real Sqrt( Real number )
Calculates the square root of the specified number.
number | - | An Integer or a Real indicating the number on which to operate. |
See Log10() for an example.
Real Trunc( Real number )
Truncates the decimal part of a Real number.
number | - | A Real number to be truncated. |
See Ceil() for an example.
Real TruncLeft( Real number )
Truncates the whole number part from a Real number.
number | - | A Real number to be left-truncated. |
See Ceil() for an example.