Oberon || Library || Module Index || Search Engine || Definition || Module


Ulm's Oberon Library:
MC68881


NAME

MC68881 - library interface to MC68881 instructions

SYNOPSIS

CONST available = TRUE;


(* rounding modes *) CONST toNearest = 0; CONST towardZero = 1; CONST towardMinusInfinity = 2; CONST towardPlusInfinity = 3;

(* rounding precision *) CONST extended = 0; single = 1; double = 2;

(* exceptions *) CONST branchOnUnordered = 0; CONST signalingNotANumber = 1; CONST operandError = 2; CONST overflow = 3; CONST underflow = 4; CONST divideByZero = 5; CONST inexactOperation = 6; CONST inexactDecimalInput = 7; CONST floatlen = 4; (* length of a single precision real number *)

PROCEDURE FACOS(x: LONGREAL) : LONGREAL; PROCEDURE FASIN(x: LONGREAL) : LONGREAL; PROCEDURE FATAN(x: LONGREAL) : LONGREAL; PROCEDURE FATANH(x: LONGREAL) : LONGREAL; PROCEDURE FCOS(x: LONGREAL) : LONGREAL; PROCEDURE FCOSH(x: LONGREAL) : LONGREAL; PROCEDURE FETOX(x: LONGREAL) : LONGREAL; PROCEDURE FETOXM1(x: LONGREAL) : LONGREAL; PROCEDURE FGETEXP(x: LONGREAL) : LONGREAL; PROCEDURE FGETMAN(x: LONGREAL) : LONGREAL; PROCEDURE FLOG10(x: LONGREAL) : LONGREAL; PROCEDURE FLOG2(x: LONGREAL) : LONGREAL; PROCEDURE FLOGN(x: LONGREAL) : LONGREAL; PROCEDURE FLOGNP1(x: LONGREAL) : LONGREAL; PROCEDURE FSIN(x: LONGREAL) : LONGREAL; PROCEDURE FSINH(x: LONGREAL) : LONGREAL; PROCEDURE FSQRT(x: LONGREAL) : LONGREAL; PROCEDURE FTAN(x: LONGREAL) : LONGREAL; PROCEDURE FTANH(x: LONGREAL) : LONGREAL; PROCEDURE FTENTOX(x: LONGREAL) : LONGREAL; PROCEDURE FTWOTOX(x: LONGREAL) : LONGREAL;

PROCEDURE GetExceptionEnable(VAR exceptions: SET); PROCEDURE SetExceptionEnable(exceptions: SET);

PROCEDURE GetRoundingMode(VAR precision, mode: INTEGER); PROCEDURE SetRoundingMode(precision, mode: INTEGER);

PROCEDURE RealToFloat(real: LONGREAL; VAR float: ARRAY OF BYTE); PROCEDURE FloatToReal(float: ARRAY OF BYTE; VAR real: LONGREAL);

DESCRIPTION

The implemenation of this module is written in assembler and offers a library interface to some MC68881 instructions.

The constant available is TRUE if a MC68881 or upward compatible processor is present. Otherwise available is FALSE and all operations are no-operations. This allows some system modules to take advantage of known floating processors in a portable manner.

The procedures FACOS to FTWOTOX execute the equally named instructions.

The MC68881 supports 8 exceptions which can be separately enabled or disabled:

branchOnUnordered
comparison of defined values against undefined values
signalingNotANumber
a signaling not-a-number was used as operand, see IEEE for details
operandError
operation has no mathematical interpretation for the given operands, e.g. operand is less than zero for FLOGN
overflow
the result of an operation equals plus or minus infinity
underflow
a non-zero result gets zero
divideByZero
division by zero
inexactOperation
the exact result of an operation is not representable
inexactDecimalInput
decimal format cannot be represented exactly; this exception does not arise in Oberon programs
All exceptions are disabled by default. SysSignals.FPE is raised if an enabled exception arises. The faulting instruction is re-executed if execution continues. Thus a floating point exception handler must either not return or disable the arised exception to avoid an infinite loop.

The MC68881 supports four rounding modes:

_______________________________________________________________
|rounding mode	       examples	for real to integer conversion|
|_________________________-1.9________-1.1________1.1______1.9|
|toNearest		  -2	      -1	  1	   2  |
|towardZero		  -1	      -1	  1	   1  |
|towardMinusInfinity	  -2	      -2	  1	   1  |
|towardPlusInfinity	  -1	      -1	  2	   2  |
|_____________________________________________________________|

Note that ENTIER is a conversion with rounding mode towards minus infinity. The inline code of the compiler for ENTIER saves the current rounding mode, sets the rounding mode towards minus infinity, executes the conversion, and restores the old rounding mode. The rounding precision is either extended, single, or double. The rounding precision is set to extended at beginning of execution and must not be changed (else floating point operations would behave unexpected, e.g. the precision of LONGREAL and REAL differs from the specifications of Reals). GetRoundingMode returns current rounding mode and precision. SetRoundingMode sets the rounding precision to precision and the rounding mode to mode.

The Oberon compiler maps REAL to the 8-byte double precision format and LONGREAL to the 12-byte extended precision format and does not provide a basic datatype for the 4-byte single precision format. RealToFloat and FloatToReal allow to convert to and from the 4-byte single precision format (e.g. to export or import real values in binary format to other programming languages). Both procedures use ARRAY OF BYTE for the 4-byte real value for convenience. The constant floatlen specifies the necessary number of bytes to hold a single precision real value.

SEE ALSO

IEEE   		IEEE floating point formats
Reals   	real conversions
SysSignals   	floating point exceptions

Edited by: borchert, last change: 1992/04/22, revision: 1.4, converted to HTML: 1997/04/28

Oberon || Library || Module Index || Search Engine || Definition || Module