Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Changes from 2 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9cd1de5
suggest swapping equality on e0277
makai410 Feb 17, 2025
6e4adbe
Remove visit_const_block in typeck writeback
nbdd0121 Feb 26, 2025
8282181
Use Binder<Vec<T>> instead of Vec<Binder<T>> in new solver
compiler-errors Feb 26, 2025
ad74788
Use bound_coroutine_witnesses in old solver
compiler-errors Feb 26, 2025
f482460
Handle asm const similar to inline const
nbdd0121 Feb 26, 2025
395b0fb
Bless tests
nbdd0121 Feb 26, 2025
f20dd49
Use original command for showing sccache stats
Kobzol Feb 27, 2025
31388f5
checked_ilog tests: deal with a bit of float imprecision
RalfJung Feb 27, 2025
b3cae68
move `rust.description` to `build.description`
onur-ozkan Feb 27, 2025
0becb57
add change-entry
onur-ozkan Feb 27, 2025
f877b12
pass `CFG_VER_DESCRIPTION` to tool builds
onur-ozkan Feb 27, 2025
6cc6b86
Update E0133 docs for 2024 edition
ehuss Feb 27, 2025
d504f70
Unconditionally lower match arm even if it's unneeded for never patte…
mu001999 Feb 27, 2025
0f7da1a
replace `rust.description` with `build.description`
onur-ozkan Feb 27, 2025
cdd8895
Add inference constraining Copy impl test
BoxyUwU Feb 14, 2025
dc6db19
Defer repeat expr `Copy` check
BoxyUwU Feb 14, 2025
6c3243f
Bless
BoxyUwU Feb 15, 2025
86945c0
Tweak incorrect ABI suggestion
estebank Feb 28, 2025
3e8fa17
Rollup merge of #137045 - BoxyUwU:defer_repeat_expr_checks, r=compile…
matthiaskrgr Feb 28, 2025
2798d2d
Rollup merge of #137171 - makai410:swapping-e0277, r=compiler-errors
matthiaskrgr Feb 28, 2025
18a685b
Rollup merge of #137686 - nbdd0121:asm_const, r=compiler-errors
matthiaskrgr Feb 28, 2025
ae57555
Rollup merge of #137689 - compiler-errors:coroutine, r=lcnr
matthiaskrgr Feb 28, 2025
6c5246f
Rollup merge of #137718 - Kobzol:sccache-stats, r=marcoieni
matthiaskrgr Feb 28, 2025
bfbe327
Rollup merge of #137723 - onur-ozkan:cfg-ver-description, r=pietroalb…
matthiaskrgr Feb 28, 2025
2833b34
Rollup merge of #137730 - RalfJung:checked_ilog_tests, r=tgross35
matthiaskrgr Feb 28, 2025
8569096
Rollup merge of #137735 - ehuss:e0133-edition-docs, r=compiler-errors
matthiaskrgr Feb 28, 2025
6069a75
Rollup merge of #137742 - mu001999-contrib:fix-137708, r=compiler-errors
matthiaskrgr Feb 28, 2025
5e24e2c
Rollup merge of #137771 - estebank:abi-sugg, r=compiler-errors
matthiaskrgr Feb 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 56 additions & 18 deletions library/coretests/tests/num/int_log.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
//! Tests for the `Integer::{ilog,log2,log10}` methods.

/// Rounds the argument down to the next integer, except that we account for potential imprecision
/// in the input, so if `f` is very close to an integer, it will round to that.
fn round_down_imprecise(f: f32) -> u32 {
// Rounds up for values less than 16*EPSILON below an integer,
// and rounds down for everything else.
(f + 16.0 * f32::EPSILON) as u32
}

