simplified a bit

This commit is contained in:
ceriel 1989-10-16 17:56:36 +00:00
parent b821194cbd
commit 82c3158ada
9 changed files with 69 additions and 103 deletions

View file

@ -13,11 +13,11 @@ LIBFLT = libflt.$(LIBSUF)
SRC = b64_add.c flt_ar2flt.c flt_div.c flt_nrm.c b64_sft.c flt_chk.c \ SRC = b64_add.c flt_ar2flt.c flt_div.c flt_nrm.c b64_sft.c flt_chk.c \
flt_flt2ar.c flt_str2fl.c flt_add.c flt_cmp.c flt_mul.c ucmp.c \ flt_flt2ar.c flt_str2fl.c flt_add.c flt_cmp.c flt_mul.c ucmp.c \
flt_modf.c flt_umin.c flt_modf.c flt_umin.c split.c
OBJ = b64_add.$(SUF) flt_ar2flt.$(SUF) flt_div.$(SUF) flt_nrm.$(SUF) \ OBJ = b64_add.$(SUF) flt_ar2flt.$(SUF) flt_div.$(SUF) flt_nrm.$(SUF) \
b64_sft.$(SUF) flt_chk.$(SUF) flt_flt2ar.$(SUF) flt_str2fl.$(SUF) \ b64_sft.$(SUF) flt_chk.$(SUF) flt_flt2ar.$(SUF) flt_str2fl.$(SUF) \
flt_add.$(SUF) flt_cmp.$(SUF) flt_mul.$(SUF) ucmp.$(SUF) \ flt_add.$(SUF) flt_cmp.$(SUF) flt_mul.$(SUF) ucmp.$(SUF) \
flt_modf.$(SUF) flt_umin.$(SUF) flt_modf.$(SUF) flt_umin.$(SUF) split.$(SUF)
.SUFFIXES: .$(SUF) .SUFFIXES: .$(SUF)
.c.$(SUF): .c.$(SUF):
@ -67,3 +67,4 @@ flt_mul.$(SUF): misc.h flt_arith.h
flt_modf.$(SUF): misc.h flt_arith.h flt_modf.$(SUF): misc.h flt_arith.h
flt_umin.$(SUF): misc.h flt_umin.$(SUF): misc.h
ucmp.$(SUF): misc.h flt_arith.h ucmp.$(SUF): misc.h flt_arith.h
split.$(SUF): misc.h flt_arith.h

View file

@ -11,8 +11,7 @@ flt_b64_sft(e,n)
register struct flt_mantissa *e; register struct flt_mantissa *e;
register int n; register int n;
{ {
if (n > 0) { if (n > 63 || n < -63) {
if (n > 63) {
e->flt_l_32 = 0; e->flt_l_32 = 0;
e->flt_h_32 = 0; e->flt_h_32 = 0;
return; return;
@ -31,15 +30,7 @@ flt_b64_sft(e,n)
e->flt_h_32 >>= (n - 1); e->flt_h_32 >>= (n - 1);
} }
} }
return;
}
n = -n; n = -n;
if (n > 0) {
if (n > 63) {
e->flt_l_32 = 0;
e->flt_h_32 = 0;
return;
}
if (n >= 32) { if (n >= 32) {
e->flt_h_32 = e->flt_l_32; e->flt_h_32 = e->flt_l_32;
e->flt_l_32 = 0; e->flt_l_32 = 0;
@ -54,22 +45,3 @@ flt_b64_sft(e,n)
} }
} }
} }
}
flt_b64_lsft(e)
register struct flt_mantissa *e;
{
/* shift left 1 bit */
e->flt_h_32 = (e->flt_h_32 << 1) & 0xFFFFFFFF;
if (e->flt_l_32 & 0x80000000L) e->flt_h_32 |= 1;
e->flt_l_32 = (e->flt_l_32 << 1) & 0xFFFFFFFF;
}
flt_b64_rsft(e)
register struct flt_mantissa *e;
{
/* shift right 1 bit */
e->flt_l_32 = (e->flt_l_32 >> 1) & 0x7FFFFFFF;
if (e->flt_h_32 & 1) e->flt_l_32 |= 0x80000000L;
e->flt_h_32 = (e->flt_h_32 >> 1) & 0x7FFFFFFF;
}

