Math (Non-Trigonometric) Functions

 

Each function below returns a numeric value and can be used where ever a numeric value is appropriate. The examples below show some ways functions can be used. Of course, actual Raptor programs may use different functions in different ways to achieve the progammer's desired functionality.

 

In Assignments:

x_magnitude <- abs(x)

product <- e^(log(factor1) + log(factor2))

 

In Select and Loop Exit Comparisons:

log(x) > 0.0

sqrt(c^2) <= sqrt(a^2 + b^2)

random > 0.5 and abs(x) < 100.0

 

Other places where functions can be used include output boxes (when a value is output) and as arguments to calls.

 

Below is an alphabetical listing of the functions.

ABS

variable <- abs(math_expression)

 

abs returns the absolute value of a mathematical expression. For example, abs(-3.7) is 3.7, and abs(23) is 23.

CEILING

variable <- ceiling(math_expression)

 

ceiling returns the lowest integer value greater than or equal to the provided argument. For example, ceiling(15.9) is 16, ceiling(3.1) is 4, ceiling(-4.1) is -4, and ceiling(23) is 23.

E

variable <- e^x

 

e returns the natural logarithm base (approximately 2.7). This is a constant function that takes no arguments and always returns the same value. Note that its existence means that a Raptor programmer may not use a variable called e.

FLOOR

variable <- floor(math_expression)

 

floor returns the highest integer value less than or equal to the provided argument. For example, floor(15.9) is 15, floor(3.1) is 3, floor(-4.1) is -5, and floor(23) is 23.

LOG

variable <- log(math_expression)

 

log returns the natural (base e) logarithm of the provided argument. A zero or negative argument results in a run-time error in the program.

MAX

variable <- max(math_expression, max_expression)

 

max returns the maximum of the two provided arguments.  For example,  max(5,7) returns 7.

MIN

variable <- min(math_expression, max_expression)

 

min returns the minimum of the two provided arguments.  For example,  min(5,7) returns 5.

PI

radians <- degrees * (pi / 180)

 

pi returns the ratio of a circle's circumference to its diameter (approximately 3.14159). This is a constant function that takes no arguments and always returns the same value.

POWERMOD

variable <- powermod(base, exp, modulus)

 

powermod, unlike most of the functions described here, takes three arguments. The function returns ((base^exp) mod modulus). Its primary use is for RSA public key encryption and decryption. powermod is provided so that bases and exponents too large for the Raptor exponentiation operator can still be used for encryption.

RANDOM

variable <- random

 

random takes no arguments. The function returns a random number in the range [0.0,1.0). That is, it may sometimes return 0.0 but will never return 1.0. To generate a random integer from 1 to n, use floor((random*n) + 1). For example, you can simulate the roll of a die (random number from 1 to 6) with floor((random * 6) + 1).

SQRT

variable <- sqrt(math_expression)

 

sqrt returns the square root of the provided argument. A negative argument results in a run-time error in the program.