Charles.Forsyth20060303-partialeea662d19 years agoHistory
205 lines · 4.2 KB · Text
RawDownload
.TH MATH-FP 2.SH NAMEmath-fp \- floating point.SH SYNOPSIS.EXinclude	"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;.EE.SH DESCRIPTIONThese constants and functions provide control over rounding modes,exceptions, and other properties of floating point arithmetic..PP.B Infinityand.B NaNare constants containingthe positive infinity and quiet not-a-number valuesof the IEEE binary floating point standard, double precision..B MachEpsis 2\u\s-2-52\s0\d, the smallest.I esuch that 1+\f2e\f1 is not equal to 1..B Piis the nearest machine number to the infinitely precise value..B Degreeis.BR Pi/ 180..PPEach thread has a floating point control word (governing rounding mode andwhether a particular floating point exception causes a trap)and a floating point status word (storing accumulated exception flags).The functions.B FPcontroland.B FPstatuscopy bits to the control or status word,in positions specified by a mask, returning the previous values of the bitsspecified in the mask.The functions.B getFPcontroland.B getFPstatusreturn the words unchanged..PP.BR INVAL ,.BR ZDIV ,.BR OVFL ,.BR UNFL ,and.B INEXare non-overlapping single-bit masksused to compose arguments or return values.They stand for the five IEEE exceptions:`invalid operation' (0/0,0+NaN,Infinity-Infinity,sqrt(-1)),`division by zero' (1/0), `overflow' (1.8e308), `underflow' (1.1e-308),and `inexact' (.3*.3)..PP.BR RND_NR ,.BR RND_NINF ,.BR RND_PINF ,and.BR RND_Zare distinct bit patternsfor `round to nearest even', `round toward negative infinity',`round toward infinity', and `round toward 0',any of which can be set or extracted from the floating point controlword using.BR RND_MASK .For example,.B FPcontrol(0,.B UNFL)makes underflow silent;.B FPstatus(0,.B INEX)checks and clears the inexact flag; and.B FPcontrol(RND_PINF,.B RND_MASK)sets directed rounding..PPBy default,.B INEXis quiet,.BR OVFL ,.BR UNFL , and.B ZDIVare fatal,and rounding is to nearest even.Limbo modules areentitled to assume this, and if they wish to use quietunderflow, overflow, or zero-divide, they must eitherset and restore the control register or clearly document thattheir caller must do so..PPThe.B ilogbfunctionreturns the nearest integral logarithm base 2 of the absolute value of.IR x:for positive finite.IR x ,1 \(<=.IB x *2\u-\s-2ilogb( x )\s0\d< 2,and.BI ilogb(- x ).B =.BI ilogb( x )\f1..BI Scalbn( x , n )is a scaled power of two:.IB x *2\u\s-2n\s0\d\f1..BI Copysign( x , s )has the magnitude of.I xand thesign bit of.IR s ..BI Nextafter( x , y )is the machine number nearest x closer to y.Finally,.BI finite( x )is 0 if.I xis.B Nanor.B Infinity,1 otherwise, and.BI isnan( x )is 1 if.I xis.B Nanand 0 otherwise..PPThe function.BI fdim( x , y)=.IB x - yif.I xis greater than.IR  y ,otherwise it is 0.The functions.BR fmin ,.BR fmax ,.BR fabs ,.BR ceil ,and.B floorare thecustomary minimum,maximum,absolute value,and integer rounding routines..PPThere are two functions for computing the modulus:.BI fmod( x , y )is the function defined by the C standard which gives the value.IB x - i*yfor some.I isuch that the remainder has the sign of.I xand magnitude less than the magnitude of.IR y ,while.BI remainder( x , y )is the function defined by the IEEE standardwhich gives a remainder of magnitude no more than half themagnitude of.IR y .The function.BI modf( x )breaks.I xinto integer and fractional parts returned in a tuple, and.B rintrounds to an integer, following therounding mode specified in the floating point control word..SH SOURCE.B /libinterp/math.c.SH SEE ALSO.IR math-intro (2)