From 35c612b99bbe9514e18061a1b12eb88d80502231 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 19 Oct 1989 14:50:52 +0000 Subject: [PATCH] some minor improvements --- modules/src/flt_arith/flt_ar2flt.c | 13 ++++++------- modules/src/flt_arith/flt_chk.c | 3 +-- modules/src/flt_arith/flt_cmp.c | 4 ++-- modules/src/flt_arith/flt_div.c | 21 +++++++++++---------- modules/src/flt_arith/flt_str2fl.c | 2 -- 5 files changed, 20 insertions(+), 23 deletions(-) diff --git a/modules/src/flt_arith/flt_ar2flt.c b/modules/src/flt_arith/flt_ar2flt.c index 2582a4b7a..ad1eaecb8 100644 --- a/modules/src/flt_arith/flt_ar2flt.c +++ b/modules/src/flt_arith/flt_ar2flt.c @@ -16,20 +16,19 @@ flt_arith2flt(n, e) */ register int i; - if (n == 0) { - e->flt_exp = 0; - e->flt_sign = 0; - e->m1 = e->m2 = 0; - return; - } if (n < 0) { e->flt_sign = 1; n = -n; } else e->flt_sign = 0; - e->flt_exp = 63; e->m1 = e->m2 = 0; + if (n == 0) { + e->flt_exp = 0; + return; + } + e->flt_exp = 63; if (n < 0) { + /* n = MINARITH */ n = 0x40000000; while ((n << 1) > 0) n <<= 1; e->flt_exp++; diff --git a/modules/src/flt_arith/flt_chk.c b/modules/src/flt_arith/flt_chk.c index 1ec3a1671..e7ddcab99 100644 --- a/modules/src/flt_arith/flt_chk.c +++ b/modules/src/flt_arith/flt_chk.c @@ -16,13 +16,12 @@ flt_chk(e) flt_status = FLT_OVFL; e->flt_exp = EXT_MAX; e->m1 = 0x80000000; - e->m2 = 0; } if (e->flt_exp <= EXT_MIN) { flt_status = FLT_UNFL; e->flt_exp = 0; e->m1 = 0; - e->m2 = 0; e->flt_sign = 0; } + e->m2 = 0; } diff --git a/modules/src/flt_arith/flt_cmp.c b/modules/src/flt_arith/flt_cmp.c index 847c8989e..b78707db2 100644 --- a/modules/src/flt_arith/flt_cmp.c +++ b/modules/src/flt_arith/flt_cmp.c @@ -14,8 +14,8 @@ flt_cmp(e1, e2) 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) { + if (e1->m1 == 0 && e1->m2 == 0 && + e2->m1 == 0 && e2->m2 == 0) { return 0; } sign = e1->flt_sign ? -1 : 1; diff --git a/modules/src/flt_arith/flt_div.c b/modules/src/flt_arith/flt_div.c index 35e3105a8..4e298706b 100644 --- a/modules/src/flt_arith/flt_div.c +++ b/modules/src/flt_arith/flt_div.c @@ -51,6 +51,7 @@ flt_div(e1,e2,e3) */ for (j = 0; j <= 3; j++, u_p++) { long q_est, temp; + long v1 = v[1]; if (j == 2) lp++; if (u_p[0] == 0 && u_p[1] < v[1]) continue; @@ -62,22 +63,22 @@ flt_div(e1,e2,e3) q_est = temp; } else if (temp >= 0) { - q_est = temp / (long)v[1]; + q_est = temp / v1; } else { long rem; - q_est = (0x7FFFFFFF/(long)v[1])+((temp&0x7FFFFFFF)/(long)v[1]); - rem = (0x7FFFFFFF%(long)v[1])+((temp&0x7FFFFFFF)%(long)v[1])+1; - while (rem > (long)v[1]) { + q_est = (0x7FFFFFFF/v1)+((temp&0x7FFFFFFF)/v1); + rem = (0x7FFFFFFF%v1)+((temp&0x7FFFFFFF)%v1)+1; + while (rem > v1) { q_est++; - rem -= v[1]; + rem -= v1; } } - temp -= q_est * (long)v[1]; + temp -= q_est * v1; while (!(temp&0xFFFF0000) && ucmp((long)v[2]*q_est,(temp<<16)+(long)u_p[2]) > 0) { q_est--; - temp += v[1]; + temp += v1; } /* Now, according to Knuth, we have an estimate of the quotient, that is either correct or one too big, but @@ -97,14 +98,14 @@ flt_div(e1,e2,e3) k = (tmp >> 16) & 0xFFFF; } k += borrow; - borrow = u_p[0] < k; + borrow = (long)u_p[0] < k; u_p[0] -= k; if (borrow) { /* So, this does not happen often; the estimate was one too big; correct this */ - *lp |= (j & 1) ? (q_est - 1) : ((q_est-1)<<16); + q_est--; borrow = 0; for (i = maxv; i > 0; i--) { long tmp @@ -115,7 +116,7 @@ flt_div(e1,e2,e3) } u_p[0] += borrow; } - else *lp |= (j & 1) ? q_est : (q_est<<16); + *lp |= (j & 1) ? q_est : (q_est<<16); } } e3->m1 = result[0]; diff --git a/modules/src/flt_arith/flt_str2fl.c b/modules/src/flt_arith/flt_str2fl.c index e3d1fcd24..f6431de4f 100644 --- a/modules/src/flt_arith/flt_str2fl.c +++ b/modules/src/flt_arith/flt_str2fl.c @@ -208,8 +208,6 @@ add_exponent(e, exp) while (divsz >= BIGSZ) { flt_mul(&x, neg ? &r_big_10pow[BIGSZ-1] : &big_10pow[BIGSZ-1],&x); divsz -= BIGSZ-1; - flt_chk(e); - if (flt_status != 0) return; } flt_mul(&x, (neg ? r_big_10pow : big_10pow) + divsz, e); } -- 2.34.1