some fixes: representation for 0, and corrected check for overflow

This commit is contained in:
ceriel 1989-08-01 16:34:01 +00:00
parent 2b2698c44c
commit 94a4bbb268
5 changed files with 18 additions and 7 deletions

View file

@ -15,12 +15,14 @@ flt_chk(e)
if (e->flt_exp >= EXT_MAX) {
flt_status = FLT_OVFL;
e->flt_exp = EXT_MAX;
e->m1 = e->m2 = 0;
e->m1 = 0x80000000;
e->m2 = 0;
}
if (e->flt_exp <= EXT_MIN) {
flt_status = FLT_UNFL;
e->flt_exp = 0;
e->m1 = e->m2 = 0;
e->m1 = 0;
e->m2 = 0;
e->flt_sign = 0;
}
}

View file

@ -11,9 +11,14 @@ int
flt_cmp(e1, e2)
register flt_arith *e1, *e2;
{
int sign = e1->flt_sign ? -1 : 1;
int sign;
int tmp;
if (e1->flt_exp == 0 && e1->m1 == 0 && e1->m2 == 0 &&
e2->flt_exp == 0 && e2->m1 == 0 && e2->m2 == 0) {
return 0;
}
sign = e1->flt_sign ? -1 : 1;
if (e1->flt_sign > e2->flt_sign) return -1;
if (e1->flt_sign < e2->flt_sign) return 1;
if (e1->flt_exp < e2->flt_exp) return -sign;

View file

@ -22,7 +22,8 @@ flt_div(e1,e2,e3)
if ((e2->m1 | e2->m2) == 0) {
flt_status = FLT_DIV0;
e3->flt_exp = EXT_MAX;
e3->m1 = e3->m2 = 0L;
e3->m1 = 0x80000000;
e3->m2 = 0L;
return;
}
if ((e1->m1 | e1->m2) == 0) { /* 0 / anything == 0 */

View file

@ -10,8 +10,11 @@
flt_nrm(e)
register flt_arith *e;
{
if ((e->m1 | e->m2) == 0L)
if ((e->m1 | e->m2) == 0L) {
e->flt_exp = 0;
e->flt_sign = 0;
return;
}
/* if top word is zero mov low word */
/* to top word, adjust exponent value */

View file

@ -253,7 +253,7 @@ flt_str2flt(s, e)
while (c = *s++, isdigit(c) || (c == '.' && ! dotseen++)) {
if (c == '.') continue;
digitseen = 1;
if (e->m1 <= 0x7FFFFFFF/5) {
if (e->m1 >= 0 && e->m1 <= 0x7FFFFFFF/5) {
struct flt_mantissa a1;
a1 = e->flt_mantissa;
@ -415,7 +415,7 @@ flt_flt2str(e, buf, bufsize)
if (*s1) *s++ = *s1++;
else *s++ = '0';
}
if ((e->m1 | e->m2) || e->flt_exp == EXT_MIN || e->flt_exp == EXT_MAX) {
if (e->m1 | e->m2) {
--dp ;
}
if (dp != 0) {