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( val FLOAT ) RETURNING rv FLOAT

Notes:

  1. val is a floating point value.

Usage:

The function 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( x FLOAT, y FLOAT ) RETURNING rv FLOAT

Notes:

  1. x is the value to be raised.
  2. y is is the power operand.

Usage:

The function returns NULL if one of the argument provided is invalid.

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 the value passed as parameter.

Syntax:

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

Notes:

  1. val is a floating point value.

Usage:

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()

Usage:

The srand() function initializes the pseudo-random numbers generator. It must be called before subsequent calls to the rand() function. If you do not call this function, the rand() function will generate the same sequence of numbers for every program execution.


util.Math.rand

Purpose:

This function returns a positive pseudo-random number.

Syntax:

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

Notes:

  1. max is the maximum random number that can be generated. Numbers will be in the range 0 to max.
    Note that the max value returned by the function cannot be greater as 32767 on most platforms.

Usage:

The srand() function must be called before subsequent calls to the rand() function. If you do not call the srand() function, the rand() function will generate the same sequence of numbers for every program execution.

Note that the maximum random number returned by the rand() function is platform dependent. On most platforms, the max will be 32767. As a general rule, you should pass a number between 0 and 32767 to the rand() function. 

The rand() function returns zero if the argument is lower or equal to 0.


util.Math.sin

Purpose:

This function computes the sine of the passed value, measured in radians.

Syntax:

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

Notes:

  1. val is a floating point value.

Usage:

Returns NULL if the argument provided is invalid.

util.Math.cos

Purpose:

This function computes the cosine of the passed value, measured in radians.

Syntax:

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

Notes:

  1. val is a floating point value.

Usage:

Returns NULL if the argument provided is invalid.

util.Math.tan

Purpose:

This function computes the tangent of the passed value, measured in radians.

Syntax:

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

Notes:

  1. val is a floating point value.

Usage:

Returns NULL if the argument provided is invalid.

util.Math.asin

Purpose:

This function computes the arc sine of the passed value, measured in radians.

Syntax:

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

Notes:

  1. val is a floating point value.

Usage:

Returns NULL if the argument provided is invalid.

util.Math.acos

Purpose:

This function computes the arc cosine of the passed value, measured in radians.

Syntax:

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

Notes:

  1. val is a floating point value.

Usage:

Returns NULL if the argument provided is invalid.

util.Math.atan

Purpose:

This function computes the arc tangent of the passed value, measured in radians.

Syntax:

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

Notes:

  1. val is a floating point value.

Usage:

Returns NULL if the argument provided is invalid.

util.Math.log

Purpose:

This function computes the natural logarithm of the passed value.

Syntax:

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

Notes:

  1. val is a floating point value.

Usage:

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( val FLOAT ) RETURNING rv FLOAT

Notes:

  1. val is a floating point value to be converted to degrees.

util.Math.toRadians

Purpose:

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

Syntax:

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

Notes:

  1. val is a floating point value to be converted to radians.

util.Math.pi

Purpose:

This function returns the FLOAT value of PI.

Syntax:

CALL util.Math.pi() RETURNING rv FLOAT