📄 math.3
字号:
.\" Copyright (c) 1985, 1993.\" The Regents of the University of California. All rights reserved..\".\" Redistribution and use in source and binary forms, with or without.\" modification, are permitted provided that the following conditions.\" are met:.\" 1. Redistributions of source code must retain the above copyright.\" notice, this list of conditions and the following disclaimer..\" 2. Redistributions in binary form must reproduce the above copyright.\" notice, this list of conditions and the following disclaimer in the.\" documentation and/or other materials provided with the distribution..\" 3. All advertising materials mentioning features or use of this software.\" must display the following acknowledgement:.\" This product includes software developed by the University of.\" California, Berkeley and its contributors..\" 4. Neither the name of the University nor the names of its contributors.\" may be used to endorse or promote products derived from this software.\" without specific prior written permission..\".\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION).\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF.\" SUCH DAMAGE..\".\" @(#)math.3 8.1 (Berkeley) 6/4/93.\".TH MATH 3 "June 4, 1993".UC 4.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.The link editor searches this library under the \*(lq\-lm\*(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''..SH "LIST OF FUNCTIONS".sp 2.nf.ta \w'copysign'u+2n +\w'infnan.3m'u+10n +\w'inverse trigonometric func'u\fIName\fP \fIAppears on Page\fP \fIDescription\fP \fIError Bound (ULPs)\fP.ta \w'copysign'u+4n +\w'infnan.3m'u+4n +\w'inverse trigonometric function'u+6nC.sp 5pacos sin.3m inverse trigonometric function 3acosh asinh.3m inverse hyperbolic function 3asin sin.3m inverse trigonometric function 3asinh asinh.3m inverse hyperbolic function 3atan sin.3m inverse trigonometric function 1atanh asinh.3m inverse hyperbolic function 3atan2 sin.3m inverse trigonometric function 2cabs hypot.3m complex absolute value 1cbrt sqrt.3m cube root 1ceil floor.3m integer no less than 0copysign ieee.3m copy sign bit 0cos sin.3m trigonometric function 1cosh sinh.3m hyperbolic function 3drem ieee.3m remainder 0erf erf.3m error function ???erfc erf.3m complementary error function ???exp exp.3m exponential 1expm1 exp.3m exp(x)\-1 1fabs floor.3m absolute value 0floor floor.3m integer no greater than 0hypot hypot.3m Euclidean distance 1infnan infnan.3m signals exceptionsj0 j0.3m bessel function ???j1 j0.3m bessel function ???jn j0.3m bessel function ???lgamma lgamma.3m log gamma function; (formerly gamma.3m)log exp.3m natural logarithm 1logb ieee.3m exponent extraction 0log10 exp.3m logarithm to base 10 3log1p exp.3m log(1+x) 1pow exp.3m exponential x**y 60\-500rint floor.3m round to nearest integer 0scalb ieee.3m exponent adjustment 0sin sin.3m trigonometric function 1sinh sinh.3m hyperbolic function 3sqrt sqrt.3m square root 1tan sin.3m trigonometric function 3tanh sinh.3m hyperbolic function 3y0 j0.3m bessel function ???y1 j0.3m bessel function ???yn j0.3m bessel function ???.ta.fi.SH NOTESIn 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:.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..REHowever the two versions do differ in ways that have to beexplained, to which end the following notes are provided..PP\fBDEC VAX\-11 D_floating\-point:\fR.PPThis is the format for which the original math library \fIlibm\fRwas developed, and to which this manual is still principallydedicated. It is \fIthe\fR double\-precision format for the PDP\-11and the earlier VAX\-11 machines; VAX\-11s after 1983 wereprovided with an optional "G" format closer to the IEEEdouble\-precision format. The earlier DEC MicroVAXs have noD format, only G double\-precision. (Why? Why not?).PPProperties of D_floating\-point:.RSWordsize: 64 bits, 8 bytes. Radix: Binary..brPrecision: 56.if n \sig..if t \significantbits, roughly like 17.if n \sig..if t \significantdecimals..RSIf x and x' are consecutive positive D_floating\-pointnumbers (they differ by 1 \*(up), then.br1.3e\-17 < 0.5**56 < (x'\-x)/x \(<= 0.5**55 < 2.8e\-17..RE.nf.ta \w'Range:'u+1n +\w'Underflow threshold'u+1n +\w'= 2.0**127'u+1nRange: Overflow threshold = 2.0**127 = 1.7e38. Underflow threshold = 0.5**128 = 2.9e\-39. NOTE: THIS RANGE IS COMPARATIVELY NARROW..ta.fi.RSOverflow customarily stops computation..brUnderflow is customarily flushed quietly to zero..brCAUTION:.RSIt is possible to have x.if n \!=.if t \\(!=y and yetx\-y = 0 because of underflow. Similarlyx > y > 0 cannot prevent either x\(**y = 0or y/x = 0 from happening without warning..RE.REZero is represented ambiguously..RSAlthough 2**55 different representations of zero are accepted bythe hardware, only the obvious representation is ever produced.There is no \-0 on a VAX..RE.Ifis not part of the VAX architecture..brReserved operands:.RSof the 2**55 that the hardwarerecognizes, only one of them is ever produced.Any floating\-point operation upon a reservedoperand, even a MOVF or MOVD, customarily stopscomputation, so they are not much used..REExceptions:.RSDivisions by zero and operations thatoverflow are invalid operations that customarilystop computation or, in earlier machines, producereserved operands that will stop computation..RERounding:.RSEvery rational operation (+, \-, \(**, /) on aVAX (but not necessarily on a PDP\-11), if not anover/underflow nor division by zero, is rounded towithin half an \*(up, and when the rounding error isexactly half an \*(up then rounding is away from 0..RE.RE.PPExcept for its narrow range, D_floating\-point is one of thebetter computer arithmetics designed in the 1960's.Its properties are reflected fairly faithfully in the elementaryfunctions for a VAX distributed in 4.3 BSD.They over/underflow only if their results have to lie out of rangeor very nearly so, and then they behave much as any rationalarithmetic operation that over/underflowed would behave.Similarly, expressions like log(0) and atanh(1) behavelike 1/0; and sqrt(\-3) and acos(3) behave like 0/0;they all produce reserved operands and/or stop computation!The situation is described in more detail in manual pages..RS.ll -0.5i\fIThis response seems excessively punitive, so it is destinedto be replaced at some time in the foreseeable future by amore flexible but still uniform scheme being developed tohandle all floating\-point arithmetic exceptions neatly.See infnan(3M) for the present state of affairs.\fR.ll +0.5i.RE.PPHow do the functions in 4.3 BSD's new \fIlibm\fR for UNIXcompare with their counterparts in DEC's VAX/VMS library?Some of the VMS functions are a little faster, some area little more accurate, some are more puritanical aboutexceptions (like pow(0.0,0.0) and atan2(0.0,0.0)),and most occupy much more memory than their counterparts in\fIlibm\fR.The VMS codes interpolate in large table to achievespeed and accuracy; the \fIlibm\fR codes use tricky formulascompact enough that all of them may some day fit into a ROM..PPMore important, DEC regards the VMS codes as proprietaryand guards them zealously against unauthorized use. But the\fIlibm\fR codes in 4.3 BSD 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 whose arithmetic resemblesVAX D_floating\-point need use anything worse than the new \fIlibm\fR..PP\fBIEEE STANDARD 754 Floating\-Point Arithmetic:\fR.PPThis standard is on its way to becoming more widely adoptedthan any other design for computer arithmetic.VLSI chips that conform to some version of that standard have beenproduced by a host of manufacturers, among them ....nf.ta 0.5i +\w'Intel i8070, i80287'u+6n Intel i8087, i80287 National Semiconductor 32081 Motorola 68881 Weitek WTL-1032, ... , -1165 Zilog Z8070 Western Electric (AT&T) WE32106..ta.fiOther implementations range from software, done thoroughlyin the Apple Macintosh, through VLSI in the Hewlett\-Packard9000 series, to the ELXSI 6400 running ECL at 3 Megaflops.Several other companies have adopted the formatsof IEEE 754 without, alas, adhering to the standard's wayof handling rounding and exceptions like over/underflow.The DEC VAX G_floating\-point format is very similar to the IEEE754 Double format, so similar that the C programs for theIEEE versions of most of the elementary functions listedabove could easily be converted to run on a MicroVAX, thoughnobody has volunteered to do that yet..PPThe codes in 4.3 BSD's \fIlibm\fR for machines that conform toIEEE 754 are intended primarily for the National Semi. 32081and WTL 1164/65. To use these codes with the Intel or Zilogchips, or with the Apple Macintosh or ELXSI 6400, is toforego the use of better codes provided (perhaps freely) bythose companies and designed by some of the authors of thecodes above.Except for \fIatan\fR, \fIcabs\fR, \fIcbrt\fR, \fIerf\fR,\fIerfc\fR, \fIhypot\fR, \fIj0\-jn\fR, \fIlgamma\fR, \fIpow\fRand \fIy0\-yn\fR,the Motorola 68881 has all the functions in \fIlibm\fR on chip,and faster and more accurate;it, Apple, the i8087, Z8070 and WE32106 all use 64.if n \sig..if t \significantbits.The 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..PP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -