PilotScript Math Functions

The following math functions are available for PilotScript components.

Math Function Name/Prototype Description Example

Abs

Number Abs(Number x)
Returns the absolute value of x.

Abs(1.4) returns 1.4

Abs(-1.4) also returns 1.4

Acos

Number Acos(Number x)
Returns the arccosine of x. The return value is in radians.

Acos(0) returns 1.570796 (i.e., pi/2)

Acos(1) returns 0

Asin

Number Asin(Number x)
Returns the arcsine of x. The return value is in radians.

Asin(0) returns 0

Asin(1) returns 1.570796 (i.e., pi/2)

Atan

Number Atan(Number x)
Returns the arctangent of x. The rReturn value is in radians.

Atan(0) returns 0

Atan(1) returns 0.785398 (that is, pi/4)

Atan2

Number Atan2(Number x, Number y)
Returns the angle between the x axis and the vector from the origin to the point (x, y). If both x and y are positiv, this is equivalent to Atan(y/x) If there is a possibility that x is zero (which would result in an infinite argument to Atan), use this function in preference to Atan . Thereturn value is in radians.

Atan2(1, 0) returns 1.570796 (i.e., pi/2)

Atan2(0, 1) returns 0

Avg

Number Avg(Number x1, Number x2[, ...])
Takes one or more numerical expressions and returns the average (mean) value. Avg(1, 2, 3, 4) returns 2.5

Bin

Number Bin(Number x, Number binsize)
Returns the bin number that the value x would fall into, given the bin size. The values in the range [(n-0.5)*binsize, (n+0.5)*binsize) are in bin (n*binsize).

Bin(149, 100) returns 100

Bin(199, 100) returns 200

Bin(7.6, 0.5) returns 7.5

Bin(7.8, 0.5) returns 8.0

Ceiling

Number Ceiling(Number x)
Returns the smallest integer that is greater than or equal to x.

Ceiling(-2.8) returns -2.0

Ceiling(2.8) returns 3

Cos

Number Cos(Number x)
Returns the cosine of x; x must be in radians. Cos(0) returns 1

Exp

Number Exp(Number x)
Returns the value x. Exp(1) returns 2.71828

Floor

Number Floor(Number x)
Rounds downward to the nearest integer and returns the largest integer less than or equal to x.

Floor(-2.8) returns -3

Floor(2.8) returns 2

GetNA

Number GetNA()
Returns the special Pipeline Pilot NA floating point value. NA represents missing or unknown numeric data and is a species of IEEE 754 NaN.
IF not IsNumber(response) 
 THEN response := GetNA(); 
END IF;

Here, the property "response" is expected to have a numeric value. If the property value on a given data record is not convertible to a number, then the value is replaced with NA.

IsFinite

Boolean IsFinite (Number value)
Returns True if the value is a finite number. Returns False if value is either NaN (Not a Number), positive infinity, or negative infinity.

IsFinite(1.0/0.0) returns False

IsFinite(GetNA()) returns False

IsFinite(9.9e99) returns True

IsInfinite

Boolean IsInfinite (Number value)
Returns True if value is either positive or negative infinity orreturns False if the value is finite or NaN (Not a Number).

IsInfinite(1.0/0.0) returns True

IsInfinite(GetNA()) returns False

IsInfinite(9.9e99) returns False

IsNA

Boolean IsNA(Number value)
Returns True if value is the special Pipeline Pilot NA floating point value. NA represents missing or unknown numeric data and is a species of IEEE 754 NaN. Returns False for any other value.

IsNA(1.0/0.0) returns False

IsNA(GetNA()) returns True

IsNA(0.0/0.0) returns False

IsNaN

Boolean IsNaN (Number value)
Returns True if value cannot be represented as a number. Returns False if value is a finite number, positive infinity, or negative infinity.

IsNaN(1.0/0.0) returns False

IsNaN(GetNA()) returns True

IsNaN(0.0/0.0) returns True

Log

Number Log(Number x)
Returns the natural logarithm of x.

