Skip to content

Commit c54a02a

Browse files
committed
---
yaml --- r: 216799 b: refs/heads/stable c: 97ea7c1 h: refs/heads/master i: 216797: 98746e2 216795: 8a09ca0 216791: 6a7fe09 216783: ceda303 216767: de71cdf v: v3
1 parent 4360283 commit c54a02a

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ refs/heads/tmp: 378a370ff2057afeb1eae86eb6e78c476866a4a6
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: a5286998df566e736b32f6795bfc3803bdaf453d
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: 8a195f075417ad78084ef2e1c5e294ac35d6cafa
32+
refs/heads/stable: 97ea7c14bae496d6444752be570dd41cf1a507bd
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375

branches/stable/src/libcore/num/flt2dec/decoder.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,21 @@ pub fn decode<T: DecodableFloat>(v: T) -> (/*negative?*/ bool, FullDecoded) {
7575
FpCategory::Infinite => FullDecoded::Infinite,
7676
FpCategory::Zero => FullDecoded::Zero,
7777
FpCategory::Subnormal => {
78-
// (mant - 2, exp) -- (mant, exp) -- (mant + 2, exp)
78+
// neighbors: (mant - 2, exp) -- (mant, exp) -- (mant + 2, exp)
7979
// Float::integer_decode always preserves the exponent,
8080
// so the mantissa is scaled for subnormals.
8181
FullDecoded::Finite(Decoded { mant: mant, minus: 1, plus: 1,
8282
exp: exp, inclusive: even })
8383
}
8484
FpCategory::Normal => {
8585
let minnorm = <T as DecodableFloat>::min_pos_norm_value().integer_decode();
86-
if mant == minnorm.0 && exp == minnorm.1 {
87-
// (maxmant, exp - 1) -- (minnormmant, exp) -- (minnormmant + 1, exp)
86+
if mant == minnorm.0 {
87+
// neighbors: (maxmant, exp - 1) -- (minnormmant, exp) -- (minnormmant + 1, exp)
8888
// where maxmant = minnormmant * 2 - 1
89-
FullDecoded::Finite(Decoded { mant: mant << 1, minus: 1, plus: 2,
90-
exp: exp - 1, inclusive: even })
89+
FullDecoded::Finite(Decoded { mant: mant << 2, minus: 1, plus: 2,
90+
exp: exp - 2, inclusive: even })
9191
} else {
92-
// (mant - 1, exp) -- (mant, exp) -- (mant + 1, exp)
92+
// neighbors: (mant - 1, exp) -- (mant, exp) -- (mant + 1, exp)
9393
FullDecoded::Finite(Decoded { mant: mant << 1, minus: 1, plus: 1,
9494
exp: exp - 1, inclusive: even })
9595
}

branches/stable/src/libcoretest/num/flt2dec/mod.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,13 @@ pub fn f32_shortest_sanity_test<F>(mut f: F) where F: FnMut(&Decoded, &mut [u8])
216216
// 10^18 * 0.314159231156617216
217217
check_shortest!(f(3.141592e17f32) => b"3141592", 18);
218218

219+
// regression test for decoders
220+
// 10^8 * 0.3355443
221+
// 10^8 * 0.33554432
222+
// 10^8 * 0.33554436
223+
let twoto25: f32 = StdFloat::ldexp(1.0, 25);
224+
check_shortest!(f(twoto25) => b"33554432", 8);
225+
219226
// 10^39 * 0.340282326356119256160033759537265639424
220227
// 10^39 * 0.34028234663852885981170418348451692544
221228
// 10^39 * 0.340282366920938463463374607431768211456
@@ -308,6 +315,13 @@ pub fn f64_shortest_sanity_test<F>(mut f: F) where F: FnMut(&Decoded, &mut [u8])
308315
// 10^18 * 0.314159200000000064
309316
check_shortest!(f(3.141592e17f64) => b"3141592", 18);
310317

318+
// regression test for decoders
319+
// 10^20 * 0.18446744073709549568
320+
// 10^20 * 0.18446744073709551616
321+
// 10^20 * 0.18446744073709555712
322+
let twoto64: f64 = StdFloat::ldexp(1.0, 64);
323+
check_shortest!(f(twoto64) => b"18446744073709552", 20);
324+
311325
// pathological case: high = 10^23 (exact). tie breaking should always prefer that.
312326
// 10^24 * 0.099999999999999974834176
313327
// 10^24 * 0.099999999999999991611392
@@ -492,15 +506,15 @@ pub fn f32_exhaustive_equivalence_test<F, G>(f: F, g: G, k: usize)
492506
// so why not simply testing all of them?
493507
//
494508
// this is of course very stressful (and thus should be behind an `#[ignore]` attribute),
495-
// but with `-O3 -C lto` this only takes about two hours or so.
509+
// but with `-C opt-level=3 -C lto` this only takes about an hour or so.
496510

497511
// iterate from 0x0000_0001 to 0x7f7f_ffff, i.e. all finite ranges
498512
let (npassed, nignored) = iterate("f32_exhaustive_equivalence_test",
499513
k, 0x7f7f_ffff, f, g, |i: usize| {
500514
let x: f32 = unsafe {mem::transmute(i as u32 + 1)};
501515
decode_finite(x)
502516
});
503-
assert_eq!((npassed, nignored), (2121451879, 17643160));
517+
assert_eq!((npassed, nignored), (2121451881, 17643158));
504518
}
505519

506520
fn to_string_with_parts<F>(mut f: F) -> String

branches/stable/src/libcoretest/num/flt2dec/strategy/grisu.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ fn shortest_f32_exhaustive_equivalence_test() {
6060
//
6161
// this reports the progress and the number of f32 values returned `None`.
6262
// with `--nocapture` (and plenty of time and appropriate rustc flags), this should print:
63-
// `done, ignored=17643160 passed=2121451879 failed=0`.
63+
// `done, ignored=17643158 passed=2121451881 failed=0`.
6464

6565
use core::num::flt2dec::strategy::dragon::format_shortest as fallback;
6666
f32_exhaustive_equivalence_test(format_shortest_opt, fallback, MAX_SIG_DIGITS);

0 commit comments

Comments
 (0)