From 97ea7c14bae496d6444752be570dd41cf1a507bd Mon Sep 17 00:00:00 2001 From: Kang Seonghoon Date: Tue, 21 Apr 2015 20:32:25 +0900 Subject: core: fixed a slight bug. The bug involves the incorrect logic for `core::num::flt2dec::decoder`. This makes some numbers in the form of 2^n missing one final digits, which breaks the bijectivity criterion. The regression tests have been added, and f32 exhaustive test is rerun to get the updated result. --- src/libcore/num/flt2dec/decoder.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/libcore/num') diff --git a/src/libcore/num/flt2dec/decoder.rs b/src/libcore/num/flt2dec/decoder.rs index 4b7d00f80e1..d4473e6bc0c 100644 --- a/src/libcore/num/flt2dec/decoder.rs +++ b/src/libcore/num/flt2dec/decoder.rs @@ -75,7 +75,7 @@ pub fn decode(v: T) -> (/*negative?*/ bool, FullDecoded) { FpCategory::Infinite => FullDecoded::Infinite, FpCategory::Zero => FullDecoded::Zero, FpCategory::Subnormal => { - // (mant - 2, exp) -- (mant, exp) -- (mant + 2, exp) + // neighbors: (mant - 2, exp) -- (mant, exp) -- (mant + 2, exp) // Float::integer_decode always preserves the exponent, // so the mantissa is scaled for subnormals. FullDecoded::Finite(Decoded { mant: mant, minus: 1, plus: 1, @@ -83,13 +83,13 @@ pub fn decode(v: T) -> (/*negative?*/ bool, FullDecoded) { } FpCategory::Normal => { let minnorm = ::min_pos_norm_value().integer_decode(); - if mant == minnorm.0 && exp == minnorm.1 { - // (maxmant, exp - 1) -- (minnormmant, exp) -- (minnormmant + 1, exp) + if mant == minnorm.0 { + // neighbors: (maxmant, exp - 1) -- (minnormmant, exp) -- (minnormmant + 1, exp) // where maxmant = minnormmant * 2 - 1 - FullDecoded::Finite(Decoded { mant: mant << 1, minus: 1, plus: 2, - exp: exp - 1, inclusive: even }) + FullDecoded::Finite(Decoded { mant: mant << 2, minus: 1, plus: 2, + exp: exp - 2, inclusive: even }) } else { - // (mant - 1, exp) -- (mant, exp) -- (mant + 1, exp) + // neighbors: (mant - 1, exp) -- (mant, exp) -- (mant + 1, exp) FullDecoded::Finite(Decoded { mant: mant << 1, minus: 1, plus: 1, exp: exp - 1, inclusive: even }) } -- cgit 1.4.1-3-g733a5