1.\" Copyright (c) 1985, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" %sccs.include.redist.man%
5.\"
6.\"     @(#)infnan.3	8.1 (Berkeley) 06/04/93
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
21At some time in the future, some of the useful properties of
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
30Invalid, Overflow and Divide\-by\-Zero exceptions of the
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
52insulate themselves from future changes.
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
67be replaced by a function with the same name that returns
68some plausible value, assigns an apt value to the global
69variable
70.Va errno ,
71and allows computation to resume.
72Alternatively, the Reserved Operand Fault Handler could be
73changed to respond by returning that plausible value, etc.
74instead of aborting.
75.Pp
76In the table below, the first two columns show various
77exceptions signaled by the
78.Tn IEEE
79standard, and the default
80result it prescribes.  The third column shows what value is
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
93circumstances.  The last two columns offer an alternative;
94they suggest a setting for
95.Va errno
96and a value for a
97revised
98.Fn infnan
99to return.  And a C program to
100implement that suggestion follows.
101.sp 0.5
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
121#include	<math.h>
122#include	<errno.h>
123extern int	errno ;
124double	infnan(iarg)
125int	iarg ;
126{
127	switch(iarg) {
128	case	\0ERANGE:	errno = ERANGE; return(HUGE);
129	case	\-ERANGE:	errno = EDOM;	return(\-HUGE);
130	default:		errno = EDOM;	return(0);
131	}
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 .
155