HP Pascal/iX Programmer's Guide (31502-90023)
11- 16
You can examine and replace the contents of the area referenced by
result_ptr
, and the Trap Subsystem will ensure that the change is
reflected in the appropriate place.
Compatibility Mode Floating-Point Traps.
The
TrapInfo
record has one extra field,
Result_ptr
.
Result_ptr
(word #5) contains the address of the result of the operation,
which can be a single- or double-word floating-point number, depending on
the type of trap. You can examine and replace the contents of the area
referenced by
result_ptr
, and the Trap Subsystem will ensure that the
change is reflected in the appropriate place.
Example
{user declares the following Pascal record for the TrapInfo record}
TYPE
real_ptr = real;
long_ptr = longreal;
TrapInfo = RECORD
{ 1} instruction,
{ 2} pc_offset,
{ 3} pc_space,
{ 4} error_code,
{ 5} status,
{ 6} operation,
{ 7} format : integer;
{ 8} source1_ptr,
{ 9} source2_ptr,
{10} result_ptr : localanyptr;
END;
CONST
IEEE_mask = hex('0007C000');
fdiv_zero = hex('00002000'); {the error code for fl. pt. div. by 0}
{trap handler routine}
PROCEDURE IEEE_trap_handler (VAR Info : TrapInfo);
VAR
long_res_ptr : long_ptr;
real_res_ptr : real_ptr;
(
Example continued on next page
.)
CONST
max_real = 3.402823E+38;
max_longreal = 1.797693L+308;
BEGIN {IEEE_trap_handler}
{handle only divide-by-zero, ignore others}
WITH Info DO
IF (Error_Code = fdiv_zero) THEN
BEGIN {divide by zero}
{change the value of the result}
IF (format = 0) THEN
BEGIN {real operation}
real_res_ptr := result_ptr;
real_res_ptr^ := maxreal;
END {real operation}
ELSE IF (format = 1) THEN
BEGIN {longreal operation}
long_res_ptr := result_ptr;
long_res_ptr^ := maxlongreal;
END; {longreal operation}