2 /********************************************
4 copyright 1991, Michael D. Brennan
6 This is a source file for mawk, an implementation of
7 the AWK programming language.
9 Mawk is distributed without warranty under the terms of
10 the GNU General Public License, version 2, 1991.
11 ********************************************/
14 *Revision 1.9 1996/09/01 16:54:35 mike
15 *Third try at bug fix for solaris strtod.
17 * Revision 1.6 1994/12/18 20:53:43 mike
18 * check NetBSD mathlib defines
20 * Revision 1.5 1994/12/14 14:48:57 mike
21 * add <siginfo.h> include -- sysV doesn't have it inside <signal.h>
22 * restore #else that had been removed
24 * Revision 1.4 1994/10/11 00:36:17 mike
27 * Revision 1.3 1993/07/17 13:23:04 mike
28 * indent and general code cleanup
30 * Revision 1.2 1993/07/04 12:52:03 mike
31 * start on autoconfig changes
33 * Revision 5.2 1992/03/31 16:14:44 brennan
35 * TURN_ON_FPE_TRAPS() macro
38 * Revision 5.1 91/12/05 07:56:18 brennan
46 /* Sets up NetBSD 1.0A for ieee floating point */
47 #if defined(_LIB_VERSION_TYPE) && defined(_LIB_VERSION) && defined(_IEEE_)
48 _LIB_VERSION_TYPE _LIB_VERSION = _IEEE_;
53 #ifdef HAVE_STRTOD_OVF_BUG
54 static fp_except entry_mask ;
55 static fp_except working_mask ;
59 #ifndef TURN_OFF_FPE_TRAPS
60 #define TURN_OFF_FPE_TRAPS() /* nothing */
63 #ifndef TURN_ON_FPE_TRAPS
64 #define TURN_ON_FPE_TRAPS() /* nothing */
69 #define FPE_ZERODIVIDE FPE_FLTDIV
70 #define FPE_OVERFLOW FPE_FLTOVF
76 /* machine dependent changes might be needed here */
80 fpe_catch(signal, sip)
84 int why = sip->si_code ;
89 fpe_catch(signal, why)
92 #endif /* SV_SIGINFO */
95 rt_error("floating point exception, probably overflow") ;
102 rt_error("division by zero") ;
105 rt_error("floating point overflow") ;
108 rt_error("floating point exception") ;
110 #endif /* noinfo_sigfpe */
116 TURN_ON_FPE_TRAPS() ;
119 signal(SIGFPE, fpe_catch) ;
122 { struct sigaction x ;
124 memset(&x, 0, sizeof(x)) ;
125 x.sa_handler = fpe_catch ;
126 x.sa_flags = SA_SIGINFO ;
128 sigaction(SIGFPE, &x, (struct sigaction*)0) ;
132 #ifdef HAVE_STRTOD_OVF_BUG
133 /* we've already turned the traps on */
134 working_mask = fpgetmask() ;
135 entry_mask = working_mask & ~FP_X_DZ & ~FP_X_OFL ;
139 #else /* FPE_TRAPS not defined */
144 TURN_OFF_FPE_TRAPS() ;
152 /* If we are not trapping math errors, we will shutup the library calls
157 struct exception *e ;
162 #else /* print error message and exit */
166 struct exception *e ;
174 error = "domain error" ;
183 error = "loss of significance" ;
188 return 1 ; /* ignore it */
191 if (strcmp(e->name, "atan2") == 0) rt_error("atan2(%g,%g) : %s",
192 e->arg1, e->arg2, error) ;
193 else rt_error("%s(%g) : %s", e->name, e->arg1, error) ;
198 #endif /* FPE_TRAPS_ON */
200 #endif /* ! no matherr */
203 /* this is how one gets the libm calls to do the right
216 case ERANGE : errno = ERANGE ; return HUGE ;
217 case -ERANGE : errno = EDOM ; return -HUGE ;
224 #endif /* BSD43_VAX */
226 /* This routine is for XENIX-68K 2.3A.
227 Error check routine to be called after fp arithmetic.
231 /* Definitions of bit values in iserr() return value */
242 register int fperrval ;
245 if ((fperrval = iserr()) == 0)
246 return ; /* no error */
248 errdesc = (char *) 0 ;
250 if (fperrval & INFNAN) errdesc = "arg is infinity or NAN" ;
251 else if (fperrval & ZERODIV) errdesc = "division by zero" ;
252 else if (fperrval & OVFLOW) errdesc = "overflow" ;
253 else if (fperrval & UFLOW) ; /* ignored */
255 if (errdesc) rt_error("%s", errdesc) ;
260 #ifdef HAVE_STRTOD_OVF_BUG
261 /* buggy strtod in solaris, probably any sysv with ieee754
262 strtod can generate an fpe */
265 strtod_with_ovf_bug(s, ep)
271 fpsetmask(entry_mask) ; /* traps off */
272 #undef strtod /* make real strtod visible */
273 ret = strtod(s, ep) ;
274 fpsetmask(working_mask) ; /* traps on */