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