⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 math.3

📁 早期freebsd实现
💻 3
📖 第 1 页 / 共 2 页
字号:
Properties of IEEE 754 Double\-Precision:.RSWordsize: 64 bits, 8 bytes.  Radix: Binary..brPrecision: 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+1nRange:	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. ....REReserved operands:.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 are 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..brNOTE: Trichotomy is violated by \*(nn..RSBesides being FALSE, predicates that entail orderedcomparison, rather than mere (in)equality,signal Invalid Operation when \*(nn is involved..RE.RERounding:.RSEvery algebraic operation (+, \-, \(**, /,.if n \sqrt).if t \\(sr)is rounded by default to within half an \*(up, andwhen the rounding error is exactly half an \*(up thenthe rounded value's least significant bit is zero.This kind of rounding is usually the best kind,sometimes provably so; for instance, for everyx = 1.0, 2.0, 3.0, 4.0, ..., 2.0**52, we find(x/3.0)\(**3.0 == x and (x/10.0)\(**10.0 == x and ...despite that both the quotients and the productshave been rounded.  Only rounding like IEEE 754can do that.  But no single kind of rounding can beproved best for every circumstance, so IEEE 754provides rounding towards zero or towards.If +or towards.If \-at the programmer's option.  And thesame kinds of rounding are specified forBinary\-Decimal Conversions, at least for magnitudesbetween roughly 1.0e\-10 and 1.0e37..REExceptions:.RSIEEE 754 recognizes five kinds of floating\-point exceptions,listed below in declining order of probable importance..RS.nf.ta \w'Invalid Operation'u+6n +\w'Gradual Underflow'u+2nException	Default Result.tc \(ru		.tcInvalid Operation	\*(nn, or FALSE.if n \{\Overflow	\(+-InfinityDivide by Zero	\(+-Infinity \}.if t \{\Overflow	\(+-\(ifDivide by Zero	\(+-\(if \}Underflow	Gradual UnderflowInexact	Rounded value.ta.fi.RENOTE:  An Exception is not an Error unless handledbadly.  What makes a class of exceptions exceptionalis that no single default response can be satisfactoryin every instance.  On the other hand, if a defaultresponse will serve most instances satisfactorily,the unsatisfactory instances cannot justify abortingcomputation every time the exception occurs..RE.PPFor each kind of floating\-point exception, IEEE 754provides a Flag that is raised each time its exceptionis signaled, and stays raised until the program resetsit.  Programs may also test, save and restore a flag.Thus, IEEE 754 provides three ways by which programsmay cope with exceptions for which the default resultmight be unsatisfactory:.IP 1) \w'\0\0\0\0'uTest for a condition that might cause an exceptionlater, and branch to avoid the exception..IP 2) \w'\0\0\0\0'uTest a flag to see whether an exception has occurredsince the program last reset its flag..IP 3) \w'\0\0\0\0'uTest a result to see whether it is a value that onlyan exception could have produced..RSCAUTION: The only reliable ways to discoverwhether Underflow has occurred are to test whetherproducts or quotients lie closer to zero than theunderflow threshold, or to test the Underflowflag.  (Sums and differences cannot underflow inIEEE 754; if x.if n \!=.if t \\(!=y then x\-y is correct tofull precision and certainly nonzero regardless ofhow tiny it may be.)  Products and quotients thatunderflow gradually can lose accuracy graduallywithout vanishing, so comparing them with zero(as one might on a VAX) will not reveal the loss.Fortunately, if a gradually underflowed value isdestined to be added to something bigger than theunderflow threshold, as is almost always the case,digits lost to gradual underflow will not be missedbecause they would have been rounded off anyway.So gradual underflows are usually \fIprovably\fR ignorable.The same cannot be said of underflows flushed to 0..RE.PPAt the option of an implementor conforming to IEEE 754,other ways to cope with exceptions may be provided:.IP 4) \w'\0\0\0\0'uABORT.  This mechanism classifies an exception inadvance as an incident to be handled by meanstraditionally associated with error\-handlingstatements like "ON ERROR GO TO ...".  Differentlanguages offer different forms of this statement,but most share the following characteristics:.IP \(em \w'\0\0\0\0'uNo means is provided to substitute a value forthe offending operation's result and resumecomputation from what may be the middle of anexpression.  An exceptional result is abandoned..IP \(em \w'\0\0\0\0'uIn a subprogram that lacks an error\-handlingstatement, an exception causes the subprogram toabort within whatever program called it, and soon back up the chain of calling subprograms untilan error\-handling statement is encountered or thewhole task is aborted and memory is dumped..IP 5) \w'\0\0\0\0'uSTOP.  This mechanism, requiring an interactivedebugging environment, is more for the programmerthan the program.  It classifies an exception inadvance as a symptom of a programmer's error; theexception suspends execution as near as it can tothe offending operation so that the programmer canlook around to see how it happened.  Quite oftenthe first several exceptions turn out to be quiteunexceptionable, so the programmer ought ideallyto be able to resume execution after each one as ifexecution had not been stopped..IP 6) \w'\0\0\0\0'u\&... Other ways lie beyond the scope of this document..RE.PPThe crucial problem for exception handling is the problem ofScope, and the problem's solution is understood, but notenough manpower was available to implement it fully in timeto be distributed in 4.3 BSD's \fIlibm\fR.  Ideally, eachelementary function should act as if it were indivisible, oratomic, in the sense that ....IP i) \w'iii)'u+2nNo exception should be signaled that is not deserved bythe data supplied to that function..IP ii) \w'iii)'u+2nAny exception signaled should be identified with thatfunction rather than with one of its subroutines..IP iii) \w'iii)'u+2nThe internal behavior of an atomic function should notbe disrupted when a calling program changes fromone to another of the five or so ways of handlingexceptions listed above, although the definitionof the function may be correlated intentionallywith exception handling..PPIdeally, every programmer should be able \fIconveniently\fR toturn a debugged subprogram into one that appears atomic toits users.  But simulating all three characteristics of anatomic function is still a tedious affair, entailing hostsof tests and saves\-restores; work is under way to amelioratethe inconvenience..PPMeanwhile, the functions in \fIlibm\fR are only approximatelyatomic.  They signal no inappropriate exception exceptpossibly ....RSOver/Underflow.RSwhen a result, if properly computed, might have lain barely within range, and.REInexact in \fIcabs\fR, \fIcbrt\fR, \fIhypot\fR, \fIlog10\fR and \fIpow\fR.RSwhen it happens to be exact, thanks to fortuitous cancellation of errors..RE.REOtherwise, ....RSInvalid Operation is signaled only when.RSany result but \*(nn would probably be misleading..REOverflow is signaled only when.RSthe exact result would be finite but beyond the overflow threshold..REDivide\-by\-Zero is signaled only when.RSa function takes exactly infinite values at finite operands..REUnderflow is signaled only when.RSthe exact result would be nonzero but tinier than the underflow threshold..REInexact is signaled only when.RSgreater range or precision would be needed to represent the exact result..RE.RE.SH BUGSWhen signals are appropriate, they are emitted by certainoperations within the codes, so a subroutine\-trace may beneeded to identify the function with its signal in casemethod 5) above is in use.  And the codes all take theIEEE 754 defaults for granted; this means that a decision totrap all divisions by zero could disrupt a code that wouldotherwise get correct results despite division by zero..SH SEE ALSOAn explanation of IEEE 754 and its proposed extension p854was published in the IEEE magazine MICRO in August 1984 underthe title "A Proposed Radix\- and Word\-length\-independentStandard for Floating\-point Arithmetic" by W. J. Cody et al.The manuals for Pascal, C and BASIC on the Apple Macintoshdocument the features of IEEE 754 pretty well.Articles in the IEEE magazine COMPUTER vol. 14 no. 3 (Mar.1981), and in the ACM SIGNUM Newsletter Special Issue ofOct. 1979, may be helpful although they pertain tosuperseded drafts of the standard.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -