4.4BSD snapshot (revision 8.1); add 1993 to copyright
[unix-history] / usr / src / lib / libm / common_source / infnan.3
CommitLineData
c3d39550
KB
1.\" Copyright (c) 1985, 1991, 1993
2.\" The Regents of the University of California. All rights reserved.
f9628029 3.\"
ae59e04c 4.\" %sccs.include.redist.man%
f9628029 5.\"
c3d39550 6.\" @(#)infnan.3 8.1 (Berkeley) %G%
ae59e04c
CL
7.\"
8.Dd
9.Dt INFNAN 3
10.Os BSD 4.3
11.Sh NAME
12.Nm infnan
13.Nd signals invalid floating\-point operations on a
14.Tn VAX
15(temporary)
16.Sh SYNOPSIS
17.Fd #include <math.h>
18.Ft double
19.Fn infnan "int iarg"
20.Sh DESCRIPTION
bacd7cb7 21At some time in the future, some of the useful properties of
ae59e04c
CL
22the Infinities and \*(Nas in the
23.Tn IEEE
24standard 754 for Binary
25Floating\-Point Arithmetic will be simulated in
26.Tn UNIX
27on the
28.Tn DEC VAX
29by using its Reserved Operands. Meanwhile, the
bacd7cb7 30Invalid, Overflow and Divide\-by\-Zero exceptions of the
ae59e04c
CL
31.Tn IEEE
32standard are being approximated on a
33.Tn VAX
34by calls to a
35procedure
36.Fn infnan
37in appropriate places in
38.Xr libm 3 .
39When
40better exception\-handling is implemented in
41.Tn UNIX ,
42only
43.Fn infnan
44among the codes in
45.Xr libm
46will have to be changed.
47And users of
48.Xr libm
49can design their own
50.Fn infnan
51now to
bacd7cb7 52insulate themselves from future changes.
ae59e04c
CL
53.Pp
54Whenever an elementary function code in
55.Xr libm
56has to
57simulate one of the aforementioned
58.Tn IEEE
59exceptions, it calls
60.Fn infnan iarg
61with an appropriate value of
62.Fa iarg .
63Then a
64reserved operand fault stops computation. But
65.Fn infnan
66could
bacd7cb7
MAN
67be replaced by a function with the same name that returns
68some plausible value, assigns an apt value to the global
ae59e04c
CL
69variable
70.Va errno ,
71and allows computation to resume.
bacd7cb7 72Alternatively, the Reserved Operand Fault Handler could be
875ee27b 73changed to respond by returning that plausible value, etc.
bacd7cb7 74instead of aborting.
ae59e04c 75.Pp
bacd7cb7 76In the table below, the first two columns show various
ae59e04c
CL
77exceptions signaled by the
78.Tn IEEE
79standard, and the default
bacd7cb7 80result it prescribes. The third column shows what value is
ae59e04c
CL
81given to
82.Fa iarg
83by functions in
84.Xr libm
85when they
86invoke
87.Fn infnan iarg
88under analogous circumstances on a
89.Tn VAX .
90Currently
91.Fn infnan
92stops computation under all those
bacd7cb7 93circumstances. The last two columns offer an alternative;
ae59e04c
CL
94they suggest a setting for
95.Va errno
96and a value for a
97revised
98.Fn infnan
99to return. And a C program to
bacd7cb7
MAN
100implement that suggestion follows.
101.sp 0.5
ae59e04c
CL
102.Bd -filled -offset indent
103.Bl -column "IEEE Signal" "IEEE Default" XXERANGE ERANGEXXorXXEDOM
104.It IEEE Signal IEEE Default Ta
105.Fa iarg Ta
106.Va errno Ta
107.Fn infnan
108.It Invalid \*(Na Ta
109.Dv EDOM EDOM 0
110.It Overflow \(+-\*(If Ta
111.Dv ERANGE ERANGE HUGE
112.It Div\-by\-0 \(+-Infinity Ta
113.Dv \(+-ERANGE ERANGE or EDOM \(+-HUGE
114.It ( Ns Dv HUGE No "= 1.7e38 ... nearly 2.0**127)"
115.El
116.Ed
117.Pp
118ALTERNATIVE
119.Fn infnan :
120.Bd -literal -offset indent
bacd7cb7
MAN
121#include <math.h>
122#include <errno.h>
123extern int errno ;
124double infnan(iarg)
125int iarg ;
126{
127 switch(iarg) {
ae59e04c 128 case \0ERANGE: errno = ERANGE; return(HUGE);
bacd7cb7
MAN
129 case \-ERANGE: errno = EDOM; return(\-HUGE);
130 default: errno = EDOM; return(0);
131 }
ae59e04c
CL
132}
133.Ed
134.Sh SEE ALSO
135.Xr math 3 ,
136.Xr intro 2 ,
137.Xr signal 3 .
138.Pp
139.Dv ERANGE
140and
141.Dv EDOM
142are defined in
143.Aq Pa errno.h .
144(See
145.Xr intro 2
146for explanation of
147.Dv EDOM
148and
149.Dv ERANGE . )
150.Sh HISTORY
151The
152.Fn infnan
153function appeared in
154.Bx 4.3 .