CHECK_MATH Function

Returns and clears the accumulated math error status.

Usage

    result = CHECK_MATH([print_flag, message_inhibit])

Input Parameters

print_flag—(optional) If present and nonzero, indicates an error message is to be printed if any accumulated math errors exist. Otherwise, no messages are printed.

message_inhibit—(optional) Disables or enables the printing of math error exception error messages when they are detected. By default, these messages are enabled. Set message_inhibit to 1 to inhibit, and 0 to re-enable.

When the interpreter exits to the interactive mode, error messages are printed for accumulated math errors that were suppressed but not cleared.

Returned Value

result—An integer indicating the accumulated math error status since the last call or issuance of the interactive prompt. (See the Discussion section below for a list of values.)

Note: On machines that do not implement the IEEE standard for floating-point math, CHECK_MATH does not properly maintain an accumulated error status.

Keywords

Trap—Controls how floating-point traps are handled:

  • If 0, no messages are printed except final accumulated error status.

  • If set to 1 (the default), traps are enabled and programs are allowed to continue after floating-point errors. The first eight floating-point error exceptions issue messages. Subsequent errors are silent.

If a floating-point error occurs which is not logged, the accumulated floating-point error status is printed when PV‑WAVE returns to the interactive mode.

Note: Trap handling is machine dependent. Some machines won’t work properly with traps enabled, while others don’t allow disabling traps.

Discussion

If CHECK_MATH is 0, no math errors have occurred since the last call or issuance of the interactive prompt. Other error status values are listed in Error Status Values, where each binary bit represents an error:

Error Status Values

Value

Condition

0

No errors detected since the last interactive prompt or call to CHECK_MATH.

1

Integer divide by zero.

2

Integer overflow.

16

Floating-point divide by zero.

32

Floating-point underflow.

64

Floating-point overflow.

128

Floating-point operand error. An illegal operand was encountered, such as a negative operand to the SQRT or ALOG functions; or an attempt to convert to integer a number whose absolute value is greater than 231 – 1.

Note: Not all machines detect all errors.

Example

; Array a will not fail as divisor.
a = [1.0, 1.0, 2.0]
; Second element in array b should cause a divide-by-zero error.
b = [1.0, 0.0, 2.0]
; Clear the previous error status and print error messages
; if an error exists.
status = CHECK_MATH(1, 0, Trap=1)
c = 1.0 / a
status = CHECK_MATH(0, 0)
PRINT, a, c, status
; PV-WAVE prints the following:
; 1.00000      1.00000     2.00000
; 1.00000      1.00000     0.500000
;       0
; Cause an integer divide-by-zero error.
d = 1.0 / b
; PV-WAVE prints the following:
; % Program caused arithmetic error: 
; % Floating divide by 0
; % Detected at $MAIN$ .
status = CHECK_MATH(0, 0)
PRINT, b, d, status
; PV-WAVE prints the following:
; 1.00000      0.000000      2.00000
; 1.00000       1.#INF0      0.500000
; 0

See Also

FINITE, ON_ERROR, RETURN, STOP

For additional information on error handling, see the PV‑WAVE Programmer’s Guide.