xref: /freebsd/lib/msun/man/ieee.3 (revision dc36d6f9bb1753f3808552f3afd30eda9a7b206a)
129bf6af8SDavid Schultz.\" Copyright (c) 1985 Regents of the University of California.
23a8617a8SJordan K. Hubbard.\" All rights reserved.
33a8617a8SJordan K. Hubbard.\"
43a8617a8SJordan K. Hubbard.\" Redistribution and use in source and binary forms, with or without
53a8617a8SJordan K. Hubbard.\" modification, are permitted provided that the following conditions
63a8617a8SJordan K. Hubbard.\" are met:
73a8617a8SJordan K. Hubbard.\" 1. Redistributions of source code must retain the above copyright
83a8617a8SJordan K. Hubbard.\"    notice, this list of conditions and the following disclaimer.
93a8617a8SJordan K. Hubbard.\" 2. Redistributions in binary form must reproduce the above copyright
103a8617a8SJordan K. Hubbard.\"    notice, this list of conditions and the following disclaimer in the
113a8617a8SJordan K. Hubbard.\"    documentation and/or other materials provided with the distribution.
12*fbbd9655SWarner Losh.\" 3. Neither the name of the University nor the names of its contributors
133a8617a8SJordan K. Hubbard.\"    may be used to endorse or promote products derived from this software
143a8617a8SJordan K. Hubbard.\"    without specific prior written permission.
153a8617a8SJordan K. Hubbard.\"
163a8617a8SJordan K. Hubbard.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
173a8617a8SJordan K. Hubbard.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
183a8617a8SJordan K. Hubbard.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
193a8617a8SJordan K. Hubbard.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
203a8617a8SJordan K. Hubbard.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
213a8617a8SJordan K. Hubbard.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
223a8617a8SJordan K. Hubbard.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
233a8617a8SJordan K. Hubbard.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
243a8617a8SJordan K. Hubbard.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
253a8617a8SJordan K. Hubbard.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
263a8617a8SJordan K. Hubbard.\" SUCH DAMAGE.
273a8617a8SJordan K. Hubbard.\"
2829bf6af8SDavid Schultz.Dd January 26, 2005
293a8617a8SJordan K. Hubbard.Dt IEEE 3
303a8617a8SJordan K. Hubbard.Os
313a8617a8SJordan K. Hubbard.Sh NAME
3229bf6af8SDavid Schultz.Nm ieee
3329bf6af8SDavid Schultz.Nd IEEE standard 754 for floating-point arithmetic
343a8617a8SJordan K. Hubbard.Sh DESCRIPTION
3529bf6af8SDavid SchultzThe IEEE Standard 754 for Binary Floating-Point Arithmetic
3629bf6af8SDavid Schultzdefines representations of floating-point numbers and abstract
3729bf6af8SDavid Schultzproperties of arithmetic operations relating to precision,
3829bf6af8SDavid Schultzrounding, and exceptional cases, as described below.
3929bf6af8SDavid Schultz.Ss IEEE STANDARD 754 Floating-Point Arithmetic
4029bf6af8SDavid SchultzRadix: Binary.
413a8617a8SJordan K. Hubbard.Pp
4229bf6af8SDavid SchultzOverflow and underflow:
4329bf6af8SDavid Schultz.Bd -ragged -offset indent -compact
4429bf6af8SDavid SchultzOverflow goes by default to a signed \*(If.
4529bf6af8SDavid SchultzUnderflow is
4629bf6af8SDavid Schultz.Em gradual .
4729bf6af8SDavid Schultz.Ed
483a8617a8SJordan K. Hubbard.Pp
4929bf6af8SDavid SchultzZero is represented ambiguously as +0 or \-0.
5029bf6af8SDavid Schultz.Bd -ragged -offset indent -compact
5129bf6af8SDavid SchultzIts sign transforms correctly through multiplication or
5229bf6af8SDavid Schultzdivision, and is preserved by addition of zeros
5329bf6af8SDavid Schultzwith like signs; but x\-x yields +0 for every
5429bf6af8SDavid Schultzfinite x.
5529bf6af8SDavid SchultzThe only operations that reveal zero's
5629bf6af8SDavid Schultzsign are division by zero and
5729bf6af8SDavid Schultz.Fn copysign x \(+-0 .
5829bf6af8SDavid SchultzIn particular, comparison (x > y, x \(>= y, etc.)\&
5929bf6af8SDavid Schultzcannot be affected by the sign of zero; but if
6029bf6af8SDavid Schultzfinite x = y then \*(If = 1/(x\-y) \(!= \-1/(y\-x) = \-\*(If.
6129bf6af8SDavid Schultz.Ed
623a8617a8SJordan K. Hubbard.Pp
6329bf6af8SDavid SchultzInfinity is signed.
6429bf6af8SDavid Schultz.Bd -ragged -offset indent -compact
6529bf6af8SDavid SchultzIt persists when added to itself
6629bf6af8SDavid Schultzor to any finite number.
6729bf6af8SDavid SchultzIts sign transforms
6829bf6af8SDavid Schultzcorrectly through multiplication and division, and
6929bf6af8SDavid Schultz(finite)/\(+-\*(If\0=\0\(+-0
7029bf6af8SDavid Schultz(nonzero)/0 = \(+-\*(If.
713a8617a8SJordan K. HubbardBut
7229bf6af8SDavid Schultz\*(If\-\*(If, \*(If\(**0 and \*(If/\*(If
7329bf6af8SDavid Schultzare, like 0/0 and sqrt(\-3),
7429bf6af8SDavid Schultzinvalid operations that produce \*(Na. ...
7529bf6af8SDavid Schultz.Ed
763a8617a8SJordan K. Hubbard.Pp
7729bf6af8SDavid SchultzReserved operands (\*(Nas):
7829bf6af8SDavid Schultz.Bd -ragged -offset indent -compact
7929bf6af8SDavid SchultzAn \*(Na is
8029bf6af8SDavid Schultz.Em ( N Ns ot Em a N Ns umber ) .
8129bf6af8SDavid SchultzSome \*(Nas, called Signaling \*(Nas, trap any floating-point operation
8229bf6af8SDavid Schultzperformed upon them; they are used to mark missing
8329bf6af8SDavid Schultzor uninitialized values, or nonexistent elements
8429bf6af8SDavid Schultzof arrays.
8529bf6af8SDavid SchultzThe rest are Quiet \*(Nas; they are
8629bf6af8SDavid Schultzthe default results of Invalid Operations, and
8729bf6af8SDavid Schultzpropagate through subsequent arithmetic operations.
8829bf6af8SDavid SchultzIf x \(!= x then x is \*(Na; every other predicate
8929bf6af8SDavid Schultz(x > y, x = y, x < y, ...) is FALSE if \*(Na is involved.
9029bf6af8SDavid Schultz.Ed
9129bf6af8SDavid Schultz.Pp
9229bf6af8SDavid SchultzRounding:
9329bf6af8SDavid Schultz.Bd -ragged -offset indent -compact
9429bf6af8SDavid SchultzEvery algebraic operation (+, \-, \(**, /,
9529bf6af8SDavid Schultz\(sr)
9629bf6af8SDavid Schultzis rounded by default to within half an
9729bf6af8SDavid Schultz.Em ulp ,
9829bf6af8SDavid Schultzand when the rounding error is exactly half an
9929bf6af8SDavid Schultz.Em ulp
10029bf6af8SDavid Schultzthen
10129bf6af8SDavid Schultzthe rounded value's least significant bit is zero.
10229bf6af8SDavid Schultz(An
10329bf6af8SDavid Schultz.Em ulp
10429bf6af8SDavid Schultzis one
10529bf6af8SDavid Schultz.Em U Ns nit
10629bf6af8SDavid Schultzin the
10729bf6af8SDavid Schultz.Em L Ns ast
10829bf6af8SDavid Schultz.Em P Ns lace . )
10929bf6af8SDavid SchultzThis kind of rounding is usually the best kind,
11029bf6af8SDavid Schultzsometimes provably so; for instance, for every
11129bf6af8SDavid Schultzx = 1.0, 2.0, 3.0, 4.0, ..., 2.0**52, we find
11229bf6af8SDavid Schultz(x/3.0)\(**3.0 == x and (x/10.0)\(**10.0 == x and ...
11329bf6af8SDavid Schultzdespite that both the quotients and the products
11429bf6af8SDavid Schultzhave been rounded.
11529bf6af8SDavid SchultzOnly rounding like IEEE 754 can do that.
11629bf6af8SDavid SchultzBut no single kind of rounding can be
11729bf6af8SDavid Schultzproved best for every circumstance, so IEEE 754
11829bf6af8SDavid Schultzprovides rounding towards zero or towards
11929bf6af8SDavid Schultz+\*(If or towards \-\*(If
12029bf6af8SDavid Schultzat the programmer's option.
12129bf6af8SDavid Schultz.Ed
12229bf6af8SDavid Schultz.Pp
12329bf6af8SDavid SchultzExceptions:
12429bf6af8SDavid Schultz.Bd -ragged -offset indent -compact
12529bf6af8SDavid SchultzIEEE 754 recognizes five kinds of floating-point exceptions,
12629bf6af8SDavid Schultzlisted below in declining order of probable importance.
12729bf6af8SDavid Schultz.Bl -column -offset indent "Invalid Operation" "Gradual Underflow"
12829bf6af8SDavid Schultz.Em "Exception	Default Result"
12929bf6af8SDavid SchultzInvalid Operation	\*(Na, or FALSE
13029bf6af8SDavid SchultzOverflow	\(+-\*(If
13129bf6af8SDavid SchultzDivide by Zero	\(+-\*(If
13229bf6af8SDavid SchultzUnderflow	Gradual Underflow
13329bf6af8SDavid SchultzInexact	Rounded value
13429bf6af8SDavid Schultz.El
13529bf6af8SDavid Schultz.Pp
13629bf6af8SDavid SchultzNOTE: An Exception is not an Error unless handled
13729bf6af8SDavid Schultzbadly.
13829bf6af8SDavid SchultzWhat makes a class of exceptions exceptional
13929bf6af8SDavid Schultzis that no single default response can be satisfactory
14029bf6af8SDavid Schultzin every instance.
14129bf6af8SDavid SchultzOn the other hand, if a default
14229bf6af8SDavid Schultzresponse will serve most instances satisfactorily,
14329bf6af8SDavid Schultzthe unsatisfactory instances cannot justify aborting
14429bf6af8SDavid Schultzcomputation every time the exception occurs.
14529bf6af8SDavid Schultz.Ed
14629bf6af8SDavid Schultz.Ss Data Formats
14729bf6af8SDavid SchultzSingle-precision:
14829bf6af8SDavid Schultz.Bd -ragged -offset indent -compact
14929bf6af8SDavid SchultzType name:
15029bf6af8SDavid Schultz.Vt float
15129bf6af8SDavid Schultz.Pp
15229bf6af8SDavid SchultzWordsize: 32 bits.
15329bf6af8SDavid Schultz.Pp
15429bf6af8SDavid SchultzPrecision: 24 significant bits,
15529bf6af8SDavid Schultzroughly like 7 significant decimals.
156284eab32SJoel Dahl.Pp
15729bf6af8SDavid SchultzIf x and x' are consecutive positive single-precision
15829bf6af8SDavid Schultznumbers (they differ by 1
15929bf6af8SDavid Schultz.Em ulp ) ,
16029bf6af8SDavid Schultzthen
161284eab32SJoel Dahl.Bl -column "XXX" -compact
16229bf6af8SDavid Schultz5.9e\-08 < 0.5**24 < (x'\-x)/x \(<= 0.5**23 < 1.2e\-07.
163284eab32SJoel Dahl.El
16429bf6af8SDavid Schultz.Pp
16529bf6af8SDavid Schultz.Bl -column "XXX" -compact
16629bf6af8SDavid SchultzRange:	Overflow threshold  = 2.0**128 = 3.4e38
16729bf6af8SDavid Schultz	Underflow threshold = 0.5**126 = 1.2e\-38
16829bf6af8SDavid Schultz.El
169284eab32SJoel Dahl.Pp
17029bf6af8SDavid SchultzUnderflowed results round to the nearest
171284eab32SJoel Dahlinteger multiple of
172284eab32SJoel Dahl.Bl -column "XXX" -compact
173284eab32SJoel Dahl0.5**149 = 1.4e\-45.
174284eab32SJoel Dahl.El
17529bf6af8SDavid Schultz.Ed
17629bf6af8SDavid Schultz.Pp
17729bf6af8SDavid SchultzDouble-precision:
17829bf6af8SDavid Schultz.Bd -ragged -offset indent -compact
17929bf6af8SDavid SchultzType name:
18029bf6af8SDavid Schultz.Vt double
181284eab32SJoel Dahl.Po On some architectures,
18229bf6af8SDavid Schultz.Vt long double
18336daf049SEitan Adleris the same as
184284eab32SJoel Dahl.Vt double
185284eab32SJoel Dahl.Pc
18629bf6af8SDavid Schultz.Pp
18729bf6af8SDavid SchultzWordsize: 64 bits.
18829bf6af8SDavid Schultz.Pp
18929bf6af8SDavid SchultzPrecision: 53 significant bits,
19029bf6af8SDavid Schultzroughly like 16 significant decimals.
191284eab32SJoel Dahl.Pp
19229bf6af8SDavid SchultzIf x and x' are consecutive positive double-precision
19329bf6af8SDavid Schultznumbers (they differ by 1
19429bf6af8SDavid Schultz.Em ulp ) ,
19529bf6af8SDavid Schultzthen
196284eab32SJoel Dahl.Bl -column "XXX" -compact
19729bf6af8SDavid Schultz1.1e\-16 < 0.5**53 < (x'\-x)/x \(<= 0.5**52 < 2.3e\-16.
198284eab32SJoel Dahl.El
19929bf6af8SDavid Schultz.Pp
20029bf6af8SDavid Schultz.Bl -column "XXX" -compact
20129bf6af8SDavid SchultzRange:	Overflow threshold  = 2.0**1024 = 1.8e308
20229bf6af8SDavid Schultz	Underflow threshold = 0.5**1022 = 2.2e\-308
20329bf6af8SDavid Schultz.El
204284eab32SJoel Dahl.Pp
20529bf6af8SDavid SchultzUnderflowed results round to the nearest
206284eab32SJoel Dahlinteger multiple of
207284eab32SJoel Dahl.Bl -column "XXX" -compact
208284eab32SJoel Dahl0.5**1074 = 4.9e\-324.
209284eab32SJoel Dahl.El
21029bf6af8SDavid Schultz.Ed
21129bf6af8SDavid Schultz.Pp
21229bf6af8SDavid SchultzExtended-precision:
21329bf6af8SDavid Schultz.Bd -ragged -offset indent -compact
21429bf6af8SDavid SchultzType name:
21529bf6af8SDavid Schultz.Vt long double
21629bf6af8SDavid Schultz(when supported by the hardware)
21729bf6af8SDavid Schultz.Pp
21829bf6af8SDavid SchultzWordsize: 96 bits.
21929bf6af8SDavid Schultz.Pp
22029bf6af8SDavid SchultzPrecision: 64 significant bits,
22129bf6af8SDavid Schultzroughly like 19 significant decimals.
222284eab32SJoel Dahl.Pp
22393e06638SDavid SchultzIf x and x' are consecutive positive extended-precision
22429bf6af8SDavid Schultznumbers (they differ by 1
22529bf6af8SDavid Schultz.Em ulp ) ,
22629bf6af8SDavid Schultzthen
227284eab32SJoel Dahl.Bl -column "XXX" -compact
22829bf6af8SDavid Schultz1.0e\-19 < 0.5**63 < (x'\-x)/x \(<= 0.5**62 < 2.2e\-19.
229284eab32SJoel Dahl.El
23029bf6af8SDavid Schultz.Pp
23129bf6af8SDavid Schultz.Bl -column "XXX" -compact
23229bf6af8SDavid SchultzRange:	Overflow threshold  = 2.0**16384 = 1.2e4932
23329bf6af8SDavid Schultz	Underflow threshold = 0.5**16382 = 3.4e\-4932
23429bf6af8SDavid Schultz.El
235284eab32SJoel Dahl.Pp
23629bf6af8SDavid SchultzUnderflowed results round to the nearest
237284eab32SJoel Dahlinteger multiple of
238284eab32SJoel Dahl.Bl -column "XXX" -compact
239284eab32SJoel Dahl0.5**16445 = 5.7e\-4953.
240284eab32SJoel Dahl.El
24129bf6af8SDavid Schultz.Ed
24229bf6af8SDavid Schultz.Pp
24329bf6af8SDavid SchultzQuad-extended-precision:
24429bf6af8SDavid Schultz.Bd -ragged -offset indent -compact
24529bf6af8SDavid SchultzType name:
24629bf6af8SDavid Schultz.Vt long double
24729bf6af8SDavid Schultz(when supported by the hardware)
24829bf6af8SDavid Schultz.Pp
24929bf6af8SDavid SchultzWordsize: 128 bits.
25029bf6af8SDavid Schultz.Pp
25129bf6af8SDavid SchultzPrecision: 113 significant bits,
25229bf6af8SDavid Schultzroughly like 34 significant decimals.
253284eab32SJoel Dahl.Pp
25493e06638SDavid SchultzIf x and x' are consecutive positive quad-extended-precision
25529bf6af8SDavid Schultznumbers (they differ by 1
25629bf6af8SDavid Schultz.Em ulp ) ,
25729bf6af8SDavid Schultzthen
258284eab32SJoel Dahl.Bl -column "XXX" -compact
25929bf6af8SDavid Schultz9.6e\-35 < 0.5**113 < (x'\-x)/x \(<= 0.5**112 < 2.0e\-34.
260284eab32SJoel Dahl.El
26129bf6af8SDavid Schultz.Pp
26229bf6af8SDavid Schultz.Bl -column "XXX" -compact
26329bf6af8SDavid SchultzRange:	Overflow threshold  = 2.0**16384 = 1.2e4932
26429bf6af8SDavid Schultz	Underflow threshold = 0.5**16382 = 3.4e\-4932
26529bf6af8SDavid Schultz.El
266284eab32SJoel Dahl.Pp
26729bf6af8SDavid SchultzUnderflowed results round to the nearest
268284eab32SJoel Dahlinteger multiple of
269284eab32SJoel Dahl.Bl -column "XXX" -compact
270284eab32SJoel Dahl0.5**16494 = 6.5e\-4966.
271284eab32SJoel Dahl.El
27229bf6af8SDavid Schultz.Ed
27329bf6af8SDavid Schultz.Ss Additional Information Regarding Exceptions
27429bf6af8SDavid SchultzFor each kind of floating-point exception, IEEE 754
27529bf6af8SDavid Schultzprovides a Flag that is raised each time its exception
27629bf6af8SDavid Schultzis signaled, and stays raised until the program resets
27729bf6af8SDavid Schultzit.
27829bf6af8SDavid SchultzPrograms may also test, save and restore a flag.
27929bf6af8SDavid SchultzThus, IEEE 754 provides three ways by which programs
28029bf6af8SDavid Schultzmay cope with exceptions for which the default result
28129bf6af8SDavid Schultzmight be unsatisfactory:
28229bf6af8SDavid Schultz.Bl -enum
28329bf6af8SDavid Schultz.It
28429bf6af8SDavid SchultzTest for a condition that might cause an exception
28529bf6af8SDavid Schultzlater, and branch to avoid the exception.
28629bf6af8SDavid Schultz.It
28729bf6af8SDavid SchultzTest a flag to see whether an exception has occurred
28829bf6af8SDavid Schultzsince the program last reset its flag.
28929bf6af8SDavid Schultz.It
29029bf6af8SDavid SchultzTest a result to see whether it is a value that only
29129bf6af8SDavid Schultzan exception could have produced.
29229bf6af8SDavid Schultz.Pp
29329bf6af8SDavid SchultzCAUTION: The only reliable ways to discover
29429bf6af8SDavid Schultzwhether Underflow has occurred are to test whether
29529bf6af8SDavid Schultzproducts or quotients lie closer to zero than the
29629bf6af8SDavid Schultzunderflow threshold, or to test the Underflow
29729bf6af8SDavid Schultzflag.
29829bf6af8SDavid Schultz(Sums and differences cannot underflow in
29929bf6af8SDavid SchultzIEEE 754; if x \(!= y then x\-y is correct to
30029bf6af8SDavid Schultzfull precision and certainly nonzero regardless of
30129bf6af8SDavid Schultzhow tiny it may be.)
30229bf6af8SDavid SchultzProducts and quotients that
30329bf6af8SDavid Schultzunderflow gradually can lose accuracy gradually
30429bf6af8SDavid Schultzwithout vanishing, so comparing them with zero
30529bf6af8SDavid Schultz(as one might on a VAX) will not reveal the loss.
30629bf6af8SDavid SchultzFortunately, if a gradually underflowed value is
30729bf6af8SDavid Schultzdestined to be added to something bigger than the
30829bf6af8SDavid Schultzunderflow threshold, as is almost always the case,
30929bf6af8SDavid Schultzdigits lost to gradual underflow will not be missed
31029bf6af8SDavid Schultzbecause they would have been rounded off anyway.
31129bf6af8SDavid SchultzSo gradual underflows are usually
31229bf6af8SDavid Schultz.Em provably
31329bf6af8SDavid Schultzignorable.
31429bf6af8SDavid SchultzThe same cannot be said of underflows flushed to 0.
31529bf6af8SDavid Schultz.El
31629bf6af8SDavid Schultz.Pp
31729bf6af8SDavid SchultzAt the option of an implementor conforming to IEEE 754,
31829bf6af8SDavid Schultzother ways to cope with exceptions may be provided:
31929bf6af8SDavid Schultz.Bl -enum
32029bf6af8SDavid Schultz.It
32129bf6af8SDavid SchultzABORT.
32229bf6af8SDavid SchultzThis mechanism classifies an exception in
32329bf6af8SDavid Schultzadvance as an incident to be handled by means
32429bf6af8SDavid Schultztraditionally associated with error-handling
32529bf6af8SDavid Schultzstatements like "ON ERROR GO TO ...".
32629bf6af8SDavid SchultzDifferent
32729bf6af8SDavid Schultzlanguages offer different forms of this statement,
32829bf6af8SDavid Schultzbut most share the following characteristics:
32929bf6af8SDavid Schultz.Bl -dash
33029bf6af8SDavid Schultz.It
33129bf6af8SDavid SchultzNo means is provided to substitute a value for
33229bf6af8SDavid Schultzthe offending operation's result and resume
33329bf6af8SDavid Schultzcomputation from what may be the middle of an
33429bf6af8SDavid Schultzexpression.
33529bf6af8SDavid SchultzAn exceptional result is abandoned.
33629bf6af8SDavid Schultz.It
33729bf6af8SDavid SchultzIn a subprogram that lacks an error-handling
33829bf6af8SDavid Schultzstatement, an exception causes the subprogram to
33929bf6af8SDavid Schultzabort within whatever program called it, and so
34029bf6af8SDavid Schultzon back up the chain of calling subprograms until
34129bf6af8SDavid Schultzan error-handling statement is encountered or the
34229bf6af8SDavid Schultzwhole task is aborted and memory is dumped.
34329bf6af8SDavid Schultz.El
34429bf6af8SDavid Schultz.It
34529bf6af8SDavid SchultzSTOP.
34629bf6af8SDavid SchultzThis mechanism, requiring an interactive
34729bf6af8SDavid Schultzdebugging environment, is more for the programmer
34829bf6af8SDavid Schultzthan the program.
34929bf6af8SDavid SchultzIt classifies an exception in
35029bf6af8SDavid Schultzadvance as a symptom of a programmer's error; the
35129bf6af8SDavid Schultzexception suspends execution as near as it can to
35229bf6af8SDavid Schultzthe offending operation so that the programmer can
35329bf6af8SDavid Schultzlook around to see how it happened.
35429bf6af8SDavid SchultzQuite often
35529bf6af8SDavid Schultzthe first several exceptions turn out to be quite
35629bf6af8SDavid Schultzunexceptionable, so the programmer ought ideally
35729bf6af8SDavid Schultzto be able to resume execution after each one as if
35829bf6af8SDavid Schultzexecution had not been stopped.
35929bf6af8SDavid Schultz.It
36029bf6af8SDavid Schultz\&... Other ways lie beyond the scope of this document.
36129bf6af8SDavid Schultz.El
36229bf6af8SDavid Schultz.Pp
36329bf6af8SDavid SchultzIdeally, each
36429bf6af8SDavid Schultzelementary function should act as if it were indivisible, or
36529bf6af8SDavid Schultzatomic, in the sense that ...
36629bf6af8SDavid Schultz.Bl -enum
36729bf6af8SDavid Schultz.It
36829bf6af8SDavid SchultzNo exception should be signaled that is not deserved by
36929bf6af8SDavid Schultzthe data supplied to that function.
37029bf6af8SDavid Schultz.It
37129bf6af8SDavid SchultzAny exception signaled should be identified with that
37229bf6af8SDavid Schultzfunction rather than with one of its subroutines.
37329bf6af8SDavid Schultz.It
37429bf6af8SDavid SchultzThe internal behavior of an atomic function should not
37529bf6af8SDavid Schultzbe disrupted when a calling program changes from
37629bf6af8SDavid Schultzone to another of the five or so ways of handling
37729bf6af8SDavid Schultzexceptions listed above, although the definition
37829bf6af8SDavid Schultzof the function may be correlated intentionally
37929bf6af8SDavid Schultzwith exception handling.
38029bf6af8SDavid Schultz.El
38129bf6af8SDavid Schultz.Pp
38229bf6af8SDavid SchultzThe functions in
38329bf6af8SDavid Schultz.Nm libm
38429bf6af8SDavid Schultzare only approximately atomic.
38529bf6af8SDavid SchultzThey signal no inappropriate exception except possibly ...
38629bf6af8SDavid Schultz.Bl -tag -width indent -offset indent -compact
38729bf6af8SDavid Schultz.It Xo
38829bf6af8SDavid SchultzOver/Underflow
38929bf6af8SDavid Schultz.Xc
39029bf6af8SDavid Schultzwhen a result, if properly computed, might have lain barely within range, and
39129bf6af8SDavid Schultz.It Xo
39229bf6af8SDavid SchultzInexact in
39329bf6af8SDavid Schultz.Fn cabs ,
39429bf6af8SDavid Schultz.Fn cbrt ,
39529bf6af8SDavid Schultz.Fn hypot ,
39629bf6af8SDavid Schultz.Fn log10
3977a15a32aSJordan K. Hubbardand
39829bf6af8SDavid Schultz.Fn pow
39929bf6af8SDavid Schultz.Xc
40029bf6af8SDavid Schultzwhen it happens to be exact, thanks to fortuitous cancellation of errors.
40129bf6af8SDavid Schultz.El
40229bf6af8SDavid SchultzOtherwise, ...
40329bf6af8SDavid Schultz.Bl -tag -width indent -offset indent -compact
40429bf6af8SDavid Schultz.It Xo
40529bf6af8SDavid SchultzInvalid Operation is signaled only when
40629bf6af8SDavid Schultz.Xc
40729bf6af8SDavid Schultzany result but \*(Na would probably be misleading.
40829bf6af8SDavid Schultz.It Xo
40929bf6af8SDavid SchultzOverflow is signaled only when
41029bf6af8SDavid Schultz.Xc
41129bf6af8SDavid Schultzthe exact result would be finite but beyond the overflow threshold.
41229bf6af8SDavid Schultz.It Xo
41329bf6af8SDavid SchultzDivide-by-Zero is signaled only when
41429bf6af8SDavid Schultz.Xc
41529bf6af8SDavid Schultza function takes exactly infinite values at finite operands.
41629bf6af8SDavid Schultz.It Xo
41729bf6af8SDavid SchultzUnderflow is signaled only when
41829bf6af8SDavid Schultz.Xc
41929bf6af8SDavid Schultzthe exact result would be nonzero but tinier than the underflow threshold.
42029bf6af8SDavid Schultz.It Xo
42129bf6af8SDavid SchultzInexact is signaled only when
42229bf6af8SDavid Schultz.Xc
42329bf6af8SDavid Schultzgreater range or precision would be needed to represent the exact result.
42429bf6af8SDavid Schultz.El
4253a8617a8SJordan K. Hubbard.Sh SEE ALSO
42629bf6af8SDavid Schultz.Xr fenv 3 ,
42729bf6af8SDavid Schultz.Xr ieee_test 3 ,
4283a8617a8SJordan K. Hubbard.Xr math 3
42929bf6af8SDavid Schultz.Pp
43029bf6af8SDavid SchultzAn explanation of IEEE 754 and its proposed extension p854
43129bf6af8SDavid Schultzwas published in the IEEE magazine MICRO in August 1984 under
43229bf6af8SDavid Schultzthe title "A Proposed Radix- and Word-length-independent
43329bf6af8SDavid SchultzStandard for Floating-point Arithmetic" by
43429bf6af8SDavid Schultz.An "W. J. Cody"
43529bf6af8SDavid Schultzet al.
43629bf6af8SDavid SchultzThe manuals for Pascal, C and BASIC on the Apple Macintosh
43729bf6af8SDavid Schultzdocument the features of IEEE 754 pretty well.
43829bf6af8SDavid SchultzArticles in the IEEE magazine COMPUTER vol.\& 14 no.\& 3 (Mar.\&
43929bf6af8SDavid Schultz1981), and in the ACM SIGNUM Newsletter Special Issue of
44029bf6af8SDavid SchultzOct.\& 1979, may be helpful although they pertain to
44129bf6af8SDavid Schultzsuperseded drafts of the standard.
44224a0682cSRuslan Ermilov.Sh STANDARDS
44324a0682cSRuslan Ermilov.St -ieee754
444