summaryrefslogtreecommitdiff
path: root/src/cmd/gc/mparith3.c
diff options
context:
space:
mode:
authorKen Thompson <ken@golang.org>2008-12-10 14:17:24 -0800
committerKen Thompson <ken@golang.org>2008-12-10 14:17:24 -0800
commit5922d3fd6e4eeb99bfc406c8793fdbc74d37cadb (patch)
treec399a42c092bb7276ba0d71ccad401794bc5ae4f /src/cmd/gc/mparith3.c
parente8c9ccaae0ad5d6b74704a42d24f34103e967ed7 (diff)
downloadgolang-5922d3fd6e4eeb99bfc406c8793fdbc74d37cadb.tar.gz
bug120
R=r OCL=20921 CL=20921
Diffstat (limited to 'src/cmd/gc/mparith3.c')
-rw-r--r--src/cmd/gc/mparith3.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/cmd/gc/mparith3.c b/src/cmd/gc/mparith3.c
index 7098ba68b..8e3da7a4b 100644
--- a/src/cmd/gc/mparith3.c
+++ b/src/cmd/gc/mparith3.c
@@ -161,7 +161,7 @@ double
mpgetflt(Mpflt *a)
{
int s, i;
- uvlong v;
+ uvlong v, vm;
double f;
if(a->val.ovf)
@@ -186,22 +186,31 @@ mpgetflt(Mpflt *a)
// independently or in the 6g half of the compiler
// pick up the mantissa in a uvlong
- s = 63;
+ s = 53;
v = 0;
for(i=Mpnorm-1; s>=Mpscale; i--) {
v = (v<<Mpscale) | a->val.a[i];
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)
v = (v<<s) | (a->val.a[i]>>(Mpscale-s));
- // 63 bits of mantissa being rounded to 53
- // should do this in multi precision
- if((v&0x3ffULL) != 0x200ULL || (v&0x400) != 0)
- v += 0x200ULL; // round toward even
+//print("vm=%.16llux v=%.16llux\n", vm, v);
+ // round toward even
+ if(v != (1ULL<<63) || (vm&1ULL) != 0)
+ vm += v>>63;
- v >>= 10;
- f = (double)(v);
+ f = (double)(vm);
f = ldexp(f, Mpnorm*Mpscale + a->exp - 53);
if(a->val.neg)