CMATH FUNCTIONS

ABS

Returns a value of the same type that is passed to it specifying the absolute value of a number.

Syntax

Abs(number)

The required number argument can be any valid numeric expression.

Remarks

The absolute value of a number is its unsigned magnitude. For example, ABS(-1) and ABS(1) both return 1.

ATN

Returns the arctangent of a number.

Syntax

Atn(number)

The required number argument is any valid numeric expression.

Remarks

The Atn function takes the ratio of two sides of a right triangle (number) and returns the corresponding angle in radians. The ratio is the length of the side opposite the angle divided by the length of the side adjacent to the angle.

The range of the result is -pi/2 to pi/2 radians.

To convert degrees to radians, multiply degrees by pi/180. To convert radians to degrees, multiply radians by 180/pi.

Note: Atn is the inverse trigonometric function of Tan, which takes an angle as its argument and returns the ratio of two sides of a right triangle. Do not confuse Atn with the cotangent, which is the simple inverse of a tangent (1/tangent).

COS

Returns the cosine of an angle.

Syntax

Cos(number)

The required number argument is any valid numeric expression that expresses an angle in radians.

Remarks

The Cos function takes an angle and returns the ratio of two sides of a right triangle. The ratio is the length of the side adjacent to the angle divided by the length of the hypotenuse.

The result lies in the range -1 to 1.

To convert degrees to radians, multiply degrees by pi/180. To convert radians to degrees, multiply radians by 180/pi.

EXP

Returns e (the base of natural logarithms) raised to a power.

Syntax

Exp(number)

The required number argument is any valid numeric expression.

Remarks

If the value of number exceeds 709.782712893, an error occurs. The constant e is approximately 2.718282.

Note: The Exp function complements the action of the Log function and is sometimes referred to as the antilogarithm.

INT, FIX

Returns a value of the type passed to it containing the integer portion of a number.

Syntax

Int(number)

Fix(number)

The required number argument is any valid numeric expression. If number contains Null, Null is returned.

Remarks

Both Int and Fix remove the fractional part of number and return the resulting integer value.

The difference between Int and Fix is that if number is negative, Int returns the first negative integer less than or equal to number, whereas Fix returns the first negative integer greater than or equal to number. For example, Int converts -8.4 to -9, and Fix converts -8.4 to -8.

Fix(number) is equivalent to:

Sgn(number) * Int(Abs(number))

LOG

Returns the natural logarithm of a number.

Syntax

Log(number)

The required number argument is any valid numeric expression greater than zero.

Remarks

The natural logarithm is the logarithm to the base e. The constant e is approximately 2.718282.

You can calculate base-n logarithms for any number x by dividing the natural logarithm of x by the natural logarithm of n as follows:

Logn(x) = Log(x) / Log(n)

RND

Returns a random number.

Syntax

Rnd[(number)]

The optional number argument is any valid numeric expression.

Return Values

If number is Rnd generates
Less than zero The same number every time, using number as the seed.
Greater than zero The next random number in the sequence.
Equal to zero The most recently generated number.
Not supplied The next random number in the sequence.

Remarks

The Rnd function returns a value less than 1 but greater than or equal to zero.

The value of number determines how Rnd generates a random number:

For any given initial seed, the same number sequence is generated because each successive call to the Rnd function uses the previous number as a seed for the next number in the sequence.

Before calling Rnd, use the Randomize statement without an argument to initialize the random-number generator with a seed based on the system timer.

To produce random integers in a given range, use this formula:

Int((upperbound - lowerbound + 1) * Rnd + lowerbound)

Here, upperbound is the highest number in the range, and lowerbound is the lowest number in the range.

Note: To repeat sequences of random numbers, call Rnd with a negative argument immediately before using Randomize with a numeric argument. Using Randomize with the same value for number does not repeat the previous sequence.

SGN

Returns a Integer indicating the sign of a number.

Syntax

Sgn(number)

The required number argument can be any valid numeric expression.

Return Values

If number is Sgn returns
Greater than zero 1
Equal to zero 0
Less than zero -1

Remarks

The sign of the number argument determines the return value of the Sgn function.

SIN

Returns the sine of an angle.

Syntax

Sin(number)

The required number argument is any valid numeric expression that expresses an angle in radians.

Remarks

The Sin function takes an angle and returns the ratio of two sides of a right triangle. The ratio is the length of the side opposite the angle divided by the length of the hypotenuse.

The result lies in the range -1 to 1.

To convert degrees to radians, multiply degrees by pi/180. To convert radians to degrees, multiply radians by 180/pi.

SQR

Returns the square root of a number.

Syntax

Sqr(number)

The required number argument is any valid numeric expression greater than or equal to zero.

TAN

Returns the tangent of an angle.

Syntax

Tan(number)

The required number argument is any valid numeric expression that expresses an angle in radians.

Remarks

