xref: /dragonfly/contrib/openbsd_libm/man/infnan.3 (revision 335b9e93)
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
43At some time in the future, some of the useful properties of
44the Infinities and \*(Nas in the IEEE standard 754
45for Binary Floating\-Point Arithmetic will be simulated in UNIX
46on the DEC VAX by using its Reserved Operands.
47Meanwhile, the Invalid, Overflow and Divide\-by\-Zero exceptions of the
48IEEE standard are being approximated on a VAX by calls to a procedure
49.Fn infnan
50in appropriate places in
51.Em libm .
52When better exception\-handling is implemented in UNIX, only
53.Fn infnan
54among the codes in
55.Em libm
56will have to be changed.
57And users of
58.Em libm
59can design their own
60.Fn infnan
61now to
62insulate themselves from future changes.
63.Pp
64Whenever an elementary function code in
65.Em libm
66has to
67simulate one of the aforementioned IEEE exceptions, it calls
68.Fn infnan iarg
69with an appropriate value of
70.Fa iarg .
71Then a
72reserved operand fault stops computation.
73But
74.Fn infnan
75could
76be replaced by a function with the same name that returns
77some plausible value, assigns an apt value to the global
78variable
79.Va errno ,
80and allows computation to resume.
81Alternatively, the Reserved Operand Fault Handler could be
82changed to respond by returning that plausible value, etc.,
83instead of aborting.
84.Pp
85In the table below, the first two columns show various exceptions
86signaled by the IEEE standard, and the default result it prescribes.
87The third column shows what value is given to
88.Fa iarg
89by functions in
90.Em libm
91when they
92invoke
93.Fn infnan iarg
94under analogous circumstances on a VAX.
95Currently
96.Fn infnan
97stops computation under all those
98circumstances.
99The last two columns offer an alternative;
100they suggest a setting for
101.Va errno
102and a value for a
103revised
104.Fn infnan
105to return.
106And 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
116ALTERNATIVE
117.Fn infnan :
118.Bd -literal -offset indent
119#include <math.h>
120#include <errno.h>
121
122double
123infnan(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
142The
143.Fn infnan
144function appeared in
145.Bx 4.3 .
146