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:

  • Floor() and Ceil() to calculate the nearest integers not greater than or not less than a given number.
  • Round() to round a number, Trunc() to truncate a number, or TruncLeft() to left-truncate a number. RoundSignificant() rounds a number to a specified number of significant digits.
  • Min() and Max() to return the minimum and maximum of two numbers.
  • Abs() to return the absolute value of a number.
  • Log() and Log10() to compute the natural and base-10 logarithm of a number, Sqrt() to calculate a square root, and Power() to calculate an exponent for a given base.
  • Random() to generate random integers.

  • Class Attributes Index

     o E_Overflow
    Overflow range error -- i.e. math.power( 10, 1000 )
     o E_Singularity
    Argument singularity -- i.e. math.power( 0, -2 )
     o E_StackFault
    Floating point unit stack overflow.
     o E_Underflow
    Underflow range error -- i.e. math.power( 10, -1000 )

    Class Methods Index

     o Abs( Real number )
    Returns the absolute value.
     o Ceil( Real number )
    Returns the number rounded up.
     o Floor( Real number )
    Returns the number rounded down.
     o Log( Real number )
    Returns the natural logarithm.
     o Log10( Real number )
    Returns the base-10 logarithm.
     o Max( Real number1, Real number2 )
    Returns the larger of the numbers.
     o Min( Real number1, Real number2 )
    Returns the smaller of the numbers.
     o Power( Real base, Real exponent )
    Returns the base raised to the exponent.
     o Random( Integer range, [Integer seed] )
    Returns "random" number that is greater than or equal to 0 and less than range.
     o Round( Real number )
    Returns the number rounded to the closest integer.
     o RoundSignificant( Real number, Integer digits )
    Returns the number rounded to the specified number of significant digits.
     o Sqrt( Real number )
    Returns the square root of the number.
     o Trunc( Real number )
    Returns the number without the decimal part.
     o TruncLeft( Real number )
    Returns the number without the whole number part.
     o RoundSignificant( Real number, Integer digits )
    Returns the number rounded to the specified number of significant digits.

    Class Attributes

     o E_Overflow

     Error E_Overflow
    

    Overflow range error -- i.e. math.power( 10, 1000 )

     o E_Singularity

     Error E_Singularity
    

    Argument singularity -- i.e. math.power( 0, -2 )

     o E_StackFault

     Error E_StackFault
    

    Floating point unit stack overflow.

     o E_Underflow

     Error E_Underflow
    

    Underflow range error -- i.e. math.power( 10, -1000 )

    Class Methods

     o Abs
     Real Abs(
            Real number )
    

    Returns the absolute value of the specified number.

    Parameters:
    number  -  An Integer or a Real to be evaluated.
    Returns:
    The absolute value of the specified number as a Real.
     o Ceil
     Real Ceil(
             Real number )
    

    Returns a Real number corresponding to the smallest Integer value that is not smaller than the specified number.

    Parameters:
    number  -  A Real number.
    Returns:
    A Real number corresponding to the smallest Integer value that is not smaller than the specified 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
     o Floor
     Real Floor(
             Real number )
    

    Returns a Real number corresponding to the largest Integer value that is not larger than the specified number.

    Parameters:
    number  -  A Real number.
    Returns:
    A Real number corresponding to the largest Integer value that is not smaller than the specified number.

    See Ceil() for an example.

     o Log
     Real Log(
            Real number )
    

    Computes the natural logarithm of the specified number.

    Parameters:
    number  -  Specifies an Integer or a Real which should be non-zero and positive.
    Returns:
    A Real number corresponding to the natural logarithm, if number is a non-zero, positive value; Undefined otherwise.
     o Log10
     Real Log10(
             Real number )
    

    Computes the base-10 logarithm of the specified number.

    Parameters:
    number  -  An Integer or Real which should be non-zero and positive.
    Returns:
    A Real number corresponding to the base-10 logarithm, if number is a non-zero, positive value; Undefined otherwise.

    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
     o Max
     Real Max(
            Real number1,
            Real number2 )
    

    Returns the larger of two given numbers.

    Parameters:
    number1  -  An Integer or a Real which is one number to be compared.
    number2  -  An Integer or a Real which is compared to number1.
    Returns:
    The Real which is the larger value, if successful; Undefined otherwise. Note: The Real value returned can be converted into an Integer by storing the result in an Integer.
     o Min
     Real Min(
            Real number1,
            Real number2 )
    

    Returns the smaller of two given numbers.

    Parameters:
    number1  -  An Integer or a Real which is one number to be compared.
    number2  -  An Integer or a Real which is compared to number1.
    Returns:
    A Real which is the smaller value, if successful; Undefined otherwise. Note: The Real value returned can be converted into an Integer by storing the result in an Integer.
     o Power
     Real Power(
             Real base,
             Real exponent )
    

    Raises the specified base number to the specified exponent power.

    Parameters:
    base  -  A Real or Integer.
    exponent  -  A Real or Integer.
    Returns:
    Specifies any number, Real or Integer. Note: The Real value returned can be forced into an Integer by storing the result in an Integer, if needed.

    See Log10() for an example.

     o Random
     Integer Random(
                 Integer range,
                [Integer seed] )
    

    Generates and returns a pseudo-random Integer within the specified range.

    Parameters:
    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.
    Returns:
    A pseudo-random Integer in the range from 0 to less than range.

    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.

     o Round
     Real Round(
             Real number )
    

    Rounds the specified number up or down to the next closest Integer.

    Parameters:
    number  -  A Real indicating the number to round.
    Returns:
    A Real number rounded to the next closest Integer value (i.e. 1.5 -> 2, 1.4 -> 1).

    See Ceil() for an example.

     o RoundSignificant
     Integer RoundSignificant(
               Real number,
               Integer digits )
    

    Rounds the specified number to the specified number of significant digits

    Parameters:
    number  -  A Real indicating the number to round.
    digits  -  The number of significant digits to round to.
    Returns:
    An integer number rounded to the number of significant digits.
     o Sqrt
     Real Sqrt(
             Real number )
    

    Calculates the square root of the specified number.

    Parameters:
    number  -  An Integer or a Real indicating the number on which to operate.
    Returns:
    The square root of the specified number as a Real, if successful; Undefined otherwise.

    See Log10() for an example.

     o Trunc
     Real Trunc(
             Real number )
    

    Truncates the decimal part of a Real number.

    Parameters:
    number  -  A Real number to be truncated.
    Returns:
    A Real number whose signed numerals to the left of the decimal point are the same as the specified number and whose numerals to the right of the decimal point are set to zero, if successful; Undefined otherwise.

    See Ceil() for an example.

     o TruncLeft
     Real TruncLeft(
               Real number )
    

    Truncates the whole number part from a Real number.

    Parameters:
    number  -  A Real number to be left-truncated.
    Returns:
    A Real number whose sign and numerals to the right of the decimal point are the same as the specified number and whose numerals to the left of the decimal point are set to zero, if successful; Undefined otherwise.

    See Ceil() for an example.