2 /* This code attempts to figure out what the default
3 floating point exception handling does.
6 /* $Log: fpe_check.c,v $
7 * Revision 1.7 1996/08/30 00:07:14 mike
8 * Modifications to the test and implementation of the bug fix for
9 * solaris overflow in strtod.
11 * Revision 1.6 1996/08/25 19:25:46 mike
12 * Added test for solaris strtod overflow bug.
14 * Revision 1.5 1996/08/11 22:10:39 mike
15 * Some systems blow the !(d==d) test for a NAN. Added a work around.
17 * Revision 1.4 1995/01/09 01:22:28 mike
18 * check sig handler ret type to make fpe_check.c more robust
20 * Revision 1.3 1994/12/18 20:54:00 mike
21 * check NetBSD mathlib defines
23 * Revision 1.2 1994/12/14 14:37:26 mike
24 * add messages to user
32 /* Sets up NetBSD 1.0A for ieee floating point */
33 #if defined(_LIB_VERSION_TYPE) && defined(_LIB_VERSION) && defined(_IEEE_)
34 _LIB_VERSION_TYPE _LIB_VERSION = _IEEE_;
44 int may_be_safe_to_look_at_why = 0 ;
46 int checking_for_strtod_ovf_bug = 0 ;
48 RETSIGTYPE fpe_catch() ;
50 void check_strtod_ovf() ;
75 void check_fpe_traps()
79 if (setjmp(jbuff) == 0)
82 message("division by zero does not generate an exception") ;
87 message("division by zero generates an exception") ;
88 signal(SIGFPE, fpe_catch) ; /* set again if sysV */
91 if ( setjmp(jbuff) == 0 )
94 message("overflow does not generate an exception") ;
99 message("overflow generates an exception") ;
100 signal(SIGFPE, fpe_catch) ;
105 double maybe_nan = log(-8.0) ;
107 if (is_nan(maybe_nan))
109 message("math library supports ieee754") ;
114 message("math library does not support ieee754") ;
126 if (!(d==d)) return 1 ;
128 /* on some systems with an ieee754 bug, we need to make another check */
130 "echo '%f' | egrep '[nN][aA][nN]|\\?' >/dev/null", d) ;
131 return system(command)==0 ;
135 Only get here if we think we have Berkeley type signals so we can
136 look at a second argument to fpe_catch() to get the reason for
145 may_be_safe_to_look_at_why = 1 ;
147 if( setjmp(jbuff) == 0 ) div_by(1000.0, 0.0) ;
151 signal(SIGFPE, fpe_catch) ;
154 if( setjmp(jbuff) == 0 ) overflow(1000.0) ;
158 signal(SIGFPE, fpe_catch) ;
162 /* make some guesses if sane values */
163 if ( divz>0 && ovf>0 && divz != ovf )
165 printf("X FPE_ZERODIVIDE %d\n", divz) ;
166 printf("X FPE_OVERFLOW %d\n", ovf) ;
177 signal(SIGFPE, fpe_catch) ;
193 /* put this down here in attempt to defeat ambitious compiler that
194 may have seen a prototype without 2nd argument */
196 RETSIGTYPE fpe_catch(signal, why)
200 if (checking_for_strtod_ovf_bug) exit(1) ;
201 if ( may_be_safe_to_look_at_why ) why_v = why ;
257 fpsetmask(fpgetmask()|FP_X_OFL|FP_X_DZ) ;
260 checking_for_strtod_ovf_bug = 1 ;
261 strtod(longstr,(char**)0) ;