From: ceriel Date: Thu, 28 Apr 1988 14:46:11 +0000 (+0000) Subject: be careful about overflow in con_float X-Git-Tag: release-5-5~3303 X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=88acb4c4d98ad701d281dd3cc1a830a9ba64eb50;p=ack.git be careful about overflow in con_float --- diff --git a/mach/m68020/ncg/mach.c b/mach/m68020/ncg/mach.c index 1d5aa9c17..6de151d12 100644 --- a/mach/m68020/ncg/mach.c +++ b/mach/m68020/ncg/mach.c @@ -62,9 +62,9 @@ con_float() { double f; double atof(); int i; -#ifndef OWNFLOAT - double frexp(); int j; + double frexp(); +#ifndef OWNFLOAT int sign = 0; int fraction[4] ; #else OWNFLOAT @@ -78,9 +78,31 @@ con_float() { } fprintf(codefile,"!float %s sz %d\n", str, argval); f = atof(str); + if (f == 0) { + if (argval == 8) fprintf(codefile, ".data2 0, 0\n"); + fprintf(codefile, ".data2 0, 0\n"); + return; + } #ifdef OWNFLOAT if (argval == 4) { + /* careful: avoid overflow */ + double ldexp(); + f = frexp(f, &i); fl = f; + fl = frexp(fl,&j); + if (i+j > 127) { + /* overflow situation */ + fprintf(codefile, ".data1 0%o, 0377, 0377, 0377 ! overflow\n", + f < 0 ? 0377 : 0177); + return; + } + if (i+j < -127) { + /* underflow situation */ + fprintf(codefile, ".data1 0%o, 0200, 0, 0 ! underflow\n", + f < 0 ? 0200 : 0); + return; + } + fl = ldexp(fl, i+j); p = (char *) &fl; } else { @@ -91,11 +113,6 @@ con_float() { fprintf(codefile,",0%o", *p++ & 0377); } #else OWNFLOAT - if (f == 0) { - if (argval == 8) fprintf(codefile, ".data2 0, 0\n"); - fprintf(codefile, ".data2 0, 0\n"); - return; - } f = frexp(f, &i); if (f < 0) { f = -f; diff --git a/mach/m68k2/ncg/mach.c b/mach/m68k2/ncg/mach.c index 1d5aa9c17..6de151d12 100644 --- a/mach/m68k2/ncg/mach.c +++ b/mach/m68k2/ncg/mach.c @@ -62,9 +62,9 @@ con_float() { double f; double atof(); int i; -#ifndef OWNFLOAT - double frexp(); int j; + double frexp(); +#ifndef OWNFLOAT int sign = 0; int fraction[4] ; #else OWNFLOAT @@ -78,9 +78,31 @@ con_float() { } fprintf(codefile,"!float %s sz %d\n", str, argval); f = atof(str); + if (f == 0) { + if (argval == 8) fprintf(codefile, ".data2 0, 0\n"); + fprintf(codefile, ".data2 0, 0\n"); + return; + } #ifdef OWNFLOAT if (argval == 4) { + /* careful: avoid overflow */ + double ldexp(); + f = frexp(f, &i); fl = f; + fl = frexp(fl,&j); + if (i+j > 127) { + /* overflow situation */ + fprintf(codefile, ".data1 0%o, 0377, 0377, 0377 ! overflow\n", + f < 0 ? 0377 : 0177); + return; + } + if (i+j < -127) { + /* underflow situation */ + fprintf(codefile, ".data1 0%o, 0200, 0, 0 ! underflow\n", + f < 0 ? 0200 : 0); + return; + } + fl = ldexp(fl, i+j); p = (char *) &fl; } else { @@ -91,11 +113,6 @@ con_float() { fprintf(codefile,",0%o", *p++ & 0377); } #else OWNFLOAT - if (f == 0) { - if (argval == 8) fprintf(codefile, ".data2 0, 0\n"); - fprintf(codefile, ".data2 0, 0\n"); - return; - } f = frexp(f, &i); if (f < 0) { f = -f; diff --git a/mach/m68k4/ncg/mach.c b/mach/m68k4/ncg/mach.c index 1d5aa9c17..6de151d12 100644 --- a/mach/m68k4/ncg/mach.c +++ b/mach/m68k4/ncg/mach.c @@ -62,9 +62,9 @@ con_float() { double f; double atof(); int i; -#ifndef OWNFLOAT - double frexp(); int j; + double frexp(); +#ifndef OWNFLOAT int sign = 0; int fraction[4] ; #else OWNFLOAT @@ -78,9 +78,31 @@ con_float() { } fprintf(codefile,"!float %s sz %d\n", str, argval); f = atof(str); + if (f == 0) { + if (argval == 8) fprintf(codefile, ".data2 0, 0\n"); + fprintf(codefile, ".data2 0, 0\n"); + return; + } #ifdef OWNFLOAT if (argval == 4) { + /* careful: avoid overflow */ + double ldexp(); + f = frexp(f, &i); fl = f; + fl = frexp(fl,&j); + if (i+j > 127) { + /* overflow situation */ + fprintf(codefile, ".data1 0%o, 0377, 0377, 0377 ! overflow\n", + f < 0 ? 0377 : 0177); + return; + } + if (i+j < -127) { + /* underflow situation */ + fprintf(codefile, ".data1 0%o, 0200, 0, 0 ! underflow\n", + f < 0 ? 0200 : 0); + return; + } + fl = ldexp(fl, i+j); p = (char *) &fl; } else { @@ -91,11 +113,6 @@ con_float() { fprintf(codefile,",0%o", *p++ & 0377); } #else OWNFLOAT - if (f == 0) { - if (argval == 8) fprintf(codefile, ".data2 0, 0\n"); - fprintf(codefile, ".data2 0, 0\n"); - return; - } f = frexp(f, &i); if (f < 0) { f = -f; diff --git a/mach/moon3/ncg/mach.c b/mach/moon3/ncg/mach.c index 1d5aa9c17..6de151d12 100644 --- a/mach/moon3/ncg/mach.c +++ b/mach/moon3/ncg/mach.c @@ -62,9 +62,9 @@ con_float() { double f; double atof(); int i; -#ifndef OWNFLOAT - double frexp(); int j; + double frexp(); +#ifndef OWNFLOAT int sign = 0; int fraction[4] ; #else OWNFLOAT @@ -78,9 +78,31 @@ con_float() { } fprintf(codefile,"!float %s sz %d\n", str, argval); f = atof(str); + if (f == 0) { + if (argval == 8) fprintf(codefile, ".data2 0, 0\n"); + fprintf(codefile, ".data2 0, 0\n"); + return; + } #ifdef OWNFLOAT if (argval == 4) { + /* careful: avoid overflow */ + double ldexp(); + f = frexp(f, &i); fl = f; + fl = frexp(fl,&j); + if (i+j > 127) { + /* overflow situation */ + fprintf(codefile, ".data1 0%o, 0377, 0377, 0377 ! overflow\n", + f < 0 ? 0377 : 0177); + return; + } + if (i+j < -127) { + /* underflow situation */ + fprintf(codefile, ".data1 0%o, 0200, 0, 0 ! underflow\n", + f < 0 ? 0200 : 0); + return; + } + fl = ldexp(fl, i+j); p = (char *) &fl; } else { @@ -91,11 +113,6 @@ con_float() { fprintf(codefile,",0%o", *p++ & 0377); } #else OWNFLOAT - if (f == 0) { - if (argval == 8) fprintf(codefile, ".data2 0, 0\n"); - fprintf(codefile, ".data2 0, 0\n"); - return; - } f = frexp(f, &i); if (f < 0) { f = -f;