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