Initial import from FreeBSD RELENG_4:
[games.git] / lib / libm / common_source / math.3
1 .\" Copyright (c) 1985, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\"    must display the following acknowledgement:
14 .\"     This product includes software developed by the University of
15 .\"     California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\"    may be used to endorse or promote products derived from this software
18 .\"    without specific prior written permission.
19 .\"
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" SUCH DAMAGE.
31 .\"
32 .\"     @(#)math.3      8.2 (Berkeley) 5/5/94
33 .\" $FreeBSD: src/lib/libm/common_source/math.3,v 1.4.2.1 2001/07/22 12:07:16 dd Exp $
34 .\"
35 .TH MATH 3 "May 5, 1994"
36 .UC 4
37 .ds up \fIulp\fR
38 .ds nn \fINaN\fR
39 .de If
40 .if n \\
41 \\$1Infinity\\$2
42 .if t \\
43 \\$1\\(if\\$2
44 ..
45 .SH NAME
46 math \- introduction to mathematical library functions
47 .SH DESCRIPTION
48 These functions constitute the C math library,
49 .I libm.
50 The link editor searches this library under the \*(lq\-lm\*(rq option.
51 Declarations for these functions may be obtained from the include file
52 .RI < math.h >.
53 The Fortran math library is described in ``man 3f intro''.
54 .SH "LIST OF FUNCTIONS"
55 .sp 2
56 .nf
57 .ta \w'copysign'u+2n +\w'infnan.3m'u+10n +\w'inverse trigonometric func'u
58 \fIName\fP      \fIAppears on Page\fP   \fIDescription\fP       \fIError Bound (ULPs)\fP
59 .ta \w'copysign'u+4n +\w'infnan.3m'u+4n +\w'inverse trigonometric function'u+6nC
60 .sp 5p
61 acos    sin.3m  inverse trigonometric function  3
62 acosh   asinh.3m        inverse hyperbolic function     3
63 asin    sin.3m  inverse trigonometric function  3
64 asinh   asinh.3m        inverse hyperbolic function     3
65 atan    sin.3m  inverse trigonometric function  1
66 atanh   asinh.3m        inverse hyperbolic function     3
67 atan2   sin.3m  inverse trigonometric function  2
68 cabs    hypot.3m        complex absolute value  1
69 cbrt    sqrt.3m cube root       1
70 ceil    floor.3m        integer no less than    0
71 copysign        ieee.3m copy sign bit   0
72 cos     sin.3m  trigonometric function  1
73 cosh    sinh.3m hyperbolic function     3
74 drem    ieee.3m remainder       0
75 erf     erf.3m  error function  ???
76 erfc    erf.3m  complementary error function    ???
77 exp     exp.3m  exponential     1
78 expm1   exp.3m  exp(x)\-1       1
79 fabs    floor.3m        absolute value  0
80 floor   floor.3m        integer no greater than 0
81 hypot   hypot.3m        Euclidean distance      1
82 infnan  infnan.3m       signals exceptions
83 j0      j0.3m   bessel function ???
84 j1      j0.3m   bessel function ???
85 jn      j0.3m   bessel function ???
86 lgamma  lgamma.3m       log gamma function; (formerly gamma.3m)
87 log     exp.3m  natural logarithm       1
88 logb    ieee.3m exponent extraction     0
89 log10   exp.3m  logarithm to base 10    3
90 log1p   exp.3m  log(1+x)        1
91 pow     exp.3m  exponential x**y        60\-500
92 rint    floor.3m        round to nearest integer        0
93 scalb   ieee.3m exponent adjustment     0
94 sin     sin.3m  trigonometric function  1
95 sinh    sinh.3m hyperbolic function     3
96 sqrt    sqrt.3m square root     1
97 tan     sin.3m  trigonometric function  3
98 tanh    sinh.3m hyperbolic function     3
99 y0      j0.3m   bessel function ???
100 y1      j0.3m   bessel function ???
101 yn      j0.3m   bessel function ???
102 .ta
103 .fi
104 .SH NOTES
105 In 4.3 BSD, distributed from the University of California
106 in late 1985, most of the foregoing functions come in two
107 versions, one for the double\-precision "D" format in the
108 DEC VAX\-11 family of computers, another for double\-precision
109 arithmetic conforming to the IEEE Standard 754 for Binary
110 Floating\-Point Arithmetic.  The two versions behave very
111 similarly, as should be expected from programs more accurate
112 and robust than was the norm when UNIX was born.  For
113 instance, the programs are accurate to within the numbers
114 of \*(ups tabulated above; an \*(up is one \fIU\fRnit in the \fIL\fRast
115 \fIP\fRlace.  And the programs have been cured of anomalies that
116 afflicted the older math library \fIlibm\fR in which incidents like
117 the following had been reported:
118 .RS
119 sqrt(\-1.0) = 0.0 and log(\-1.0) = \-1.7e38.
120 .br
121 cos(1.0e\-11) > cos(0.0) > 1.0.
122 .br
123 pow(x,1.0)
124 .if n \
125 !=
126 .if t \
127 \(!=
128 x when x = 2.0, 3.0, 4.0, ..., 9.0.
129 .br
130 pow(\-1.0,1.0e10) trapped on Integer Overflow.
131 .br
132 sqrt(1.0e30) and sqrt(1.0e\-30) were very slow.
133 .RE
134 However the two versions do differ in ways that have to be
135 explained, to which end the following notes are provided.
136 .PP
137 \fBDEC VAX\-11 D_floating\-point:\fR
138 .PP
139 This is the format for which the original math library \fIlibm\fR
140 was developed, and to which this manual is still principally
141 dedicated.  It is \fIthe\fR double\-precision format for the PDP\-11
142 and the earlier VAX\-11 machines; VAX\-11s after 1983 were
143 provided with an optional "G" format closer to the IEEE
144 double\-precision format.  The earlier DEC MicroVAXs have no
145 D format, only G double\-precision.
146 (Why?  Why not?)
147 .PP
148 Properties of D_floating\-point:
149 .RS
150 Wordsize: 64 bits, 8 bytes.  Radix: Binary.
151 .br
152 Precision: 56
153 .if n \
154 sig.
155 .if t \
156 significant
157 bits, roughly like 17
158 .if n \
159 sig.
160 .if t \
161 significant
162 decimals.
163 .RS
164 If x and x' are consecutive positive D_floating\-point
165 numbers (they differ by 1 \*(up), then
166 .br
167 1.3e\-17 < 0.5**56 < (x'\-x)/x \(<= 0.5**55 < 2.8e\-17.
168 .RE
169 .nf
170 .ta \w'Range:'u+1n +\w'Underflow threshold'u+1n +\w'= 2.0**127'u+1n
171 Range:  Overflow threshold      = 2.0**127      = 1.7e38.
172         Underflow threshold     = 0.5**128      = 2.9e\-39.
173         NOTE:  THIS RANGE IS COMPARATIVELY NARROW.
174 .ta
175 .fi
176 .RS
177 Overflow customarily stops computation.
178 .br
179 Underflow is customarily flushed quietly to zero.
180 .br
181 CAUTION:
182 .RS
183 It is possible to have x
184 .if n \
185 !=
186 .if t \
187 \(!=
188 y and yet
189 x\-y = 0 because of underflow.  Similarly
190 x > y > 0 cannot prevent either x\(**y = 0
191 or  y/x = 0 from happening without warning.
192 .RE
193 .RE
194 Zero is represented ambiguously.
195 .RS
196 Although 2**55 different representations of zero are accepted by
197 the hardware, only the obvious representation is ever produced.
198 There is no \-0 on a VAX.
199 .RE
200 .If
201 is not part of the VAX architecture.
202 .br
203 Reserved operands:
204 .RS
205 of the 2**55 that the hardware
206 recognizes, only one of them is ever produced.
207 Any floating\-point operation upon a reserved
208 operand, even a MOVF or MOVD, customarily stops
209 computation, so they are not much used.
210 .RE
211 Exceptions:
212 .RS
213 Divisions by zero and operations that
214 overflow are invalid operations that customarily
215 stop computation or, in earlier machines, produce
216 reserved operands that will stop computation.
217 .RE
218 Rounding:
219 .RS
220 Every rational operation  (+, \-, \(**, /) on a
221 VAX (but not necessarily on a PDP\-11), if not an
222 over/underflow nor division by zero, is rounded to
223 within half an \*(up, and when the rounding error is
224 exactly half an \*(up then rounding is away from 0.
225 .RE
226 .RE
227 .PP
228 Except for its narrow range, D_floating\-point is one of the
229 better computer arithmetics designed in the 1960's.
230 Its properties are reflected fairly faithfully in the elementary
231 functions for a VAX distributed in 4.3 BSD.
232 They over/underflow only if their results have to lie out of range
233 or very nearly so, and then they behave much as any rational
234 arithmetic operation that over/underflowed would behave.
235 Similarly, expressions like log(0) and atanh(1) behave
236 like 1/0; and sqrt(\-3) and acos(3) behave like 0/0;
237 they all produce reserved operands and/or stop computation!
238 The situation is described in more detail in manual pages.
239 .RS
240 .ll -0.5i
241 \fIThis response seems excessively punitive, so it is destined
242 to be replaced at some time in the foreseeable future by a
243 more flexible but still uniform scheme being developed to
244 handle all floating\-point arithmetic exceptions neatly.
245 See infnan(3M) for the present state of affairs.\fR
246 .ll +0.5i
247 .RE
248 .PP
249 How do the functions in 4.3 BSD's new \fIlibm\fR for UNIX
250 compare with their counterparts in DEC's VAX/VMS library?
251 Some of the VMS functions are a little faster, some are
252 a little more accurate, some are more puritanical about
253 exceptions (like pow(0.0,0.0) and atan2(0.0,0.0)),
254 and most occupy much more memory than their counterparts in
255 \fIlibm\fR.
256 The VMS codes interpolate in large table to achieve
257 speed and accuracy; the \fIlibm\fR codes use tricky formulas
258 compact enough that all of them may some day fit into a ROM.
259 .PP
260 More important, DEC regards the VMS codes as proprietary
261 and guards them zealously against unauthorized use.  But the
262 \fIlibm\fR codes in 4.3 BSD are intended for the public domain;
263 they may be copied freely provided their provenance is always
264 acknowledged, and provided users assist the authors in their
265 researches by reporting experience with the codes.
266 Therefore no user of UNIX on a machine whose arithmetic resembles
267 VAX D_floating\-point need use anything worse than the new \fIlibm\fR.
268 .PP
269 \fBIEEE STANDARD 754 Floating\-Point Arithmetic:\fR
270 .PP
271 This standard is on its way to becoming more widely adopted
272 than any other design for computer arithmetic.
273 VLSI chips that conform to some version of that standard have been
274 produced by a host of manufacturers, among them ...
275 .nf
276 .ta 0.5i +\w'Intel i8070, i80287'u+6n
277         Intel i8087, i80287     National Semiconductor  32081
278         Motorola 68881  Weitek WTL-1032, ... , -1165
279         Zilog Z8070     Western Electric (AT&T) WE32106.
280 .ta
281 .fi
282 Other implementations range from software, done thoroughly
283 in the Apple Macintosh, through VLSI in the Hewlett\-Packard
284 9000 series, to the ELXSI 6400 running ECL at 3 Megaflops.
285 Several other companies have adopted the formats
286 of IEEE 754 without, alas, adhering to the standard's way
287 of handling rounding and exceptions like over/underflow.
288 The DEC VAX G_floating\-point format is very similar to the IEEE
289 754 Double format, so similar that the C programs for the
290 IEEE versions of most of the elementary functions listed
291 above could easily be converted to run on a MicroVAX, though
292 nobody has volunteered to do that yet.
293 .PP
294 The codes in 4.3 BSD's \fIlibm\fR for machines that conform to
295 IEEE 754 are intended primarily for the National Semi. 32081
296 and WTL 1164/65.  To use these codes with the Intel or Zilog
297 chips, or with the Apple Macintosh or ELXSI 6400, is to
298 forego the use of better codes provided (perhaps freely) by
299 those companies and designed by some of the authors of the
300 codes above.
301 Except for \fIatan\fR, \fIcabs\fR, \fIcbrt\fR, \fIerf\fR,
302 \fIerfc\fR, \fIhypot\fR, \fIj0\-jn\fR, \fIlgamma\fR, \fIpow\fR
303 and \fIy0\-yn\fR,
304 the Motorola 68881 has all the functions in \fIlibm\fR on chip,
305 and faster and more accurate;
306 it, Apple, the i8087, Z8070 and WE32106 all use 64
307 .if n \
308 sig.
309 .if t \
310 significant
311 bits.
312 The main virtue of 4.3 BSD's
313 \fIlibm\fR codes is that they are intended for the public domain;
314 they may be copied freely provided their provenance is always
315 acknowledged, and provided users assist the authors in their
316 researches by reporting experience with the codes.
317 Therefore no user of UNIX on a machine that conforms to
318 IEEE 754 need use anything worse than the new \fIlibm\fR.
319 .PP
320 Properties of IEEE 754 Double\-Precision:
321 .RS
322 Wordsize: 64 bits, 8 bytes.  Radix: Binary.
323 .br
324 Precision: 53
325 .if n \
326 sig.
327 .if t \
328 significant
329 bits, roughly like 16
330 .if n \
331 sig.
332 .if t \
333 significant
334 decimals.
335 .RS
336 If x and x' are consecutive positive Double\-Precision
337 numbers (they differ by 1 \*(up), then
338 .br
339 1.1e\-16 < 0.5**53 < (x'\-x)/x \(<= 0.5**52 < 2.3e\-16.
340 .RE
341 .nf
342 .ta \w'Range:'u+1n +\w'Underflow threshold'u+1n +\w'= 2.0**1024'u+1n
343 Range:  Overflow threshold      = 2.0**1024     = 1.8e308
344         Underflow threshold     = 0.5**1022     = 2.2e\-308
345 .ta
346 .fi
347 .RS
348 Overflow goes by default to a signed
349 .If "" .
350 .br
351 Underflow is \fIGradual,\fR rounding to the nearest
352 integer multiple of 0.5**1074 = 4.9e\-324.
353 .RE
354 Zero is represented ambiguously as +0 or \-0.
355 .RS
356 Its sign transforms correctly through multiplication or
357 division, and is preserved by addition of zeros
358 with like signs; but x\-x yields +0 for every
359 finite x.  The only operations that reveal zero's
360 sign are division by zero and copysign(x,\(+-0).
361 In particular, comparison (x > y, x \(>= y, etc.)
362 cannot be affected by the sign of zero; but if
363 finite x = y then
364 .If
365 \&= 1/(x\-y)
366 .if n \
367 !=
368 .if t \
369 \(!=
370 \-1/(y\-x) =
371 .If \- .
372 .RE
373 .If
374 is signed.
375 .RS
376 it persists when added to itself
377 or to any finite number.  Its sign transforms
378 correctly through multiplication and division, and
379 .If (finite)/\(+- \0=\0\(+-0
380 (nonzero)/0 =
381 .If \(+- .
382 But
383 .if n \
384 Infinity\-Infinity, Infinity\(**0 and Infinity/Infinity
385 .if t \
386 \(if\-\(if, \(if\(**0 and \(if/\(if
387 are, like 0/0 and sqrt(\-3),
388 invalid operations that produce \*(nn. ...
389 .RE
390 Reserved operands:
391 .RS
392 there are 2**53\-2 of them, all
393 called \*(nn (\fIN\fRot \fIa N\fRumber).
394 Some, called Signaling \*(nns, trap any floating\-point operation
395 performed upon them; they are used to mark missing
396 or uninitialized values, or nonexistent elements
397 of arrays.  The rest are Quiet \*(nns; they are
398 the default results of Invalid Operations, and
399 propagate through subsequent arithmetic operations.
400 If x
401 .if n \
402 !=
403 .if t \
404 \(!=
405 x then x is \*(nn; every other predicate
406 (x > y, x = y, x < y, ...) is FALSE if \*(nn is involved.
407 .br
408 NOTE: Trichotomy is violated by \*(nn.
409 .RS
410 Besides being FALSE, predicates that entail ordered
411 comparison, rather than mere (in)equality,
412 signal Invalid Operation when \*(nn is involved.
413 .RE
414 .RE
415 Rounding:
416 .RS
417 Every algebraic operation (+, \-, \(**, /,
418 .if n \
419 sqrt)
420 .if t \
421 \(sr)
422 is rounded by default to within half an \*(up, and
423 when the rounding error is exactly half an \*(up then
424 the rounded value's least significant bit is zero.
425 This kind of rounding is usually the best kind,
426 sometimes provably so; for instance, for every
427 x = 1.0, 2.0, 3.0, 4.0, ..., 2.0**52, we find
428 (x/3.0)\(**3.0 == x and (x/10.0)\(**10.0 == x and ...
429 despite that both the quotients and the products
430 have been rounded.  Only rounding like IEEE 754
431 can do that.  But no single kind of rounding can be
432 proved best for every circumstance, so IEEE 754
433 provides rounding towards zero or towards
434 .If +
435 or towards
436 .If \-
437 at the programmer's option.  And the
438 same kinds of rounding are specified for
439 Binary\-Decimal Conversions, at least for magnitudes
440 between roughly 1.0e\-10 and 1.0e37.
441 .RE
442 Exceptions:
443 .RS
444 IEEE 754 recognizes five kinds of floating\-point exceptions,
445 listed below in declining order of probable importance.
446 .RS
447 .nf
448 .ta \w'Invalid Operation'u+6n +\w'Gradual Underflow'u+2n
449 Exception       Default Result
450 .sp 0.5
451 Invalid Operation       \*(nn, or FALSE
452 .if n \{\
453 Overflow        \(+-Infinity
454 Divide by Zero  \(+-Infinity \}
455 .if t \{\
456 Overflow        \(+-\(if
457 Divide by Zero  \(+-\(if \}
458 Underflow       Gradual Underflow
459 Inexact Rounded value
460 .ta
461 .fi
462 .RE
463 NOTE:  An Exception is not an Error unless handled
464 badly.  What makes a class of exceptions exceptional
465 is that no single default response can be satisfactory
466 in every instance.  On the other hand, if a default
467 response will serve most instances satisfactorily,
468 the unsatisfactory instances cannot justify aborting
469 computation every time the exception occurs.
470 .RE
471 .PP
472 For each kind of floating\-point exception, IEEE 754
473 provides a Flag that is raised each time its exception
474 is signaled, and stays raised until the program resets
475 it.  Programs may also test, save and restore a flag.
476 Thus, IEEE 754 provides three ways by which programs
477 may cope with exceptions for which the default result
478 might be unsatisfactory:
479 .IP 1) \w'\0\0\0\0'u
480 Test for a condition that might cause an exception
481 later, and branch to avoid the exception.
482 .IP 2) \w'\0\0\0\0'u
483 Test a flag to see whether an exception has occurred
484 since the program last reset its flag.
485 .IP 3) \w'\0\0\0\0'u
486 Test a result to see whether it is a value that only
487 an exception could have produced.
488 .RS
489 CAUTION: The only reliable ways to discover
490 whether Underflow has occurred are to test whether
491 products or quotients lie closer to zero than the
492 underflow threshold, or to test the Underflow
493 flag.  (Sums and differences cannot underflow in
494 IEEE 754; if x
495 .if n \
496 !=
497 .if t \
498 \(!=
499 y then x\-y is correct to
500 full precision and certainly nonzero regardless of
501 how tiny it may be.)  Products and quotients that
502 underflow gradually can lose accuracy gradually
503 without vanishing, so comparing them with zero
504 (as one might on a VAX) will not reveal the loss.
505 Fortunately, if a gradually underflowed value is
506 destined to be added to something bigger than the
507 underflow threshold, as is almost always the case,
508 digits lost to gradual underflow will not be missed
509 because they would have been rounded off anyway.
510 So gradual underflows are usually \fIprovably\fR ignorable.
511 The same cannot be said of underflows flushed to 0.
512 .RE
513 .PP
514 At the option of an implementor conforming to IEEE 754,
515 other ways to cope with exceptions may be provided:
516 .IP 4) \w'\0\0\0\0'u
517 ABORT.  This mechanism classifies an exception in
518 advance as an incident to be handled by means
519 traditionally associated with error\-handling
520 statements like "ON ERROR GO TO ...".  Different
521 languages offer different forms of this statement,
522 but most share the following characteristics:
523 .IP \(em \w'\0\0\0\0'u
524 No means is provided to substitute a value for
525 the offending operation's result and resume
526 computation from what may be the middle of an
527 expression.  An exceptional result is abandoned.
528 .IP \(em \w'\0\0\0\0'u
529 In a subprogram that lacks an error\-handling
530 statement, an exception causes the subprogram to
531 abort within whatever program called it, and so
532 on back up the chain of calling subprograms until
533 an error\-handling statement is encountered or the
534 whole task is aborted and memory is dumped.
535 .IP 5) \w'\0\0\0\0'u
536 STOP.  This mechanism, requiring an interactive
537 debugging environment, is more for the programmer
538 than the program.  It classifies an exception in
539 advance as a symptom of a programmer's error; the
540 exception suspends execution as near as it can to
541 the offending operation so that the programmer can
542 look around to see how it happened.  Quite often
543 the first several exceptions turn out to be quite
544 unexceptionable, so the programmer ought ideally
545 to be able to resume execution after each one as if
546 execution had not been stopped.
547 .IP 6) \w'\0\0\0\0'u
548 \&... Other ways lie beyond the scope of this document.
549 .RE
550 .PP
551 The crucial problem for exception handling is the problem of
552 Scope, and the problem's solution is understood, but not
553 enough manpower was available to implement it fully in time
554 to be distributed in 4.3 BSD's \fIlibm\fR.  Ideally, each
555 elementary function should act as if it were indivisible, or
556 atomic, in the sense that ...
557 .IP i) \w'iii)'u+2n
558 No exception should be signaled that is not deserved by
559 the data supplied to that function.
560 .IP ii) \w'iii)'u+2n
561 Any exception signaled should be identified with that
562 function rather than with one of its subroutines.
563 .IP iii) \w'iii)'u+2n
564 The internal behavior of an atomic function should not
565 be disrupted when a calling program changes from
566 one to another of the five or so ways of handling
567 exceptions listed above, although the definition
568 of the function may be correlated intentionally
569 with exception handling.
570 .PP
571 Ideally, every programmer should be able \fIconveniently\fR to
572 turn a debugged subprogram into one that appears atomic to
573 its users.  But simulating all three characteristics of an
574 atomic function is still a tedious affair, entailing hosts
575 of tests and saves\-restores; work is under way to ameliorate
576 the inconvenience.
577 .PP
578 Meanwhile, the functions in \fIlibm\fR are only approximately
579 atomic.  They signal no inappropriate exception except
580 possibly ...
581 .RS
582 Over/Underflow
583 .RS
584 when a result, if properly computed, might have lain barely within range, and
585 .RE
586 Inexact in \fIcabs\fR, \fIcbrt\fR, \fIhypot\fR, \fIlog10\fR and \fIpow\fR
587 .RS
588 when it happens to be exact, thanks to fortuitous cancellation of errors.
589 .RE
590 .RE
591 Otherwise, ...
592 .RS
593 Invalid Operation is signaled only when
594 .RS
595 any result but \*(nn would probably be misleading.
596 .RE
597 Overflow is signaled only when
598 .RS
599 the exact result would be finite but beyond the overflow threshold.
600 .RE
601 Divide\-by\-Zero is signaled only when
602 .RS
603 a function takes exactly infinite values at finite operands.
604 .RE
605 Underflow is signaled only when
606 .RS
607 the exact result would be nonzero but tinier than the underflow threshold.
608 .RE
609 Inexact is signaled only when
610 .RS
611 greater range or precision would be needed to represent the exact result.
612 .RE
613 .RE
614 .SH BUGS
615 When signals are appropriate, they are emitted by certain
616 operations within the codes, so a subroutine\-trace may be
617 needed to identify the function with its signal in case
618 method 5) above is in use.  And the codes all take the
619 IEEE 754 defaults for granted; this means that a decision to
620 trap all divisions by zero could disrupt a code that would
621 otherwise get correct results despite division by zero.
622 .SH SEE ALSO
623 An explanation of IEEE 754 and its proposed extension p854
624 was published in the IEEE magazine MICRO in August 1984 under
625 the title "A Proposed Radix\- and Word\-length\-independent
626 Standard for Floating\-point Arithmetic" by W. J. Cody et al.
627 The manuals for Pascal, C and BASIC on the Apple Macintosh
628 document the features of IEEE 754 pretty well.
629 Articles in the IEEE magazine COMPUTER vol. 14 no. 3 (Mar.
630 1981), and in the ACM SIGNUM Newsletter Special Issue of
631 Oct. 1979, may be helpful although they pertain to
632 superseded drafts of the standard.