Back to Contents


Mathematical functions Class

Summary:

See also: Built-in Functions


Basics

The Math class provides mathematical functions.

This API is provided as a Dynamic C Extension library; it is part of the standard package.

To use this extension, you must import the util package in your program:

IMPORT util

Syntax

The Math class is a provides an interface for mathematical functions.

Syntax:

util.Math

Notes:

  1. This class does not have to be instantiated; it provides class methods for the current program.

Methods:

Class Methods
Name Description
sqrt This function computes the square root of its argument.
pow This function computes the value of x raised to the power y.
exp This function computes the base- e exponential of x.
srand This function intializes the pseudo-random number generator.
rand This function returns a pseudo-random number.
sin This function computes the sine of their argument x, measured in radians.
cos This function computes the cosine of their argument x, measured in radians.
tan This function computes the tangent of their argument x, measured in radians.
asin This function computes the arc sine of their argument x, measured in radians.
acos This function computes the arc cosine of their argument x, measured in radians.
atan This function computes the arc tangent of their argument x, measured in radians.
log This function computes the natural logarithm of the argument x.
toDegrees Converts an angle measured in radians to an equivalent angle measured in degrees.
toRadians Converts an angle measured in degrees to an equivalent angle measured in radians.
pi This function returns the FLOAT value of PI.

util.Math.sqrt

Purpose:

Returns the square root of the argument provided.

Syntax:

CALL util.Math.sqrt(FLOAT f) RETURNING rv FLOAT

Notes:

  1. Returns NULL if the argument provided is invalid.

util.Math.pow

Purpose:

This function computes the value of x raised to the power y.

Syntax:

CALL util.Math.pow(FLOAT x, FLOAT y) RETURNING rv FLOAT

Notes:

  1. Returns NULL if one of the argument provided is invalid.
  2. If x is negative, the caller should ensure that y is an integer value.

util.Math.exp

Purpose:

This function computes the base- e exponential of x.

Syntax:

CALL util.Math.exp(FLOAT x) RETURNING rv FLOAT

Notes:

  1. Returns NULL if the argument provided on error.

util.Math.srand

Purpose:

This function initializes the pseudo-random numbers generator.

Syntax:

CALL util.Math.srand()

util.Math.rand

Purpose:

This function returns a pseudo-random number between 0 and x

Syntax:

CALL util.Math.rand(x INTEGER) RETURNING rv INTEGER

util.Math.sin

Purpose:

This function computes the sine of the argument x, measured in radians.

Syntax:

CALL util.Math.sin(FLOAT f) RETURNING rv FLOAT

Notes:

  1. Returns NULL if the argument provided is invalid.

util.Math.cos

Purpose:

This function computes the cosine of the argument x, measured in radians.

Syntax:

CALL util.Math.cos(FLOAT f) RETURNING rv FLOAT

Notes:

  1. Returns NULL if the argument provided is invalid.

util.Math.tan

Purpose:

This function computes the tangent of the argument x, measured in radians.

Syntax:

CALL util.Math.tan(FLOAT f) RETURNING rv FLOAT

Notes:

  1. Returns NULL if the argument provided is invalid.

util.Math.asin

Purpose:

This function computes the arc sine of the argument x, measured in radians.

Syntax:

CALL util.Math.asin(FLOAT f) RETURNING rv FLOAT

Notes:

  1. Returns NULL if the argument provided is invalid.

util.Math.acos

Purpose:

This function computes the arc cosine of the argument x, measured in radians.

Syntax:

CALL util.Math.acos(FLOAT f) RETURNING rv FLOAT

Notes:

  1. Returns NULL if the argument provided is invalid.

util.Math.atan

Purpose:

This function computes the arc tangent of the argument x, measured in radians.

Syntax:

CALL util.Math.atan(FLOAT f) RETURNING rv FLOAT

Notes:

  1. Returns NULL if the argument provided is invalid.

util.Math.log

Purpose:

This function computes the natural logarithm of the argument x.

Syntax:

CALL util.Math.log(FLOAT f) RETURNING rv FLOAT

Notes:

  1. Returns NULL if the argument provided is invalid.

util.Math.toDegrees

Purpose:

Converts an angle measured in radians to an approximately equivalent angle measured in degrees.

Syntax:

CALL util.Math.toDegrees(FLOAT f) RETURNING rv FLOAT

util.Math.toRadians

Purpose:

Converts an angle measured in degrees to an approximately equivalent angle measured in radians.

Syntax:

CALL util.Math.toRadians(FLOAT f) RETURNING rv FLOAT

util.Math.pi

Purpose:

This function returns the FLOAT value of PI.

Syntax:

CALL util.Math.pi() RETURNING rv FLOAT