]> Cypherpunks repositories - gostls13.git/commitdiff
change floating literal normalization
authorKen Thompson <ken@golang.org>
Mon, 19 Jul 2010 23:10:46 +0000 (16:10 -0700)
committerKen Thompson <ken@golang.org>
Mon, 19 Jul 2010 23:10:46 +0000 (16:10 -0700)
from word-oriented to bit-oriented.
this will increase fp literal precision
by up to a full word.

R=rsc
CC=golang-dev
https://golang.org/cl/1859044

src/cmd/gc/mparith3.c

index 5ee8b0308f8bec4bdc6cdd5702f05aeeb497dd4d..7b7e66668eb68547df3441663617de0869f35d59 100644 (file)
@@ -27,16 +27,36 @@ sigfig(Mpflt *a)
 void
 mpnorm(Mpflt *a)
 {
-       int s;
+       int s, os;
+       long x;
 
-       s = sigfig(a);
-       if(s == 0) {
+       os = sigfig(a);
+       if(os == 0) {
                // zero
                a->exp = 0;
                a->val.neg = 0;
                return;
        }
-       s = (Mpnorm-s) * Mpscale;
+
+       // this will normalize to the nearest word
+       x = a->val.a[os-1];
+       s = (Mpnorm-os) * Mpscale;
+
+       // further normalize to the nearest bit
+       for(;;) {
+               x <<= 1;
+               if(x & Mpbase)
+                       break;
+               s++;
+               if(x == 0) {
+                       // this error comes from trying to
+                       // convert an Inf or something
+                       // where the initial x=0x80000000
+                       s = (Mpnorm-os) * Mpscale;
+                       break;
+               }
+       }
+
        mpshiftfix(&a->val, s);
        a->exp -= s;
 }