Log(10.0) returns 2.302585

Log(100) returns 4.60517

Log10

Number Log10(Number x)
Returns the base 10 logarithm of x.

Log10(10.0) returns 1.0

Log10(100) returns 2.0

Max

Number Max(Number x, Number y)
Returns the maximum value of x and y. Max(-3.0, 1.2) returns 1.2

Min

Number Min(Number x, Number y)
Returns the minimum value of x and y. Min(-3.0, 1.2) returns -3.0

Mod

Number Mod(Number x, Number y)
Using integer math, returns the remainder of x divided by y. If y is zero, the result is undefined.

Mod(17, 3) returns 2

Mod(4.8, 2) returns 0

Pi

Number Pi()
Returns the value of pi. Pi() returns 3.14159

Power

Number Power(Number x, Number y)
Returns the value x^y. Raising a negative number to a non-integer power produces undefined results.

Power(-2,3) returns -8

Power(-2,3.1) returns NaN (not-a-number)

Rand

Number Rand()
Returns a pseudo-random number, uniformly distributed in the range [0.0, 1.0). The sequence of random numbers is local to the component and not affected by uses of Rand() in other components. Use SRand() to set the seed for a random number generator. For a more robust random number generator, see Rand64(). For Rand, the sequence of pseudo-random number repeats itself after approximately one million values. The period for Rand64 is orders of magnitude greater.
value := Floor(Rand() * 10 + 1);

Assigns a random integer between 1 and 10 inclusive to the property named "value".

Rand64

Number Rand64()

Returns a pseudo-random number uniformly distributed in the range [0.0, 1.0). The sequence of random numbers is local to the component and not affected by uses of Rand64() in other components. For Rand, the sequence of pseudo-random number repeats itself after about one million values. The period for Rand64 is orders of magnitude greater.

To set the seed for random number generator, use SRand64().

value := Floor(Rand64() * 10 + 1);

Assigns a random integer between 1 and 10 inclusive to the property named "value".

Sign

Number Sign(Number x)

Returns an integer indicating the sign of a number.

  • If number > 0, returns 1
  • If number = 0, returns 0
  • If number < 0, returns -1

Sign(2.763) return 1

Sign(-0.6) returns -1

Sign(0) returns 0

Sin

Number Sin(Number x)
Returns the sine of x. Note that x must be in radians. Sin(0) returns 0

Sqrt

Number Sqrt(Number x)
Returns the square root of x. Taking a square root of a negative number produces undefined results.

Sqrt(2) returns 1.41421

Sqrt(-5) returns NaN (not-a-number)

SRand

None SRand(Number x)
Seeds the random number generator with the value x. Use the Rand() function to retrieve random number values. If x is not specified, then the random number generator is seeded with a value from the system clock. It is typical to call SRand() in the Initial Expression to prepare for the arrival of data. (If SRand() is not called before calling Rand(), then the same sequence of numbers occurs each time.) The sequence of random numbers generated is local to the component in which SRand() is called. Random states in other components remain unaffected.
SRand(12345);

Seeds the random number generator with the value 12345. With such a fixed-value seed, the sequence of random numbers will be the same each time the protocol is run.

SRand64

None SRand64(Number x)

Seeds the random number generator with the value x. Use the Rand64() function to retrieve random number values. If x is not specified, then the random number generator is seeded with a value from the system clock.

It is typical to call SRand64() in the Initial Expression to prepare for the arrival of data. (If SRand64() is not called before calling Rand64(), then the same sequence of numbers occurs each time.) The sequence of random numbers generated is local to the component in which SRand64() is called. Random states in other components remain unaffected.

SRand64(12345);

Seeds the random number generator with the value 12345. With such a fixed-value seed, the sequence of random numbers will be the same each time the protocol is run.

Sum

Number Sum(Number x1, Number x2[, ...])
Takes one or more numerical expressions and returns the sum. Sum(1, 2, 3, 4) returns 10

Tan

Number Tan(Number x)
Returns the tangent of x; x must be in radians. Tan(0) returns 0