Commit 5f1a3be9 authored by Ken Thompson's avatar Ken Thompson

bug120

R=r
OCL=20921
CL=20921
parent fbfc9ddd
...@@ -161,7 +161,7 @@ double ...@@ -161,7 +161,7 @@ double
mpgetflt(Mpflt *a) mpgetflt(Mpflt *a)
{ {
int s, i; int s, i;
uvlong v; uvlong v, vm;
double f; double f;
if(a->val.ovf) if(a->val.ovf)
...@@ -186,22 +186,31 @@ mpgetflt(Mpflt *a) ...@@ -186,22 +186,31 @@ mpgetflt(Mpflt *a)
// independently or in the 6g half of the compiler // independently or in the 6g half of the compiler
// pick up the mantissa in a uvlong // pick up the mantissa in a uvlong
s = 63; s = 53;
v = 0; v = 0;
for(i=Mpnorm-1; s>=Mpscale; i--) { for(i=Mpnorm-1; s>=Mpscale; i--) {
v = (v<<Mpscale) | a->val.a[i]; v = (v<<Mpscale) | a->val.a[i];
s -= Mpscale; s -= Mpscale;
} }
vm = v;
if(s > 0)
vm = (vm<<s) | (a->val.a[i]>>(Mpscale-s));
// continue with 64 more bits
s += 64;
for(; s>=Mpscale; i--) {
v = (v<<Mpscale) | a->val.a[i];
s -= Mpscale;
}
if(s > 0) if(s > 0)
v = (v<<s) | (a->val.a[i]>>(Mpscale-s)); v = (v<<s) | (a->val.a[i]>>(Mpscale-s));
// 63 bits of mantissa being rounded to 53 //print("vm=%.16llux v=%.16llux\n", vm, v);
// should do this in multi precision // round toward even
if((v&0x3ffULL) != 0x200ULL || (v&0x400) != 0) if(v != (1ULL<<63) || (vm&1ULL) != 0)
v += 0x200ULL; // round toward even vm += v>>63;
v >>= 10; f = (double)(vm);
f = (double)(v);
f = ldexp(f, Mpnorm*Mpscale + a->exp - 53); f = ldexp(f, Mpnorm*Mpscale + a->exp - 53);
if(a->val.neg) if(a->val.neg)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment