Intrinsic Functions

An intrinsic function is a built-in mvBASIC function to be used on numeric operands.

Numeric Functions

In addition to the standard numeric operators (+, -, *, /), mvBASIC provides several functions for evaluating numeric calculations.

ABS

Returns the absolute value of a given expression. The absolute value of a number is its positive value, or the difference between itself and zero.

INT

Gives the integer value of an expression. It truncates the decimal portion of a number and returns the result.

REM

Takes two arguments and returns the remainder value when the first expression is divided by the second.

SQRT

Returns the square root of a positive expression.

RND

Returns a random number between 0 and the given expression minus 1.

PWR

Takes two arguments and returns the first value to the power of the second.

In addition, the following trigonometric functions are available in mvBASIC:

SIN

Returns the sine of the angle.

COS

Returns the cosine of the angle.

TAN

Returns the tangent of the angle (SIN/COS).

LN

Returns the natural logarithm (log base e) of the expression.

EXP

Returns e to the power of the expression (the inverse of LN).

The accuracy of each numeric function is dependent on the decimal precision used by the program; i.e., the number of decimal places to which numeric values are calculated. By default, all numeric values are calculated to four decimal places. To reassign this value, use the PRECISION statement. The maximum precision supported by mvBASIC is 9.

Logical Functions (NOT, NUM, ALPHA)

A logical function, or Boolean function, is one which returns either 0 or 1. A return value of 0 is taken to mean false, and a return value of 1 is taken to mean true. Logical functions are most useful in conditional statements (IF, CASE), or in the exit for loops.

In addition to the logical operators (=, <>, >, >=, <, <=, MATCH), the following intrinsic logical functions are supported in mvBASIC:

NOT

Returns the logical inverse of a given expression. That is, if the expression evaluates to 0 or the null string (" "), the NOT function returns 1; if the expression evaluates to anything other than 0 or the null string, the NOT function returns 0.

NUM

Returns 1 if the given expression is numeric, or 0 if it is nonnumeric. (Note that the NUM function might return 0 for a clearly numeric value if it contains more decimal places than the current precision.)

ALPHA

Returns 1 if the given expression is alphabetic, or 0 if it is non alphabetic.

Example

Suppose a program expects a positive number in Attribute 3 of a file item. The source code might read:

PRICE = RECORD<3>

IF NOT(NUM(PRICE)) THEN

PRINT "ERROR — NON-NUMERIC DATA IN ATTRIBUTE 3."

STOP

END ELSE

IF PRICE < 0 THEN

PRINT "ERROR — NEGATIVE DATA IN ATTRIBUTE 3."

STOP

END

END

Using the Boolean operators (AND, OR), the same code might read:

PRICE = RECORD<3>

IF NOT(NUM(PRICE)) OR PRICE < 0 THEN

PRINT "ERROR IN ATTRIBUTE 3 — ":

PRINT "POSITIVE NUMBER EXPECTED."

STOP

END

See Also

Overview of mvBASIC Statements and Functions

Assignment Statements

Internal Program Control

External Program Control

Sending Output to the Screen and Printer

Terminal Input

Dynamic Array Processing

Generalized String Processing

Dimensioned Arrays

Reading and Updating File Items

Reading and Writing Tapes or Floppy Disks

Communications

Execution Locks

Compiler Directives

Miscellaneous Statements and Functions

The Error Message Processor