Math Functions

AeroScript includes many functions that let you do basic math operations, including exponential, square root, logarithmic, rounding, remainder, and trigometric calculations.

Exponential, Square Root, and Logarithmic Functions

Use the Exp(), Sqrt(), and Log() functions to compute exponential, square root, and logarithmic values. Restricted operations, such as the square root of a negative number, cause a runtime error.

Exponential

The example that follows shows how to use the Exp() function with different input values. This function returns Euler's number raised to the power of a specified number.

// Set $rglobal[0] to Euler’s number raised to the power of 5.5
// (~244.692).
$rglobal[0] = Exp(5.5)

// The line that follows generates a task error because the result is
// too large to express as a real value.
$rglobal[1] = Exp(1e308)

To calculate the value of Euler’s number, specify a value of 1 to the Exp() function. Refer to the example that follows.

// Set $rglobal[2] to Euler’s number (~2.71828).
$rglobal[2] = Exp(1)

Square Root

The example that follows shows how to use the Sqrt() function with different input values. This function returns the square root of a number.

// Set $rglobal[0] to the square root of 1024 (32.0).
$rglobal[0] = Sqrt(1024.0)

// Set $rglobal[1] to the square root of 123 (~11.091).
$rglobal[1] = Sqrt(123)

// The line that follows generates a task error because the input value
// is not within the range of acceptable domain values.
$rglobal[2] = Sqrt(-2)

Logarithm

The example that follows shows how to use the Log() function with different input values. This function returns the natural logarithm of a number.

// Set $rglobal[0] to e (~2.718).
// Set $rglobal[1] to the base-e logarithm of e (1.0).
$rglobal[0] = Exp(1)
$rglobal[1] = Log($rglobal[0])

// Set $rglobal[2] to the base-e logarithm of 123 (~4.812).
$rglobal[2] = Log(123)

// The line that follows generates a task error because the input value
// is not within the range of acceptable domain values.
$rglobal[3] = Log(-0.5)

The example that follows shows how to use the Log10() function with different input values. This function returns the common logarithm of a number.

// Set $rglobal[0] to the base-10 logarithm of 100 (2.0).
$rglobal[0] = Log10(100)

// Set $rglobal[1] to the base-10 logarithm of 123 (~2.090).
$rglobal[1] = Log10(123)

// The line that follows generates a task error because the input value
// is not within the range of acceptable domain values.
$rglobal[2] = Log10(-1.23)

The example that follows shows how to use the Log2() function with different input values. This function returns the binary logarithm of a number.

// Set $rglobal[0] to the base-2 logarithm of 1024 (10.0).
$rglobal[0] = Log2(1024)

// Set $rglobal[1] to the base-2 logarithm of 123 (~6.943).
$rglobal[1] = Log2(123)

// The line that follows generates a task error because the input value
// is not within the range of acceptable domain values.
$rglobal[2] = Log2(-1.0)

Rounding and Remainder Functions

AeroScript includes functions that let you round numbers and get the remainder of numbers.

Rounding

Use the Abs(), Ceil(), Floor(), Round(), functions to compute rounding values.

The example that follows shows how to use the Abs() function with different input values. This function calculates the absolute value of a number.

// Set $rglobal[0] to the absolute value of -123 (123.0).
$rglobal[0] = Abs(-123)

// Set $rglobal[1] to the absolute value of 35.4 (35.4).
$rglobal[1] = Abs(35.4)

The example that follows shows how to use the Ceil() function with different input values. This function returns the nearest integer that is greater than or equal to a number.

// Set $rglobal[0] to 32.001 rounded up to the nearest integer as a 
// floating-point value (33.0).
$rglobal[0] = Ceil(32.001)

// Set $rglobal[1] to -12.3 rounded up to the nearest integer as a
// floating-point value (-12.0).
$rglobal[1] = Ceil(-12.3)

// The Ceil() function produces floating-point values that are always
// integers, so they can be assigned to an integer variable.
$iglobal[0] = Ceil($rglobal[0])
			

The example that follows show how to use the Floor() function with different input values. This function returns the nearest integer that is less than or equal to a number.

// Set $rglobal[0] to 32.999 rounded down to the nearest integer as 
// a floating-point value (32.0).
$rglobal[0] = Floor(32.999)

// Set $rglobal[1] to -96.1 rounded down to the nearest integer as a
// floating-point value (-97.0).
$rglobal[1] = Floor(-96.1)

// The Floor() function produces floating-point values that are
// always integers, so they can be assigned to an integer variable.
$iglobal[0] = Floor($rglobal[0])

The example that follows shows how to use the Round() function with different input values. This function returns a number rounded to the nearest integer.

// Set $rglobal[0] to 19.158 rounded to the nearest integer (19.0).
$rglobal[0] = Round(19.158)

// Set $rglobal[1] to -24.158 rounded to the nearest integer (-24.0).
$rglobal[1] = Round(-24.158)

// Set $rglobal[2] to -19.5 rounded to the nearest integer (-20.0).
$rglobal[2] = Round(-19.5)

// The Round() function produces floating-point values that are
// always integers, so they can be assigned to an integer variable.
$iglobal[0] = Round($rglobal[0])

