Return to BSD News archive
Newsgroups: comp.os.386bsd.bugs Path: sserve!manuel.anu.edu.au!munnari.oz.au!spool.mu.edu!uunet!email!mbirgmei From: mbirgmei@email.tuwien.ac.at (Martin BIRGMEIER) Subject: HUGE_VAL Message-ID: <1993Mar9.084812.12168@email.tuwien.ac.at> Organization: Technical University of Vienna Date: Tue, 9 Mar 1993 08:48:12 GMT Lines: 130 The patch for strtod() and atof() in the latest patchkit is nice, but it won't compile: cc aborts upon reaching the HUGE_VAL statement. This is somewhat clear to me: HUGE_VAL by definition is not a legal floating point value; thus it can only be scanned by a routine which knows what to return for numbers which are too large to be represented as a double: This routine then should return HUGE_VAL. But here we have a circular dependency: We want to compile strtod() such that it can return HUGE_VAL for numbers which are too large; but on the other hand we want to scan a decimal representation for HUGE_VAL with a scanner which still depends on the old strtod() (or atof() for that matter) which can't handle it. The solution of course is to cleanly break this cycle. What I have done is simply created a procedure which returns `positive infinity' when called, and made HUGE_VAL a macro calling this procedure. Patches follow below and seem to work quite nicely (I hope :-)). Three remarks: 1e500 in the original math.h is just fine as long as strtod() can already handle it (which makes me strongly suspicious of patch00086 in the latest patchkit - patching HUGE_VAL to be scannable by the old scanner just means that it is not HUGE_VAL any more); Also, please don't complain that I did not make the constant array `plus_infinity' depend on the machine architecture and endianness and whatever... it's in i386/stdlib, that should be enough. Finally, regarding speed - well, that's up to you :-). ============================== cut here ============================== *** /usr/src/lib/libc/stdlib/Makefile.inc.INFINITY_ORIG Sun May 24 20:33:29 1992 --- /usr/src/lib/libc/stdlib/Makefile.inc Tue Mar 9 08:32:37 1993 *************** *** 11,17 **** .if (${MACHINE} == "hp300") SRCS+= abs.s atof.c .elif (${MACHINE} == "i386") ! SRCS+= abs.s atof.c .elif (${MACHINE} == "tahoe") SRCS+= abs.s atof.s .elif (${MACHINE} == "vax") --- 11,17 ---- .if (${MACHINE} == "hp300") SRCS+= abs.s atof.c .elif (${MACHINE} == "i386") ! SRCS+= abs.s atof.c _plus_infinity.c .elif (${MACHINE} == "tahoe") SRCS+= abs.s atof.s .elif (${MACHINE} == "vax") *** /usr/src/lib/libc/i386/stdlib/_plus_infinity.c.INFINITY_ORIG Mon Mar 8 18:17:02 1993 --- /usr/src/lib/libc/i386/stdlib/_plus_infinity.c Tue Mar 9 08:28:15 1993 *************** *** 0 **** --- 1,14 ---- + /* + * @(#) _plus_infinity.c V1.0 MB March 8 1993 + */ + + /* + * _plus_infinity() - + * return what's commonly called HUGE_VAL + */ + + double _plus_infinity() { + static char plus_infinity[10] = + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x7f }; + return * ((double *) plus_infinity); + } *** /usr/src/include/math.h.INFINITY_ORIG Tue Mar 9 08:34:58 1993 --- /usr/src/include/math.h Tue Mar 9 09:29:41 1993 *************** *** 39,46 **** --- 39,50 ---- #if defined(vax) || defined(tahoe) /* DBL_MAX from float.h */ #define HUGE_VAL 1.701411834604692294E+38 #else + #ifdef __386BSD__ + #define HUGE_VAL (_plus_infinity()) + #else #define HUGE_VAL 1e500 /* IEEE: positive infinity */ #endif + #endif #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) #if defined(vax) || defined(tahoe) *************** *** 73,78 **** --- 77,83 ---- #include <sys/cdefs.h> __BEGIN_DECLS + double _plus_infinity __P((void)); double acos __P((double)); double asin __P((double)); double atan __P((double)); *** /usr/include/math.h.INFINITY_ORIG Sat Feb 29 01:13:15 1992 --- /usr/include/math.h Tue Mar 9 09:29:48 1993 *************** *** 39,46 **** --- 39,50 ---- #if defined(vax) || defined(tahoe) /* DBL_MAX from float.h */ #define HUGE_VAL 1.701411834604692294E+38 #else + #ifdef __386BSD__ + #define HUGE_VAL (_plus_infinity()) + #else #define HUGE_VAL 1e500 /* IEEE: positive infinity */ #endif + #endif #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) #if defined(vax) || defined(tahoe) *************** *** 73,78 **** --- 77,83 ---- #include <sys/cdefs.h> __BEGIN_DECLS + double _plus_infinity __P((void)); double acos __P((double)); double asin __P((double)); double atan __P((double)); ============================== cut here ============================== Yours, Martin Birgmeier Dept. of Comm. Engr., TU Vienna