Import OpenBSD's libm (trunk, 4 July 2015) to a new vendor branch
[dragonfly.git] / contrib / openbsd_libm / man / infnan.3
1 .\"     $OpenBSD: infnan.3,v 1.17 2015/01/15 19:06:31 schwarze Exp $
2 .\"
3 .\" Copyright (c) 1985, 1991, 1993
4 .\"     The Regents of the University of California.  All rights reserved.
5 .\"
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
8 .\" are met:
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\"    notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\"    notice, this list of conditions and the following disclaimer in the
13 .\"    documentation and/or other materials provided with the distribution.
14 .\" 3. Neither the name of the University nor the names of its contributors
15 .\"    may be used to endorse or promote products derived from this software
16 .\"    without specific prior written permission.
17 .\"
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 .\" SUCH DAMAGE.
29 .\"
30 .\"     @(#)infnan.3    8.1 (Berkeley) 6/4/93
31 .\"
32 .Dd $Mdocdate: January 15 2015 $
33 .Dt INFNAN 3 vax
34 .Os
35 .Sh NAME
36 .Nm infnan
37 .Nd signals invalid floating\-point operations on a VAX (temporary)
38 .Sh SYNOPSIS
39 .In math.h
40 .Ft double
41 .Fn infnan "int iarg"
42 .Sh DESCRIPTION
43 At some time in the future, some of the useful properties of
44 the Infinities and \*(Nas in the IEEE standard 754
45 for Binary Floating\-Point Arithmetic will be simulated in UNIX
46 on the DEC VAX by using its Reserved Operands.
47 Meanwhile, the Invalid, Overflow and Divide\-by\-Zero exceptions of the
48 IEEE standard are being approximated on a VAX by calls to a procedure
49 .Fn infnan
50 in appropriate places in
51 .Em libm .
52 When better exception\-handling is implemented in UNIX, only
53 .Fn infnan
54 among the codes in
55 .Em libm
56 will have to be changed.
57 And users of
58 .Em libm
59 can design their own
60 .Fn infnan
61 now to
62 insulate themselves from future changes.
63 .Pp
64 Whenever an elementary function code in
65 .Em libm
66 has to
67 simulate one of the aforementioned IEEE exceptions, it calls
68 .Fn infnan iarg
69 with an appropriate value of
70 .Fa iarg .
71 Then a
72 reserved operand fault stops computation.
73 But
74 .Fn infnan
75 could
76 be replaced by a function with the same name that returns
77 some plausible value, assigns an apt value to the global
78 variable
79 .Va errno ,
80 and allows computation to resume.
81 Alternatively, the Reserved Operand Fault Handler could be
82 changed to respond by returning that plausible value, etc.,
83 instead of aborting.
84 .Pp
85 In the table below, the first two columns show various exceptions
86 signaled by the IEEE standard, and the default result it prescribes.
87 The third column shows what value is given to
88 .Fa iarg
89 by functions in
90 .Em libm
91 when they
92 invoke
93 .Fn infnan iarg
94 under analogous circumstances on a VAX.
95 Currently
96 .Fn infnan
97 stops computation under all those
98 circumstances.
99 The last two columns offer an alternative;
100 they suggest a setting for
101 .Va errno
102 and a value for a
103 revised
104 .Fn infnan
105 to return.
106 And a C program to implement that suggestion follows.
107 .Bl -column "IEEE Signal" "IEEE Default" "+-ERANGE" "ERANGE/EDOM" "infnanXX"
108 .It Sy "IEEE Signal" Ta Sy "IEEE Default" Ta Fa iarg Ta Va errno Ta Fn infnan
109 .It Invalid Ta \*(Na Ta Dv EDOM Ta Dv EDOM Ta 0
110 .It Overflow Ta \(+-\*(If Ta Dv ERANGE Ta Dv ERANGE Ta Dv HUGE
111 .It Div\-by\-0 Ta \(+-\*(If Ta Dv +-ERANGE Ta Dv ERANGE/EDOM Ta Dv +-HUGE
112 .El
113 .Pp
114 .Dl ( Ns Dv HUGE No = 1.7e38 ... nearly  2.0**127)
115 .Pp
116 ALTERNATIVE
117 .Fn infnan :
118 .Bd -literal -offset indent
119 #include <math.h>
120 #include <errno.h>
121
122 double
123 infnan(int iarg)
124 {
125         switch (iarg) {
126         case \0ERANGE:
127                 errno = ERANGE;
128                 return (HUGE);
129         case \-ERANGE:
130                 errno = EDOM;
131                 return (\-HUGE);
132         default:
133                 errno = EDOM;
134                 return (0);
135         }
136 }
137 .Ed
138 .Sh SEE ALSO
139 .Xr intro 2 ,
140 .Xr signal 3
141 .Sh HISTORY
142 The
143 .Fn infnan
144 function appeared in
145 .Bx 4.3 .