From 94a4bbb26867cd663f60b0818fc801ccbcda278a Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 1 Aug 1989 16:34:01 +0000 Subject: [PATCH] some fixes: representation for 0, and corrected check for overflow --- modules/src/flt_arith/flt_chk.c | 6 ++++-- modules/src/flt_arith/flt_cmp.c | 7 ++++++- modules/src/flt_arith/flt_div.c | 3 ++- modules/src/flt_arith/flt_nrm.c | 5 ++++- modules/src/flt_arith/flt_str2fl.c | 4 ++-- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/modules/src/flt_arith/flt_chk.c b/modules/src/flt_arith/flt_chk.c index 2a027d014..1ec3a1671 100644 --- a/modules/src/flt_arith/flt_chk.c +++ b/modules/src/flt_arith/flt_chk.c @@ -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; } } diff --git a/modules/src/flt_arith/flt_cmp.c b/modules/src/flt_arith/flt_cmp.c index fd21a9b40..847c8989e 100644 --- a/modules/src/flt_arith/flt_cmp.c +++ b/modules/src/flt_arith/flt_cmp.c @@ -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; diff --git a/modules/src/flt_arith/flt_div.c b/modules/src/flt_arith/flt_div.c index 82fe7b120..39134bea4 100644 --- a/modules/src/flt_arith/flt_div.c +++ b/modules/src/flt_arith/flt_div.c @@ -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 */ diff --git a/modules/src/flt_arith/flt_nrm.c b/modules/src/flt_arith/flt_nrm.c index 988d8565d..107071a6f 100644 --- a/modules/src/flt_arith/flt_nrm.c +++ b/modules/src/flt_arith/flt_nrm.c @@ -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 */ diff --git a/modules/src/flt_arith/flt_str2fl.c b/modules/src/flt_arith/flt_str2fl.c index bc178a131..9a3b20e25 100644 --- a/modules/src/flt_arith/flt_str2fl.c +++ b/modules/src/flt_arith/flt_str2fl.c @@ -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) { -- 2.34.1