View file

@ -65,7 +65,7 @@ flt_add(e1,e2,e3)
else { else {
*e3 = *e2; *e3 = *e2;
if (flt_b64_add(&e3->flt_mantissa,&e1->flt_mantissa)) {/* addition carry */ if (flt_b64_add(&e3->flt_mantissa,&e1->flt_mantissa)) {/* addition carry */
flt_b64_rsft(&e3->flt_mantissa); flt_b64_sft(&e3->flt_mantissa, 1);
e3->m1 |= 0x80000000L; /* set max bit */ e3->m1 |= 0x80000000L; /* set max bit */
e3->flt_exp++; /* increase the exponent */ e3->flt_exp++; /* increase the exponent */
} }

View file

@ -35,7 +35,7 @@ flt_arith2flt(n, e)
e->flt_exp++; e->flt_exp++;
} }
for (i = 64; i > 0 && n != 0; i--) { for (i = 64; i > 0 && n != 0; i--) {
flt_b64_rsft(&(e->flt_mantissa)); flt_b64_sft(&(e->flt_mantissa),1);
e->m1 |= (n & 1) << 31; e->m1 |= (n & 1) << 31;
n >>= 1; n >>= 1;
} }

View file

@ -35,16 +35,10 @@ flt_div(e1,e2,e3)
e3->flt_exp = e1->flt_exp - e2->flt_exp; e3->flt_exp = e1->flt_exp - e2->flt_exp;
u[4] = (e1->m2 & 1) << 15; u[4] = (e1->m2 & 1) << 15;
flt_b64_rsft(&(e1->flt_mantissa)); flt_b64_sft(&(e1->flt_mantissa),1);
u[0] = (e1->m1 >> 16) & 0xFFFF; flt_split(e1, u);
u[1] = e1->m1 & 0xFFFF;
u[2] = (e1->m2 >> 16) & 0xFFFF;
u[3] = e1->m2 & 0xFFFF;
u[5] = 0; u[6] = 0; u[7] = 0; u[5] = 0; u[6] = 0; u[7] = 0;
v[1] = (e2->m1 >> 16) & 0xFFFF; flt_split(e2, &v[1]);
v[2] = e2->m1 & 0xFFFF;
v[3] = (e2->m2 >> 16) & 0xFFFF;
v[4] = e2->m2 & 0xFFFF;
while (! v[maxv]) maxv--; while (! v[maxv]) maxv--;
result[0] = 0; result[0] = 0;
result[1] = 0; result[1] = 0;
@ -68,20 +62,20 @@ flt_div(e1,e2,e3)
q_est = temp; q_est = temp;
} }
else if (temp >= 0) { else if (temp >= 0) {
q_est = temp / v[1]; q_est = temp / (long)v[1];
} }
else { else {
long rem; long rem;
q_est = (0x7FFFFFFF/v[1])+((temp&0x7FFFFFFF)/v[1]); q_est = (0x7FFFFFFF/(long)v[1])+((temp&0x7FFFFFFF)/(long)v[1]);
rem = (0x7FFFFFFF%v[1])+((temp&0x7FFFFFFF)%v[1])+1; rem = (0x7FFFFFFF%(long)v[1])+((temp&0x7FFFFFFF)%(long)v[1])+1;
while (rem > v[1]) { while (rem > (long)v[1]) {
q_est++; q_est++;
rem -= v[1]; rem -= v[1];
} }
} }
temp -= q_est * v[1]; temp -= q_est * (long)v[1];
while (!(temp&0xFFFF0000) && while (!(temp&0xFFFF0000) &&
ucmp((long)(v[2]*q_est),(long)((temp<<16)+u_p[2])) > 0) { ucmp((long)v[2]*q_est,(temp<<16)+(long)u_p[2]) > 0) {
q_est--; q_est--;
temp += v[1]; temp += v[1];
} }
@ -95,7 +89,7 @@ flt_div(e1,e2,e3)
int borrow = 0; int borrow = 0;
for (i = maxv; i > 0; i--) { for (i = maxv; i > 0; i--) {
long tmp = q_est * v[i] + k + borrow; long tmp = q_est * (long)v[i] + k + borrow;
unsigned short md = tmp & 0xFFFF; unsigned short md = tmp & 0xFFFF;
borrow = (md > u_p[i]); borrow = (md > u_p[i]);

View file

@ -32,14 +32,8 @@ flt_mul(e1,e2,e3)
/* assign unknown long formats */ /* assign unknown long formats */
/* to known unsigned word formats */ /* to known unsigned word formats */
mp[0] = (e1->m1 >> 16) & 0xFFFF; flt_split(e1, mp);
mp[1] = e1->m1 & 0xFFFF; flt_split(e2, mc);
mp[2] = (e1->m2 >> 16) & 0xFFFF;
mp[3] = e1->m2 & 0xFFFF;
mc[0] = (e2->m1 >> 16) & 0xFFFF;
mc[1] = e2->m1 & 0xFFFF;
mc[2] = (e2->m2 >> 16) & 0xFFFF;
mc[3] = e2->m2 & 0xFFFF;
for (i = 8; i--;) { for (i = 8; i--;) {
result[i] = 0; result[i] = 0;
} }

View file

@ -204,26 +204,14 @@ add_exponent(e, exp)
if (neg) exp = -exp; if (neg) exp = -exp;
divsz = exp / SMALLSZ; divsz = exp / SMALLSZ;
modsz = exp % SMALLSZ; modsz = exp % SMALLSZ;
if (neg) { flt_mul(e, (neg ? r_10pow : s10pow) + modsz, &x);
flt_mul(e, &r_10pow[modsz], &x);
while (divsz >= BIGSZ) { while (divsz >= BIGSZ) {
flt_mul(&x, &r_big_10pow[BIGSZ-1],&x); flt_mul(&x, neg ? &r_big_10pow[BIGSZ-1] : &big_10pow[BIGSZ-1],&x);
divsz -= BIGSZ-1; divsz -= BIGSZ-1;
flt_chk(e); flt_chk(e);
if (flt_status != 0) return; if (flt_status != 0) return;
} }
flt_mul(&x, &r_big_10pow[divsz], e); flt_mul(&x, (neg ? r_big_10pow : big_10pow) + divsz, e);
}
else {
flt_mul(e, &s10pow[modsz], &x);
while (divsz >= BIGSZ) {
flt_mul(&x, &big_10pow[BIGSZ-1],&x);
divsz -= BIGSZ-1;
flt_chk(e);
if (flt_status != 0) return;
}
flt_mul(&x, &big_10pow[divsz], e);
}
} }
flt_str2flt(s, e) flt_str2flt(s, e)
@ -258,7 +246,7 @@ flt_str2flt(s, e)
a1 = e->flt_mantissa; a1 = e->flt_mantissa;
flt_b64_sft(&(e->flt_mantissa), -3); flt_b64_sft(&(e->flt_mantissa), -3);
flt_b64_lsft(&a1); flt_b64_sft(&a1, -1);
flt_b64_add(&(e->flt_mantissa), &a1); flt_b64_add(&(e->flt_mantissa), &a1);
a1.flt_h_32 = 0; a1.flt_h_32 = 0;
a1.flt_l_32 = c - '0'; a1.flt_l_32 = c - '0';

View file

@ -19,3 +19,4 @@
#define flt_nrm flt__nrm #define flt_nrm flt__nrm
#define flt_chk flt__chk #define flt_chk flt__chk
#define flt_b64_add flt__64add #define flt_b64_add flt__64add
#define flt_split flt__split

View file

@ -0,0 +1,16 @@
/* $Header$ */
#include "misc.h"
flt_split(e, p)
register flt_arith *e;
register unsigned short *p;
{
/* Split mantissa of e into the array p
*/
p[0] = (int)(e->m1 >> 16) & 0xFFFF;
p[1] = (int)(e->m1) & 0xFFFF;
p[2] = (int)(e->m2 >> 16) & 0xFFFF;
p[3] = (int)(e->m2) & 0xFFFF;
}