Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 6 pull requests #129728

Closed
wants to merge 17 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Enable some ilog2 tests as well
  • Loading branch information
saethlin committed Aug 28, 2024
commit 83de14c4ffeaa58874b0bbdb2da1ce3b32798b90
18 changes: 5 additions & 13 deletions library/core/tests/num/int_log.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
//! This tests the `Integer::{ilog,log2,log10}` methods. These tests are in a
//! separate file because there's both a large number of them, and not all tests
//! can be run on Android. This is because in Android `ilog2` uses an imprecise
//! approximation:https://github.com/rust-lang/rust/blob/4825e12fc9c79954aa0fe18f5521efa6c19c7539/src/libstd/sys/unix/android.rs#L27-L53
//! Tests for the `Integer::{ilog,log2,log10}` methods.

#[test]
fn checked_ilog() {
@@ -48,6 +45,10 @@ 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));

for i in 1..=u8::MAX {
assert_eq!(i.checked_ilog2(), Some((i as f32).log2() as u32), "checking {i}");
}
@@ -77,15 +78,6 @@ fn checked_ilog2() {
}
}

// Validate cases that fail on Android's imprecise float ilog2 implementation.
#[test]
#[cfg(not(target_os = "android"))]
fn checked_ilog2_not_android() {
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));
}

#[test]
fn checked_ilog10() {
assert_eq!(0u8.checked_ilog10(), None);