diff options
author | Guido van Rossum <guido@python.org> | 1997-01-02 22:31:07 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1997-01-02 22:31:07 (GMT) |
commit | 07ef655222e4db5ad4e5fff68b35d05e4ff713a2 (patch) | |
tree | d9a3671e46a969e4830016f56e35855bc5a8348a | |
parent | 74679b455fad59a38f4172ae883244c1dc12e2af (diff) | |
download | cpython-07ef655222e4db5ad4e5fff68b35d05e4ff713a2.zip cpython-07ef655222e4db5ad4e5fff68b35d05e4ff713a2.tar.gz cpython-07ef655222e4db5ad4e5fff68b35d05e4ff713a2.tar.bz2 |
Oops -- unpack float/double didn't do the right thing if e==0.
-rw-r--r-- | Modules/structmodule.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/Modules/structmodule.c b/Modules/structmodule.c index 23b820b..ef13912 100644 --- a/Modules/structmodule.c +++ b/Modules/structmodule.c @@ -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; |