Tan takes an angle and returns the ratio of two sides of a right triangle. The ratio is the length of the side opposite the angle divided by the length of the side adjacent to the angle.

To convert degrees to radians, multiply degrees by pi/180. To convert radians to degrees, multiply radians by 180/pi.

IMP

Used to perform a logical implication on two expressions.

Syntax

result = expression1 Imp expression2

The Imp operator syntax has these parts:

Part Description
Result Required; any numeric variable.
expression1 Required; any expression.
expression2 Required; any expression.

Remarks

The following table illustrates how result is determined:

If expression1 is And expression2 is The result is
True True True
True False False
True Null Null
False True True
False False True
False Null True
Null True True
Null False Null
Null Null Null

The Imp operator performs a bitwise comparison of identically positioned bits in two numeric expressions and sets the corresponding bit in result according to the following table:

If bit in expression1 is And bit in expression2 is The result is
0 0 1
0 1 1
1 0 0
1 1 1

EQV

Used to perform a logical equivalence on two expressions.

Syntax

result = expression1 Eqv expression2

The Eqv operator syntax has these parts:

Part Description
result Required; any numeric variable.
expression1 Required; any expression.
expression2 Required; any expression.

Remarks

If either expression is Null, result is also Null. When neither expression is Null, result is determined according to the following table:

If expression1 is And expression2 is The result is
True True True
True False False
False True False
False False True

The Eqv operator performs a bitwise comparison of identically positioned bits in two numeric expressions and sets the corresponding bit in result according to the following table:

If bit in expression1 is And bit in expression2 is The result is
0 0 1
0 1 0
1 0 0
1 1 1

XOR

Used to perform a logical exclusion on two expressions.

Syntax

[result =] expression1 Xor expression2

The Xor operator syntax has these parts:

Part Description
result Optional; any numeric variable.
expression1 Required; any expression.
expression2 Required; any expression.

Remarks

If one, and only one, of the expressions evaluates to True, result is True. However, if either expression is Null, result is also Null. When neither expression is Null, result is determined according to the following table:

If expression1 is And expression2 is Then result is
True True False
True False True
False True True
False False False

The Xor operator performs as both a logical and bitwise operator. A bit-wise comparison of two expressions using exclusive-or logic to form the result, as shown in the following table:

If bit in expression1 is And bit in expression2 is Then result is
0 0 0
0 1 1
1 0 1
1 1 0

OR

Used to perform a logical disjunction on two expressions.

Syntax

result = expression1 Or expression2

The Or operator syntax has these parts:

Part Description
result Required; any numeric variable.
expression1 Required; any expression.
expression2 Required; any expression.

Remarks

If either or both expressions evaluate to True, result is True. The following table illustrates how result is determined:

If expression1 is And expression2 is Then result is
True True True
True False True
True Null True
False True True
False False False
False Null Null
Null True True
Null False Null
Null Null Null

The Or operator also performs a bitwise comparison of identically positioned bits in two numeric expressions and sets the corresponding bit in result according to the following table:

If bit in expression1 is And bit in expression2 is Then result is
0 0 0
0 1 1
1 0 1
1 1 1

AND

Used to perform a logical conjunction on two expressions.

Syntax

result = expression1 And expression2

The And operator syntax has these parts:

Part Description
result Required; any numeric variable.
expression1 Required; any expression.
expression2 Required; any expression.

Remarks

If both expressions evaluate to True, result is True. If either expression evaluates to False, result is False. The following table illustrates how result is determined:

If expression1 is And expression2 is The result is
True True True
True False False
True Null Null
False True False
False False False
False Null False
Null True Null
Null False False
Null Null Null

The And operator also performs a bitwise comparison of identically positioned bits in two numeric expressions and sets the corresponding bit in result according to the following table:

If bit in expression1 is And bit in expression2 is The result is
0 0 0
0 1 0
1 0 0
1 1 1

MOD

Used to divide two numbers and return only the remainder.

Syntax

result = number1 Mod number2

The Mod operator syntax has these parts:

Part Description
result Required; any numeric variable.
number1 Required; any numeric expression.
number2 Required; any numeric expression.

Remarks

The modulus, or remainder, operator divides number1 by number2 (rounding floating-point numbers to integers) and returns only the remainder as result. For example, in the following expression

, A (result) equals 5.

A = 19 Mod 6.7

Any fractional portion is truncated. However, if any expression is Null, result is Null. Any expression that is Empty is treated as 0.

NOT

Used to perform logical negation on an expression.

Syntax

result = Not expression

The Not operator syntax has these parts:

Part Description
result Required; any numeric variable.
expression Required; any expression.

Remarks

The following table illustrates how result is determined:

If expression is Then result is
True False
False True
Null Null

In addition, the Not operator inverts the bit values of any variable and sets the corresponding bit in result according to the following table:

If bit in expression is Then bit in result is
0 1
1 0