
Calling Sequence


NumericEvent(event, operation, operands, default_value)
NumericEvent(event, default_value)


Parameters


event



symbol that represents one of six numeric events

operation



name of the operation causing the event

operands



list of the operands to that operation

default_value



suggested default value for the event handler to return





Description


•

A numeric event is an indication of an anomalous numerical computation. Six types of anomalies are detected by Maple:

invalid_operation

An invalid computation was attempted, such as $\mathrm{\infty}$  $\mathrm{\infty}$

division_by_zero

An infinite singularity occurred, such as 1/0 or ln(0)

overflow

The result of a computation is too large to represent

underflow

The result of a computation is too small to represent

inexact

The result of a computation is not exactly representable

real_to_complex

An operation with all real operands returned a complex (nonreal) result



•

When a numeric event is signaled, its corresponding event handler is invoked to determine what should happen next. Maple has default handlers for each of the 6 numeric events. You can install your own event handler by using the NumericEventHandler routine.

•

In addition to the automatic triggering of events by builtin numeric operations, user code can trigger an event explicitly by calling the NumericEvent function.

•

The event parameter specifies which event is to be triggered, and is specified by one of the event symbols listed above.

•

The optional operation and operands parameters are the values that will be passed as the operation and operands parameters to the event handler (see NumericEventHandler). If NumericEvent is called from within a Maple function, these parameters can be omitted, and the values procname and [args] will be passed in their place.

•

The default_value parameter indicates a suggested default value. For example, a handler for division_by_zero might be passed a default_value of infinity or infinity, depending on the sign of the dividend.

•

If the event handler returns a result, NumericEvent will return that result. If the event handler raises an exception, NumericEvent will not return to the point it was called.

•

The NumericStatus function can be used to determine which numeric events have been signaled during a computation.

•

Numeric events are signaled for operations involving hardware floatingpoint numbers, arbitrary precision software floatingpoint numbers, and exact numbers in the regular Maple computation environment. However, in the evalhf environment, in Compiled code, and in code generated for other environments by the CodeGeneration package, nondefault numeric event handling settings are not guaranteed to be respected.



Examples


>

MyDivide := proc(a,b)
if b = 0 then
if a < 0 then NumericEvent(division_by_zero,1e10000)
else NumericEvent(division_by_zero,1e10000)
end if
else
a / b
end if
end proc:

>

$\mathrm{MyDivide}\left(3.0\,0.\right)$

${1.}{}{{10}}^{{10000}}$
 (1) 
>

$\mathrm{NumericEventHandler}\left(\mathrm{division\_by\_zero}=\mathrm{exception}\right)\:$

>

$\mathrm{MyDivide}\left(3.0\,0.\right)$

>

$\mathrm{NumericStatus}\left(\mathrm{division\_by\_zero}=\mathrm{false}\right)$

${\mathrm{division\_by\_zero}}{=}{\mathrm{true}}$
 (2) 
>

MyHandler := proc(operator,operands,default_value)
# MyHandler issues a warning, clears the status flag and then
# continues with the default value.
WARNING("division by zero in %1 with args %2",operator,operands);
NumericStatus(division_by_zero = false);
default_value;
end proc:

>

$\mathrm{NumericEventHandler}\left(\mathrm{division\_by\_zero}=\mathrm{MyHandler}\right)\:$

>

$\mathrm{MyDivide}\left(3.0\,0.\right)$

${\mathrm{1.}}{}{{10}}^{{10000}}$
 (3) 
>

$\mathrm{NumericStatus}\left(\mathrm{division\_by\_zero}=\mathrm{false}\right)$

${\mathrm{division\_by\_zero}}{=}{\mathrm{false}}$
 (4) 


