OScript API/Built-in Package Index |
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:
Overflow range error -- i.e. math.power( 10, 1000 )
Argument singularity -- i.e. math.power( 0, -2 )
Floating point unit stack overflow.
Underflow range error -- i.e. math.power( 10, -1000 )
Returns the absolute value.
Returns the number rounded up.
Returns the number rounded down.
Returns the natural logarithm.
Returns the base-10 logarithm.
Returns the larger of the numbers.
Returns the smaller of the numbers.
Returns the base raised to the exponent.
Returns "random" number that is greater than or equal to 0 and less than range.
Returns the number rounded to the closest integer.
Returns the integer part of a number rounded to the specified number of significant digits.
Returns the integer part of a number rounded to the specified number of significant digits.
Returns the number rounded to the specified number of significant digits.
Returns the square root of the number.
Returns the number without the decimal part.
Returns the number without the whole number part.
Not used.
Not used.
Argument singularity -- i.e. math.power( 0, -2 )
Floating point unit stack overflow.
Underflow range error -- i.e. math.power( 10, -1000 )
Returns the absolute value of the specified number.
An Integer or a Real to be evaluated.
The absolute value of the specified number as a Real.
Returns a Real number corresponding to the smallest Integer value that is not smaller than the specified number.
A Real number.
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
Returns a Real number corresponding to the largest Integer value that is not larger than the specified number.
A Real number.
A Real number corresponding to the largest Integer value that is not smaller than the specified number.
See Ceil() for an example.
Computes the natural logarithm of the specified number.
Specifies an Integer or a Real which should be non-zero and positive.
A Real number corresponding to the natural logarithm, if number is a non-zero, positive value; Undefined otherwise.
Computes the base-10 logarithm of the specified number.
An Integer or Real which should be non-zero and positive.
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
Returns the larger of two given numbers.
An Integer or a Real which is one number to be compared.
An Integer or a Real which is compared to number1.
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.
Returns the smaller of two given numbers.
An Integer or a Real which is one number to be compared.
An Integer or a Real which is compared to number1.
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.
Raises the specified base number to the specified exponent power.
A Real or Integer.
A Real or Integer.
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.
Generates and returns a pseudo-random Integer within the specified range.
A positive Integer which is the upper limit for the generated random number, all generated random integers will be less than range.
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.
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.
Rounds the specified number up or down to the next closest Integer.
A Real indicating the number to round.
A Real number rounded to the next closest Integer value (i.e. 1.5 -> 2, 1.4 -> 1).
See Ceil() for an example.
Rounds the integer part of a number to the specified number of significant digits
A real number to round. If a value of zero is provided, the function will return MININTEGER.
A positive integer indicating the number of significant digits to round to. If a zero or negative number is provided, the function will return zero.
An integer number rounded to the number of significant digits.
Examples: Echo( Math.RoundSignificant( 0, 1 ) ) Echo( Math.RoundSignificant( 12.3, -1 ) ) Echo( Math.RoundSignificant( 12.3, 0 ) ) Echo( Math.RoundSignificant( 12.3, 1 ) ) Echo( Math.RoundSignificant( 12.3, 2 ) ) Echo( Math.RoundSignificant( 12.3, 3 ) ) The outputs of the examples are: -2147483648 0 0 10 12 12
Rounds the integer part of a number to the specified number of significant digits. It is an alias of RoundSignificant
A real number to round. If a value of zero is provided, the function will return MININTEGER.
A positive integer indicating the number of significant digits to round to. If a zero or negative number is provided, the function will return zero.
An integer number rounded to the number of significant digits.
See [[RoundSignificant()]] for examples.
Rounds the number to the specified number of significant digits
A real number to round. If a value of zero is provided, the function will return Undefined.
A positive integer indicating the number of significant digits to round to. If a zero or negative number is provided, the function will return Undefined.
A real number rounded to the number of significant digits.
Examples: Echo( Math.RoundSignificantReal( 0, 1 ) ) Echo( Math.RoundSignificantReal( 12.3, -1 ) ) Echo( Math.RoundSignificantReal( 12.3, 0 ) ) Echo( Math.RoundSignificantReal( 12.3, 1 ) ) Echo( Math.RoundSignificantReal( 12.3, 2 ) ) Echo( Math.RoundSignificantReal( 12.3, 3 ) ) The outputs of the examples are: Undefined Undefined Undefined 10 12 12.3
Calculates the square root of the specified number.
An Integer or a Real indicating the number on which to operate.
The square root of the specified number as a Real, if successful; Undefined otherwise.
See Log10() for an example.
Truncates the decimal part of a Real number.
A Real number to be truncated.
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.
Truncates the whole number part from a Real number.
A Real number to be left-truncated.
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.
Copyright © 2021 OpenText Corporation. All rights reserved. |