ADD STRTOD TO LIBC WHILE FIXING ATOF FP TRAP.
authorJörg Wunsch <joerg_wunsch@uriah.heep.sax.de>
Mon, 1 Mar 1993 00:00:00 +0000 (00:00 +0000)
committerJörg Wunsch <joerg_wunsch@uriah.heep.sax.de>
Mon, 1 Mar 1993 00:00:00 +0000 (00:00 +0000)
This version of atof checks for overflow conditions, rather
than simply causing a SIGFP.  It also takes advantage of the overlap
between atof() and strtod() functionality to finally implement the
long-missing strtod in libc (yay!).  Also adjusts awk's config.h to
live with this new fact.

[ Editor's note: ]

ALSO BE SURE TO READ THE TOP LEVEL README FILE FOR THE PATCH KIT.
There are important instructions on how to properly build things
after installing this patch.  If you do not do so, this patch will
not do anything for you.

AUTHOR: Joerg Wunsch
386BSD-Patchkit: patch00089

usr/src/lib/libc/i386/stdlib/atof.c
usr/src/usr.bin/awk/config.h

index 4dcc7f7..70f1c7e 100644 (file)
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * PATCHES MAGIC                LEVEL   PATCH THAT GOT US HERE
+ * --------------------         -----   ----------------------
+ * CURRENT PATCH LEVEL:         1       00089
+ * --------------------         -----   ----------------------
+ *
+ * 27 Feb 93    Joerg Wunsch   Implement strtod, fix atof.
+ *
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
@@ -47,6 +55,8 @@ static char sccsid[] = "@(#)atof.c    5.2 (Berkeley) 4/12/91";
 #include <stdlib.h>
 #include <math.h>
 #include <ctype.h>
 #include <stdlib.h>
 #include <math.h>
 #include <ctype.h>
+#include <errno.h>
+#include <stdio.h>
 
 static double twoemax = 9007199254740992.;     /*2^53*/
 
 
 static double twoemax = 9007199254740992.;     /*2^53*/
 
@@ -79,8 +89,9 @@ static struct {
 };
 
 double
 };
 
 double
-atof(p)
+strtod(p, endp)
        register const char *p;
        register const char *p;
+       char **endp;
 {
        register int c;
        register int exp = 0;
 {
        register int c;
        register int exp = 0;
@@ -90,6 +101,7 @@ atof(p)
        int bexp;
        int neg = 1;
        int negexp = 1;
        int bexp;
        int neg = 1;
        int negexp = 1;
+       const char *oldp = p;
 
        while (isspace(*p))
                ++p;
 
        while (isspace(*p))
                ++p;
@@ -138,6 +150,14 @@ atof(p)
                exp >>= 1;
        }
 
                exp >>= 1;
        }
 
+       /* according to ANSI, check for over-/underflow */
+       if(exp > 0) {
+               if(endp)
+                       *endp = oldp;
+               errno = ERANGE;
+               return neg < 0? -HUGE_VAL: HUGE_VAL;
+       }
+
        if (bexp < 0)
                fl /= flexp;
        else
        if (bexp < 0)
                fl /= flexp;
        else
@@ -145,5 +165,16 @@ atof(p)
 
        fl = ldexp(fl, bexp);
 
 
        fl = ldexp(fl, bexp);
 
+       if(endp)
+               *endp = p;
        return neg < 0 ? -fl : fl;
 }
        return neg < 0 ? -fl : fl;
 }
+
+
+double
+atof(p)
+       const char *p;
+{
+       return strtod(p, (char **)NULL);
+}
+
index 0623876..223dd22 100644 (file)
@@ -30,7 +30,15 @@ the GNU General Public License, version 2, 1991.
  * Revision 3.1  91/06/07  10:39:33  brennan
  * VERSION 0.995
  * 
  * Revision 3.1  91/06/07  10:39:33  brennan
  * VERSION 0.995
  * 
-*/
+ *
+ * PATCHES MAGIC                LEVEL   PATCH THAT GOT US HERE
+ * --------------------         -----   ----------------------
+ * CURRENT PATCH LEVEL:         1       00089
+ * --------------------         -----   ----------------------
+ *
+ * 01 Mar 93    Chris Demetriou                Adjust to life with strtod in libc
+ *
+ */
 
 /* BSD UNIX on 386BSD */
 
 
 /* BSD UNIX on 386BSD */
 
@@ -43,7 +51,7 @@ the GNU General Public License, version 2, 1991.
 #define   FPE_ZERODIVIDE   FPE_FLTDIV_FAULT
 #define   FPE_OVERFLOW     FPE_FLTOVF_FAULT
 
 #define   FPE_ZERODIVIDE   FPE_FLTDIV_FAULT
 #define   FPE_OVERFLOW     FPE_FLTOVF_FAULT
 
-#define   HAVE_STRTOD          0
+#define   HAVE_STRTOD          1
 #define   HAVE_MATHERR         0
 
 #define   HAVE_FMOD            1
 #define   HAVE_MATHERR         0
 
 #define   HAVE_FMOD            1