include "math.m"; math:= load Math Math->PATH; Infinity, NaN, MachEps, Pi, Degree : real; INVAL, ZDIV, OVFL, UNFL, INEX : int; RND_NR, RND_NINF, RND_PINF, RND_Z, RND_MASK: int; getFPcontrol, getFPstatus: fn() : int; FPcontrol, FPstatus: fn(r, mask: int) : int; ilogb : fn(x: real) : int; scalbn : fn(x: real, n: int) : real; copysign : fn(x, s: real) : real; finite, isnan : fn(x: real) : int; nextafter : fn(x, y: real) : real; fdim, fmin, fmax : fn(x, y: real) : real; fabs : fn(x: real) : real; ceil, floor : fn(x: real) : real; remainder : fn(x, p: real) : real; fmod : fn(x, y: real) : real; modf : fn(x: real) :(int, real); rint : fn(x: real) : real;
Constants for non-overlapping single-bit masks are provided for use in arguments or return values. They stand for the five IEEE exceptions:
INVAL | invalid operation | 0/0, 0+NaN, Infinity-Infinity, or sqrt(-1) |
ZDIV | division by zero | 1/0 |
OVFL | overflow | 1.8e308 |
UNFL | underflow | 1.1e-308 |
INEX | inexact | .3*.3 |
By default, INEX is quiet, OVFL, UNFL, and ZDIV are fatal, and rounding (details on rounding given shortly) is to nearest even. Limbo modules are entitled to assume this, and if they wish to use quiet underflow, overflow, or zero-divide, they must either set and restore the control register or clearly document that their callers must do so.
Constants (distinct bit patterns) are defined for interfacing with the floating point control word.
RND_NR | round to nearest even |
RND_NINF | round toward negative infinity |
RND_PINF | round toward infinity |
RND_Z | round toward zero |
Any of the above can be set or extracted from the floating point control word using RND_MASK. Several examples follow:
FPcontrol(0, UNFL); | Make underflow silent. |
FPstatus(0, INEX); | Check and clear the inexact flag. |
FPcontrol (RND_PINF, RND_MASK); | Set directed rounding. |