about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorKang Seonghoon <public+git@mearie.org>2015-04-21 20:32:25 +0900
committerKang Seonghoon <public+git@mearie.org>2015-05-06 14:22:26 +0900
commit97ea7c14bae496d6444752be570dd41cf1a507bd (patch)
tree0a0b52c4568cf5ccd53faa2f8662cc6c37b2adc4 /src/libcore
parent8a195f075417ad78084ef2e1c5e294ac35d6cafa (diff)
downloadrust-97ea7c14bae496d6444752be570dd41cf1a507bd.tar.gz
rust-97ea7c14bae496d6444752be570dd41cf1a507bd.zip
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.
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/num/flt2dec/decoder.rs12
1 files changed, 6 insertions, 6 deletions
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<T: DecodableFloat>(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<T: DecodableFloat>(v: T) -> (/*negative?*/ bool, FullDecoded) {
         }
         FpCategory::Normal => {
             let minnorm = <T as DecodableFloat>::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 })
             }