Remainder

The Trunc() and Frac() functions let you get parts of fractional numbers.

To get the integer part of a number, use the Trunc() function. The example that follows shows how to use the Trunc() function with different input values.

// Set $rglobal[0] to 16.361 with its fractional part removed
// (16.0).
$rglobal[0] = Trunc(16.361)

// Set $rglobal[1] to -8.412 with its fractional part removed (-8.0).
$rglobal[1] = Trunc(-8.412)

// The Trunc() function produces floating-point values that are
// always integers, so they can be assigned to an integer variable.
$iglobal[0] = Trunc($rglobal[0])
				

To get the fractional part of a number, use the Frac() function. The examples that follow show how to use the Frac() function with different input values.

// Set $rglobal[0] to the fractional portion of 10.967 (0.967).
$rglobal[0] = Frac(10.967)

// Set $rglobal[1] to the fractional portion of -24.134 (-0.134).
$rglobal[1] = Frac(-24.134)

// Set $rglobal[2] to the fractional portion of 19.000 (0.0).
$rglobal[2] = Frac(19.000

Trigonometric Functions

AeroScript supplies functions to do trigonometric calculations, including arccosine, arcsine, arctangent, cosine, sine, and tangent. Restricted operations, such as the arccosine of -2, cause a compiler error or runtime error.

The mathematical constant π (pi), the ratio of a circle’s circumference to its diameter, is commonly used in trigonometric functions. You can define the value of π in your program. Refer to the example that follows.

#define PI 3.14159265358979323846

Inverse (Arc) Trigonometric Operations

The example that follows shows how to use the Acos() function with different input values. This function returns the arccosine of a number.

// Set $rglobal[0] to the arccosine of 1.0 (0.0).
$rglobal[0] = Acos(1.0)

// Set $rglobal[1] to the arccosine of 0.0 (π/2 or ~1.571).
$rglobal[1] = Acos(0.0)

// The line that follows generates a task error because the input value
// is not within the range of acceptable domain values.
$rglobal[2] = Acos(2)

The example that follows shows how to use the Asin() function with different input values. This function returns the arcsine of a number.

// Set $rglobal[0] to the arcsine of 1.0 (π/2 or ~1.571).
$rglobal[0] = Asin(1.0)

// Set $rglobal[1] to the arcsine of 0.0 (0.0).
$rglobal[1] = Asin(0.0)

// The line that follows generates a task error because the input value
// is not within the range of acceptable domain values.
$rglobal[2] = Asin(-2)

The example that follows shows how to use the Atan() function with different input values. This function returns the arctangent of a number.

// Set $rglobal[0] to the arctangent of 0.0 (0.0).
$rglobal[0] = Atan(0.0)

// Set $rglobal[1] to the arctangent of 1.0 (π/4 or ~0.785).
$rglobal[1] = Atan(1.0)

The examples that follow show how to use the Atan2() function with different input values. This function returns the arctangent of the quotient of two numbers.

// Set $rglobal[0] to the arctangent when y = 0.0 and x = 5.3 (0.0).
$rglobal[0] = Atan2(0.0, 5.3)

// Set $rglobal[1] to the arctangent when y = 1.0 and x = 0.0 (π/2
// or ~1.571).
$rglobal[1] = Atan2(1.0, 0.0)

// Set $rglobal[2] to the arctangent when y = 1.0 and x = 1.0 (π/4
// or ~0.785).
$rglobal[2] = Atan2(1.0, 1.0)

// Set $rglobal[3] to the arctangent when y = -1.0 and x = 1.0 (-π/4
// or ~-0.785).
$rglobal[3] = Atan2(-1.0, 1.0)

// The line that follows generates a task error because the input value
// is not within the range of acceptable domain values.
$rglobal[4] = Atan2(0.0, 0.0)

Trigonometric Operations

The example that follows shows how to use the Cos() function with different input values. This function calculates the cosine of a number.

// Define the mathematical constant pi.
#define PI 3.14159265358979323846

// Set $rglobal[0] to the cosine of π/4 (Sqrt(2) / 2 or ~0.707).
$rglobal[0] = Cos(PI / 4)

// Set $rglobal[1] to the cosine of π (-1.0).
$rglobal[1] = Cos(PI)

The example that follows shows how to use the Sin() function with different input values. This function calculates the sine of a number.

// Define the mathematical constant pi.
#define PI 3.14159265358979323846

// Set $rglobal[0] to the sine of π/4 (Sqrt(2) / 2 or ~0.707).
$rglobal[0] = Sin(PI / 4)

// Set $rglobal[1] to the sine of π (0.0).
$rglobal[1] = Sin(PI)

The example that follows shows how to use the Tan() function with different input values. This function calculates the tangent of a number.

// Define the mathematical constant pi.
#define PI 3.14159265358979323846

// Set $rglobal[0] to the tangent of π/4 (1.0).
$rglobal[0] = Tan(PI / 4)

// Set $rglobal[1] to the tangent of π (0.0).
$rglobal[1] = Tan(PI)

Related Help Pages

Data Type Conversion Example Program