]> granicus.if.org Git - python/commitdiff
Oops -- unpack float/double didn't do the right thing if e==0.
authorGuido van Rossum <guido@python.org>
Thu, 2 Jan 1997 22:31:07 +0000 (22:31 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 2 Jan 1997 22:31:07 +0000 (22:31 +0000)
Modules/structmodule.c

index 23b820bd6f323820d4a64f45fc38e4b50d537e03..ef139122d5cd50dc756670ac5ee4f08e5398abb5 100644 (file)
@@ -402,8 +402,13 @@ unpack_float(p, incr)
        x = (double)f / 8388608.0;
 
        /* XXX This sadly ignores Inf/NaN issues */
-       if (e != 0)
-               x = ldexp(1.0 + x, e - 127);
+       if (e == 0)
+               e = -126;
+       else {
+               x += 1.0;
+               e -= 127;
+       }
+       x = ldexp(x, e);
 
        if (s)
                x = -x;
@@ -459,8 +464,13 @@ unpack_double(p, incr)
        x /= 268435456.0; /* 2**28 */
 
        /* XXX This sadly ignores Inf/NaN */
-       if (e != 0)
-               x = ldexp(1.0 + x, e - 1023);
+       if (e == 0)
+               e = -1022;
+       else {
+               x += 1.0;
+               e -= 1023;
+       }
+       x = ldexp(x, e);
 
        if (s)
                x = -x;