Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / lib / libm / common_source / infnan.3
1 .\" Copyright (c) 1985, 1991, 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 .\"     @(#)infnan.3    8.1 (Berkeley) 6/4/93
33 .\" $FreeBSD: src/lib/libm/common_source/infnan.3,v 1.4.2.6 2001/12/17 10:08:31 ru Exp $
34 .\" $DragonFly: src/lib/libm/common_source/Attic/infnan.3,v 1.2 2003/06/17 04:26:50 dillon Exp $
35 .\"
36 .Dd June 4, 1993
37 .Dt INFNAN 3
38 .Os
39 .Sh NAME
40 .Nm infnan
41 .Nd signals invalid floating\-point operations on a
42 .Tn VAX
43 (temporary)
44 .Sh LIBRARY
45 .Lb libm
46 .Sh SYNOPSIS
47 .In math.h
48 .Ft double
49 .Fn infnan "int iarg"
50 .Sh DESCRIPTION
51 At some time in the future, some of the useful properties of
52 the Infinities and \*(Nas in the
53 .Tn IEEE
54 standard 754 for Binary
55 Floating\-Point Arithmetic will be simulated in
56 .Tn UNIX
57 on the
58 .Tn DEC VAX
59 by using its Reserved Operands.  Meanwhile, the
60 Invalid, Overflow and Divide\-by\-Zero exceptions of the
61 .Tn IEEE
62 standard are being approximated on a
63 .Tn VAX
64 by calls to a
65 procedure
66 .Fn infnan
67 in appropriate places in
68 .Xr libm 3 .
69 When
70 better exception\-handling is implemented in
71 .Tn UNIX ,
72 only
73 .Fn infnan
74 among the codes in
75 .Xr libm
76 will have to be changed.
77 And users of
78 .Xr libm
79 can design their own
80 .Fn infnan
81 now to
82 insulate themselves from future changes.
83 .Pp
84 Whenever an elementary function code in
85 .Xr libm
86 has to
87 simulate one of the aforementioned
88 .Tn IEEE
89 exceptions, it calls
90 .Fn infnan iarg
91 with an appropriate value of
92 .Fa iarg .
93 Then a
94 reserved operand fault stops computation.  But
95 .Fn infnan
96 could
97 be replaced by a function with the same name that returns
98 some plausible value, assigns an apt value to the global
99 variable
100 .Va errno ,
101 and allows computation to resume.
102 Alternatively, the Reserved Operand Fault Handler could be
103 changed to respond by returning that plausible value, etc.\&
104 instead of aborting.
105 .Pp
106 In the table below, the first two columns show various
107 exceptions signaled by the
108 .Tn IEEE
109 standard, and the default
110 result it prescribes.  The third column shows what value is
111 given to
112 .Fa iarg
113 by functions in
114 .Xr libm
115 when they
116 invoke
117 .Fn infnan iarg
118 under analogous circumstances on a
119 .Tn VAX .
120 Currently
121 .Fn infnan
122 stops computation under all those
123 circumstances.  The last two columns offer an alternative;
124 they suggest a setting for
125 .Va errno
126 and a value for a
127 revised
128 .Fn infnan
129 to return.  And a C program to
130 implement that suggestion follows.
131 .Bl -column "IEEE Signal" "IEEE Default" XXERANGE ERANGEXXorXXEDOM
132 .It "IEEE Signal        IEEE Default    " Fa iarg Ta Va errno Ta Fn infnan
133 .It "Invalid    \*(Na   " Er "EDOM      EDOM    0"
134 .It "Overflow   \(+-\*(If       " Er "ERANGE    ERANGE" Ta Dv HUGE
135 .It "Div\-by\-0 \(+-Infinity    " Er "\(+-ERANGE        ERANGE or EDOM" Ta Dv \(+-HUGE
136 .El
137 .Bd -ragged -offset center -compact
138 .Dv ( HUGE
139 = 1.7e38 ... nearly 2.0**127)
140 .Ed
141 .Pp
142 ALTERNATIVE
143 .Fn infnan :
144 .Bd -literal -offset indent
145 #include        <math.h>
146 #include        <errno.h>
147 extern int      errno ;
148 double  infnan(iarg)
149 int     iarg ;
150 {
151         switch(iarg) {
152         case    \0ERANGE:       errno = ERANGE; return(HUGE);
153         case    \-ERANGE:       errno = EDOM;   return(\-HUGE);
154         default:                errno = EDOM;   return(0);
155         }
156 }
157 .Ed
158 .Sh SEE ALSO
159 .Xr intro 2 ,
160 .Xr math 3 ,
161 .Xr signal 3
162 .Pp
163 .Er ERANGE
164 and
165 .Er EDOM
166 are defined in
167 .Aq Pa errno.h .
168 (See
169 .Xr intro 2
170 for explanation of
171 .Er EDOM
172 and
173 .Er ERANGE . )
174 .Sh HISTORY
175 The
176 .Fn infnan
177 function appeared in
178 .Bx 4.3 .