Skip to content

checked_ilog2 test fails with imprecise float intrinsics #137591

Closed
@RalfJung

Description

@RalfJung

Miri made its floatig-point intrinsics imprecise to reflect that we don't guarantee an exact result, and now we are seeing test failures when bumping the Miri subtree:

2025-02-24T19:16:35.0690558Z thread 'num::int_log::checked_ilog2' panicked at library/coretests/tests/num/int_log.rs:50:5:
2025-02-24T19:16:35.0691376Z assertion `left == right` failed
2025-02-24T19:16:35.0691830Z   left: Some(13)
2025-02-24T19:16:35.0692204Z  right: Some(12)
2025-02-24T19:16:35.0692798Z 
2025-02-24T19:16:35.0692807Z 
2025-02-24T19:16:35.0692960Z failures:
2025-02-24T19:16:35.0693335Z     num::int_log::checked_ilog2

The failure occurs here:

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

log2 here is the float operation. We even document:

The precision of this function is non-deterministic. This means it varies by platform, Rust version, and can even differ within the same execution from one invocation to the next.

So I think the test is bogus?

Cc @saethlin @tgross35

Note that this is somewhat urgent as it blocks updating Miri's subtree.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-floating-pointArea: Floating point numbers and arithmeticA-testsuiteArea: The testsuite used to check the correctness of rustcC-bugCategory: This is a bug.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions