math.3m
来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· 3M 代码 · 共 550 行 · 第 1/2 页
3M
550 行
.TH math 3m RISC.ds up \fIulp\fR.ds nn \fINaN\fR.de If.if n \\\\$1Infinity\\$2.if t \\\\$1\\(if\\$2...SH Namemath \- introduction to mathematical library functions.SH DescriptionThese functions constitute the C math library.I libm.There are two versions of the math library.I libm.aand.I libm43.a..PPThe first,.I libm.a,contains routines written in MIPS assembly language and tuned for bestperformance and includes many routines for the.I floatdata type. The routines in there are based on the algorithms of Cody andWaite or those in the 4.3 BSD release, whichever provides the best performancewith acceptable error bounds. Those routines with Cody and Waiteimplementations are marked with a `*' in the list of functions below..PPThe second version of the math library,.I libm43.a,contains routines all based on the original codes in the 4.3 BSD release.The difference between the two version's error bounds is typically around 1unit in the last place, whereas the performance difference may be a factorof two or more..PPThe link editor searches this library under the \*(lq\-lm\*(rq (or\*(lq\-lm43\*(rq) option.Declarations for these functions may be obtained from the include file.RI < math.h >.The Fortran math library is described in ``man 3f intro''..SS List Of FunctionsThe cycle counts of all functions are approximate; cycle counts often dependon the value of argument. The error bound sometimes applies only to theprimary range..PP.TStab(@);l l lfHB s s slfHB lfHB lfHB lfHB lfHB lfHBl l l l l l ._.sp 4p@@Error Bound (ULPs) CyclesName@Description@libm.a@libm43.a@libm.a@libm43.a.sp 4p_.sp 6pacos@T{inverse trig functionT}@3@3@?@?acosh@T{inverse hyperbolic functionT}@3@3@?@?asin@T{inverse trig functionT}@3@3@?@?asinh@T{inverse hyperbolic functionT}@3@3@?@?atan@T{inverse trig functionT}@1@1@152@260atanh@T{inverse hyperbolic functionT}@3@3@?@?atan2@T{inverse trig functionT}@2@2@?@?cabs@T{complex absolute valueT}@1@1@?@?cbrt@cube root@1@1@?@?ceil@T{integer no less thanT}@0@0@?@?copysign@copy sign bit@0@0@?@?cos*@trig function@2@1@128@243cosh*@hyperbolic function@?@3@142@294drem@remainder@0@0@?@?erf@error function@?@?@?@?erfc@T{complementary error functionT}@?@?@?@?exp*@exponential@2@1@101@230expm1@exp(x)\-1@1@1@281@281fabs@absolute value@0@0@?@?fatan*@T{inverse trig functionT}@3@@64fcos*@trig function@1@@87fcosh*@hyperbolic function@?@@105fexp*@exponential@1@@79flog*@natural logarithm@1@@100floor@T{integer no greater thanT}@0@0@?@?fsin*@trig function@1@@68fsinh*@hyperbolic function@?@@44fsqrt@square root@1@@95ftan*@trig function@?@@61ftanh*@hyperbolic function@?@@116hypot@Euclidean distance@1@1@?@?j0@bessel function@?@?@?@?j1@bessel function@?@?@?@?jn@bessel function@?@?@?@?lgamma@log gamma function@?@?@?@?log*@natural logarithm@2@1@119@217logb@exponent extraction@0@0@?@?log10*@logarithm to base 10@3@3@?@?log1p@log(1+x)@1@1@269@269pow@exponential x**y@60\-500@60\-500@?@?rint@T{round to nearest integerT}@0@0@?@?scalb@exponent adjustment@0@0@?@?sin*@trig function@2@1@101@222sinh*@hyperbolic function@?@3@79@292sqrt@square root@1@1@133@133tan*@trig function@?@3@92@287tanh*@hyperbolic function@?@3@156@293y0@bessel function@?@?@?@?y1@bessel function@?@?@?@?yn@bessel function@?@?@?@?.sp 6p_.TE.PPIn 4.3 BSD, distributed from the University of Californiain late 1985, most of the foregoing functions come in twoversions, one for the double\-precision "D" format in theDEC VAX\-11 family of computers, another for double\-precisionarithmetic conforming to the IEEE Standard 754 for BinaryFloating\-Point Arithmetic. The two versions behave verysimilarly, as should be expected from programs more accurateand robust than was the norm when UNIX was born. Forinstance, the programs are accurate to within the numbersof \*(ups tabulated above; an \*(up is one \fIU\fRnit in the \fIL\fRast\fIP\fRlace. And the programs have been cured of anomalies thatafflicted the older math library \fIlibm\fR in which incidents likethe following had been reported:.sp.RSsqrt(\-1.0) = 0.0 and log(\-1.0) = \-1.7e38..brcos(1.0e\-11) > cos(0.0) > 1.0..brpow(x,1.0).if n \!=.if t \\(!=x when x = 2.0, 3.0, 4.0, ..., 9.0..brpow(\-1.0,1.0e10) trapped on Integer Overflow..brsqrt(1.0e30) and sqrt(1.0e\-30) were very slow..RE.spRISC machines conform to the IEEE Standard 754 for BinaryFloating\-Point Arithmetic, to which only the notes forIEEE floating-point apply and are included here..SS "BIEEE STANDARD 754 Floating\-Point Arithmetic:"This standard is on its way to becoming more widely adoptedthan any other design for computer arithmetic..PPThe main virtue of 4.3 BSD's\fIlibm\fR codes is that they are intended for the public domain;they may be copied freely provided their provenance is alwaysacknowledged, and provided users assist the authors in theirresearches by reporting experience with the codes.Therefore no user of UNIX on a machine that conforms toIEEE 754 need use anything worse than the new \fIlibm\fR..SS "Properties of IEEE 754 Double\-Precision:".RS\fBWordsize:\fP 64 bits, 8 bytes. \fBRadix:\fP Binary..br\fBPrecision:\fP 53.if n \sig..if t \significantbits, roughly like 16.if n \sig..if t \significantdecimals..RSIf x and x' are consecutive positive Double\-Precisionnumbers (they differ by 1 \*(up), then.br1.1e\-16 < 0.5**53 < (x'\-x)/x \(<= 0.5**52 < 2.3e\-16..RE.nf.ta \w'Range:'u+1n +\w'Underflow threshold'u+1n +\w'= 2.0**1024'u+1n\fBRange:\fP Overflow threshold = 2.0**1024 = 1.8e308 Underflow threshold = 0.5**1022 = 2.2e\-308.ta.fi.RSOverflow goes by default to a signed.If "" ..brUnderflow is \fIGradual,\fR rounding to the nearestinteger multiple of 0.5**1074 = 4.9e\-324..REZero is represented ambiguously as +0 or \-0..RSIts sign transforms correctly through multiplication ordivision, and is preserved by addition of zeroswith like signs; but x\-x yields +0 for everyfinite x. The only operations that reveal zero'ssign are division by zero and copysign(x,\(+-0).In particular, comparison (x > y, x \(>= y, etc.)cannot be affected by the sign of zero; but iffinite x = y then.If\&= 1/(x\-y).if n \!=.if t \\(!=\-1/(y\-x) =.If \- ..RE.Ifis signed..RSit persists when added to itselfor to any finite number. Its sign transformscorrectly through multiplication and division, and.If (finite)/\(+- \0=\0\(+-0(nonzero)/0 =.If \(+- .But .if n \Infinity\-Infinity, Infinity\(**0 and Infinity/Infinity.if t \\(if\-\(if, \(if\(**0 and \(if/\(ifare, like 0/0 and sqrt(\-3),invalid operations that produce \*(nn. ....RE\fBReserved operands:\fP.RSthere are 2**53\-2 of them, allcalled \*(nn (\fIN\fRot \fIa N\fRumber).Some, called Signaling \*(nns, trap any floating\-point operationperformed upon them; they could be used to mark missingor uninitialized values, or nonexistent elementsof arrays. The rest are Quiet \*(nns; they arethe default results of Invalid Operations, andpropagate through subsequent arithmetic operations.If x.if n \!=.if t \\(!=x then x is \*(nn; every other predicate(x > y, x = y, x < y, ...) is FALSE if \*(nn is involved..NTTrichotomy is violated by \*(nn.Besides being FALSE, predicates that entail orderedcomparison, rather than mere (in)equality,signal Invalid Operation when \*(nn is involved.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?