#[test]
fn checked_ilog() {
assert_eq!(999u32.checked_ilog(10), Some(2));
Expand All @@ -25,11 +33,19 @@ fn checked_ilog() {
}
#[cfg(not(miri))] // Miri is too slow
for i in 1..=i16::MAX {
assert_eq!(i.checked_ilog(13), Some((i as f32).log(13.0) as u32), "checking {i}");
assert_eq!(
i.checked_ilog(13),
Some(round_down_imprecise((i as f32).log(13.0))),
"checking {i}"
);
}
#[cfg(not(miri))] // Miri is too slow
for i in 1..=u16::MAX {
assert_eq!(i.checked_ilog(13), Some((i as f32).log(13.0) as u32), "checking {i}");
assert_eq!(
i.checked_ilog(13),
Some(round_down_imprecise((i as f32).log(13.0))),
"checking {i}"
);
}
}

Expand All @@ -46,36 +62,46 @@ fn checked_ilog2() {
assert_eq!(0i8.checked_ilog2(), None);
assert_eq!(0i16.checked_ilog2(), None);

assert_eq!(8192u16.checked_ilog2(), Some((8192f32).log2() as u32));
assert_eq!(32768u16.checked_ilog2(), Some((32768f32).log2() as u32));
assert_eq!(8192i16.checked_ilog2(), Some((8192f32).log2() as u32));
assert_eq!(8192u16.checked_ilog2(), Some(round_down_imprecise((8192f32).log2())));
assert_eq!(32768u16.checked_ilog2(), Some(round_down_imprecise((32768f32).log2())));
assert_eq!(8192i16.checked_ilog2(), Some(round_down_imprecise((8192f32).log2())));

for i in 1..=u8::MAX {
assert_eq!(i.checked_ilog2(), Some((i as f32).log2() as u32), "checking {i}");
assert_eq!(
i.checked_ilog2(),
Some(round_down_imprecise((i as f32).log2())),
"checking {i}"
);
}
#[cfg(not(miri))] // Miri is too slow
for i in 1..=u16::MAX {
// Guard against Android's imprecise f32::ilog2 implementation.
if i != 8192 && i != 32768 {
assert_eq!(i.checked_ilog2(), Some((i as f32).log2() as u32), "checking {i}");
}
assert_eq!(
i.checked_ilog2(),
Some(round_down_imprecise((i as f32).log2())),
"checking {i}"
);
}
for i in i8::MIN..=0 {
assert_eq!(i.checked_ilog2(), None, "checking {i}");
}
for i in 1..=i8::MAX {
assert_eq!(i.checked_ilog2(), Some((i as f32).log2() as u32), "checking {i}");
assert_eq!(
i.checked_ilog2(),
Some(round_down_imprecise((i as f32).log2())),
"checking {i}"
);
}
#[cfg(not(miri))] // Miri is too slow
for i in i16::MIN..=0 {
assert_eq!(i.checked_ilog2(), None, "checking {i}");
}
#[cfg(not(miri))] // Miri is too slow
for i in 1..=i16::MAX {
// Guard against Android's imprecise f32::ilog2 implementation.
if i != 8192 {
assert_eq!(i.checked_ilog2(), Some((i as f32).log2() as u32), "checking {i}");
}
assert_eq!(
i.checked_ilog2(),
Some(round_down_imprecise((i as f32).log2())),
"checking {i}"
);
}
}

Expand All @@ -92,15 +118,27 @@ fn checked_ilog10() {
}
#[cfg(not(miri))] // Miri is too slow
for i in 1..=i16::MAX {
assert_eq!(i.checked_ilog10(), Some((i as f32).log10() as u32), "checking {i}");
assert_eq!(
i.checked_ilog10(),
Some(round_down_imprecise((i as f32).log10())),
"checking {i}"
);
}
#[cfg(not(miri))] // Miri is too slow
for i in 1..=u16::MAX {
assert_eq!(i.checked_ilog10(), Some((i as f32).log10() as u32), "checking {i}");
assert_eq!(
i.checked_ilog10(),
Some(round_down_imprecise((i as f32).log10())),
"checking {i}"
);
}
#[cfg(not(miri))] // Miri is too slow
for i in 1..=100_000u32 {
assert_eq!(i.checked_ilog10(), Some((i as f32).log10() as u32), "checking {i}");
assert_eq!(
i.checked_ilog10(),
Some(round_down_imprecise((i as f32).log10())),
"checking {i}"
);
}
}

Expand Down