Previous Topic: BOOLWORD()Next Topic: CALLX()


CALC()

This function evaluates a complex numerical expression and returns the results.

Syntax

result = CALC(expression,[decimal])

Parameters

result

Numeric result of the operation.

expression

The mathematical expression to be evaluated. Numbers can be up to six significant digits, containing a decimal point and leading plus sign or leading minus sign. Blanks are ignored. The operators that you can use are shown in the following section.

Because CALC() uses true floating-point arithmetic, values can be imprecise. Large and small numbers include a scaling factor (power of 10), and return values in the following form:

1.23456 * 10 ** 25

decimal

Number of digits to the right of the decimal point.

Default: All significant digits appear, but trailing zeros are omitted.

Operators for the Expression Operand

+

Plus

-

Minus

**

Raise to a power

*

Multiply

/

Divide

(

Start priority grouping

)

End priority grouping

sin()

Evaluate sine

cos()

Evaluate cosine

atan()

Evaluate arc tangent

exp()

Exponential

abs()

Absolute value

sqrt()

Square root

log10()

Base 10 logarithm

log()

Base 10 logarithm

ln()

Base e (natural) logarithm

Return Codes

101

One of the following codes:

ARG 1 MISSING OR INVALID

CHARACTER IN ARG 1

102

ARG 2 INVALID

121

One of the following codes:

EXPECTED OPERATOR MISSING

TOO MANY NUMERIC FIELDS

OPERATOR FOLLOWS OPERATOR

INVALID OPERATOR

NUMBER FOLLOWS RIGHT PARENTHESIS

UNBALANCED PARENTHESES

OVERFLOW OR UNDERFLOW

EXPRESSION TOO COMPLEX

ERROR DURING SIN/COS EVALUATION

ERROR DURING EXP EVALUATION

ERROR DURING LOG EVALUATION

ERROR DURING SQRT EVALUATION

RESULT TOO LARGE

DIVISION BY ZERO

Example

calc('1+1')         == '2'
calc('(1+2)*5')     == '15'         /* Not 11   */
calc('abs(-9)')     == '9'