From a2c47f28132910a1bcad96da19fc48e93385f2bb Mon Sep 17 00:00:00 2001 From: Chanry Date: Sun, 14 Jul 2019 19:58:10 +0800 Subject: [PATCH] calculate M value wrongly if E is equal to 24, the result is correct; otherwise, result wrong. M cannot be calculated in that way. --- chapter2/code/floats/float-f2i.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/chapter2/code/floats/float-f2i.c b/chapter2/code/floats/float-f2i.c index e3a1088e..d07a1757 100644 --- a/chapter2/code/floats/float-f2i.c +++ b/chapter2/code/floats/float-f2i.c @@ -49,12 +49,11 @@ int float_f2i(float_bits f) { num = 0x80000000; } else { E = exp - bias; - M = frac | 0x800000; if (E > 23) { - num = M << (E - 23); + num = (1 << E) | (frac << (E - 23)); } else { /* whether sig is 1 or 0, round to zero */ - num = M >> (23 - E); + num = (1 << E) | (frac >> (23 - E)); } }