[Top] [Prev] [Next]

fp - floating point operations

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;

Description

These constants and functions provide control over rounding modes, exceptions, and other properties of floating point arithmetic.
Infinity and NaN

Infinity and NaN are constants containing the positive infinity and quiet not-a-number values of the IEEE binary floating point standard, double precision.

MachEps

The constant MachEps is 2-52, the smallest e such that 1+e is not equal to 1.

Pi

Pi is the nearest machine number to the infinitely precise value.

Degree

Degree is Pi/180.

FPcontrol (r, mask) and

FPstatus (r, mask)

Each thread has a floating point control word that governs rounding mode and whether a particular floating point exception causes a trap. It also has a floating point status word that stores accumulated exception flags. The functions FPcontrol and FPstatus copy bits to the control or status word, in positions specified by mask, returning the previous values of the bits specified in the mask.

getFPcontrol ( ) and getFPstatus ( )

The functions getFPcontrol and getFPstatus return the words unchanged.

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 is to nearest even number. Limbo modules are entitled to assume this, and if they need to use quiet OVFL, UNFL, or ZDIV, they must either set and restore the control register or clearly document that the modules that call them 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 constants 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.

ilogb (x)

The ilogb function returns the nearest integral logarithm base 2 of the absolute value of x: for positive finite x,

1 <= x*2-ilogb(x)< 2, and ilogb(-x) = ilogb(x).

scalbn (x, n)

The scalbn function returns a scaled power of two:

x *2n.

copysign (x, s)

The copysign function returns the magnitude of x and the sign bit of s.

nextafter (x, y)

The nextafter function returns the machine number nearest x closer to y.

finite (x)

The finite function returns is 0 if x is Nan or Infinity, and 1 otherwise.

isnan (x)

The isnan function returns 1 if x is Nan, and 0 otherwise.

fdim (x, y)

The fdim function equals x - y if x is greater than y, otherwise it is 0.

fmin (x, y)

The minimum of x and y.

fmax (x, y)

The maximum of x and y.

fabs (x)

The absolute value of x.

ceil (x)

The ceiling (round-up) of x.

floor (x)

The floor (round-down) of x.

fmod (x, y)

The fmod function conforms to the C language standard. It returns the value x - i *y for some i such that the remainder has the sign of x and magnitude less than the magnitude of y.

remainder (x, y)

The remainder function conforms to the IEEE standard which gives a remainder of magnitude no more than half the magnitude of y.

modf (x)

The modf function breaks x into integer and fractional parts returned in a tuple.

rint (x)

The rint function rounds to an integer, following the rounding mode specified in the floating point control word.

See Also

Limbo Math Module



[Top] [Prev] [Next]

infernosupport@lucent.com
Copyright © 1996,Lucent Technologies, Inc. All rights reserved.