Skip to content

Move several more float tests to floats/mod.rs #144923

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

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

rocurley
Copy link
Contributor

@rocurley rocurley commented Aug 4, 2025

This PR moves several tests to floats/mod.rs, as discussed in #141726. The tests moved are:

  • test_abs
  • test_signum
  • test_is_sign_positive
  • test_is_sign_negative
  • test_next_up
  • test_next_down
  • test_sqrt_domain
  • test_clamp_min_greater_than_max
  • test_clamp_min_is_nan
  • test_clamp_max_is_nan
  • test_total_cmp

This covers all the "easy" tests: the ones that don't have a lot of precision-specific constants. It's not clear to me that it's worth migrating the others.

Each test is its own commit (with the exception of the clamp tests), so it may be easiest to review each commit individually.

r? tgross35

This clobbers the existing generic abs test, but it covers strictly
more, so that seems fine.
Note that the behaviour of the f128 test is slightly changed to use the
same nan mask as is used in test_float_bits_conv, which is the behaviour
used by f16,f32,and f64.
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 4, 2025
@rocurley rocurley marked this pull request as ready for review August 4, 2025 19:21
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 4, 2025
@rustbot

This comment has been minimized.

This standardizes how max and min subnormals are generated. Since the
new method doesn't use powf, it also enables some of the tests for f128
that were previously disabled due to issues with powf (although it looks
like those issues were already fixed anyway). f16 signalling nan tests
previously disabled are not re-enabled, since the underlying LLVM issue
has not been closed.
@rocurley rocurley force-pushed the float_tests_refactor_3 branch from 4737950 to 4e92c1c Compare August 4, 2025 19:24
@rust-log-analyzer
Copy link
Collaborator

The job aarch64-gnu-llvm-19-2 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
[RUSTC-TIMING] allocbenches test:true 8.221
error[E0223]: ambiguous associated type
##[error]    --> coretests/tests/floats/mod.rs:1202:32
     |
1202 |         fn quiet_bit_mask() -> Float::Bits {
     |                                ^^^^^^^^^^^
     |
help: use fully-qualified syntax
     |
1202 -         fn quiet_bit_mask() -> Float::Bits {
1202 +         fn quiet_bit_mask() -> <f16 as floats::TestableFloat>::Bits {
     |

error[E0223]: ambiguous associated type
##[error]    --> coretests/tests/floats/mod.rs:1202:32
     |
1202 |         fn quiet_bit_mask() -> Float::Bits {
     |                                ^^^^^^^^^^^
     |
help: use fully-qualified syntax
     |
1202 -         fn quiet_bit_mask() -> Float::Bits {
1202 +         fn quiet_bit_mask() -> <f32 as floats::TestableFloat>::Bits {
     |

error[E0223]: ambiguous associated type
##[error]    --> coretests/tests/floats/mod.rs:1202:32
     |
1202 |         fn quiet_bit_mask() -> Float::Bits {
     |                                ^^^^^^^^^^^
     |
help: use fully-qualified syntax
     |
1202 -         fn quiet_bit_mask() -> Float::Bits {
1202 +         fn quiet_bit_mask() -> <f64 as floats::TestableFloat>::Bits {
     |

error[E0223]: ambiguous associated type
##[error]    --> coretests/tests/floats/mod.rs:1202:32
     |
1202 |         fn quiet_bit_mask() -> Float::Bits {
     |                                ^^^^^^^^^^^
     |
help: use fully-qualified syntax
     |
1202 -         fn quiet_bit_mask() -> Float::Bits {
1202 +         fn quiet_bit_mask() -> <f128 as floats::TestableFloat>::Bits {
     |

error[E0223]: ambiguous associated type
##[error]    --> coretests/tests/floats/mod.rs:1310:32
     |
1310 |         fn quiet_bit_mask() -> Float::Bits {
     |                                ^^^^^^^^^^^
     |
help: use fully-qualified syntax
     |
1310 -         fn quiet_bit_mask() -> Float::Bits {
1310 +         fn quiet_bit_mask() -> <f32 as floats::TestableFloat>::Bits {
     |

error[E0223]: ambiguous associated type
##[error]    --> coretests/tests/floats/mod.rs:1310:32
     |
1310 |         fn quiet_bit_mask() -> Float::Bits {
     |                                ^^^^^^^^^^^
     |
help: use fully-qualified syntax
     |
1310 -         fn quiet_bit_mask() -> Float::Bits {
1310 +         fn quiet_bit_mask() -> <f64 as floats::TestableFloat>::Bits {
     |

error[E0223]: ambiguous associated type
##[error]    --> coretests/tests/floats/mod.rs:1310:32
     |
1310 |         fn quiet_bit_mask() -> Float::Bits {
     |                                ^^^^^^^^^^^
     |
help: use fully-qualified syntax
     |
1310 -         fn quiet_bit_mask() -> Float::Bits {
1310 +         fn quiet_bit_mask() -> <f128 as floats::TestableFloat>::Bits {
     |

error[E0223]: ambiguous associated type
##[error]    --> coretests/tests/floats/mod.rs:1310:32
     |
1310 |         fn quiet_bit_mask() -> Float::Bits {
     |                                ^^^^^^^^^^^
     |
help: use fully-qualified syntax
     |
1310 -         fn quiet_bit_mask() -> Float::Bits {
1310 +         fn quiet_bit_mask() -> <f16 as floats::TestableFloat>::Bits {
     |

[RUSTC-TIMING] corebenches test:true 8.642
error[E0308]: mismatched types
##[error]    --> coretests/tests/floats/mod.rs:1210:54
     |
1210 |         assert_eq!(Ordering::Equal, Float::total_cmp(-q_nan(), &-q_nan()));
     |                                     ---------------- ^^^^^^^^ expected `&f16`, found `f16`
     |                                     |
     |                                     arguments to this function are incorrect
     |
note: method defined here
    --> /checkout/library/core/src/num/f16.rs:1170:12
     |
1170 |     pub fn total_cmp(&self, other: &Self) -> crate::cmp::Ordering {
     |            ^^^^^^^^^
help: consider borrowing here
     |
1210 |         assert_eq!(Ordering::Equal, Float::total_cmp(&-q_nan(), &-q_nan()));
     |                                                      +

error[E0308]: mismatched types
##[error]    --> coretests/tests/floats/mod.rs:1211:54
     |
1211 |         assert_eq!(Ordering::Equal, Float::total_cmp(-Float::INFINITY, &-Float::INFINITY));
     |                                     ---------------- ^^^^^^^^^^^^^^^^ expected `&f16`, found `f16`
     |                                     |
     |                                     arguments to this function are incorrect
     |
note: method defined here
    --> /checkout/library/core/src/num/f16.rs:1170:12
     |
1170 |     pub fn total_cmp(&self, other: &Self) -> crate::cmp::Ordering {
     |            ^^^^^^^^^
help: consider borrowing here
     |
1211 |         assert_eq!(Ordering::Equal, Float::total_cmp(&-Float::INFINITY, &-Float::INFINITY));
     |                                                      +

error[E0308]: mismatched types
##[error]    --> coretests/tests/floats/mod.rs:1212:54
     |
1212 |         assert_eq!(Ordering::Equal, Float::total_cmp(-Float::MAX, &-Float::MAX));
     |                                     ---------------- ^^^^^^^^^^^ expected `&f16`, found `f16`
     |                                     |
     |                                     arguments to this function are incorrect
     |
note: method defined here
    --> /checkout/library/core/src/num/f16.rs:1170:12
     |
1170 |     pub fn total_cmp(&self, other: &Self) -> crate::cmp::Ordering {
     |            ^^^^^^^^^
help: consider borrowing here
     |
1212 |         assert_eq!(Ordering::Equal, Float::total_cmp(&-Float::MAX, &-Float::MAX));
     |                                                      +

error[E0308]: mismatched types
##[error]    --> coretests/tests/floats/mod.rs:1213:54
     |
1213 |         assert_eq!(Ordering::Equal, Float::total_cmp(-2.5, &-2.5));
     |                                     ---------------- ^^^^ expected `&f16`, found floating-point number
     |                                     |
     |                                     arguments to this function are incorrect
     |
note: method defined here
    --> /checkout/library/core/src/num/f16.rs:1170:12
     |
1170 |     pub fn total_cmp(&self, other: &Self) -> crate::cmp::Ordering {
     |            ^^^^^^^^^
help: consider borrowing here
     |
1213 |         assert_eq!(Ordering::Equal, Float::total_cmp(&-2.5, &-2.5));
     |                                                      +

error[E0308]: mismatched types
##[error]    --> coretests/tests/floats/mod.rs:1214:54
     |
1214 |         assert_eq!(Ordering::Equal, Float::total_cmp(-1.0, &-1.0));
     |                                     ---------------- ^^^^ expected `&f16`, found floating-point number
     |                                     |
     |                                     arguments to this function are incorrect
     |
note: method defined here
    --> /checkout/library/core/src/num/f16.rs:1170:12
     |
1170 |     pub fn total_cmp(&self, other: &Self) -> crate::cmp::Ordering {
     |            ^^^^^^^^^
help: consider borrowing here
     |
1214 |         assert_eq!(Ordering::Equal, Float::total_cmp(&-1.0, &-1.0));
     |                                                      +

error[E0308]: mismatched types
##[error]    --> coretests/tests/floats/mod.rs:1215:54
     |
1215 |         assert_eq!(Ordering::Equal, Float::total_cmp(-1.5, &-1.5));
     |                                     ---------------- ^^^^ expected `&f16`, found floating-point number
     |                                     |
     |                                     arguments to this function are incorrect
     |
note: method defined here
    --> /checkout/library/core/src/num/f16.rs:1170:12
     |
1170 |     pub fn total_cmp(&self, other: &Self) -> crate::cmp::Ordering {
     |            ^^^^^^^^^
help: consider borrowing here
     |
1215 |         assert_eq!(Ordering::Equal, Float::total_cmp(&-1.5, &-1.5));
     |                                                      +

error[E0308]: mismatched types
##[error]    --> coretests/tests/floats/mod.rs:1216:54
     |
1216 |         assert_eq!(Ordering::Equal, Float::total_cmp(-0.5, &-0.5));
     |                                     ---------------- ^^^^ expected `&f16`, found floating-point number
     |                                     |
     |                                     arguments to this function are incorrect
     |
note: method defined here
    --> /checkout/library/core/src/num/f16.rs:1170:12
     |
1170 |     pub fn total_cmp(&self, other: &Self) -> crate::cmp::Ordering {
     |            ^^^^^^^^^
help: consider borrowing here
     |
1216 |         assert_eq!(Ordering::Equal, Float::total_cmp(&-0.5, &-0.5));
     |                                                      +

error[E0308]: mismatched types
##[error]    --> coretests/tests/floats/mod.rs:1217:54
     |
1217 |         assert_eq!(Ordering::Equal, Float::total_cmp(-Float::MIN_POSITIVE, &-Float::MIN_POSITIVE));
     |                                     ---------------- ^^^^^^^^^^^^^^^^^^^^ expected `&f16`, found `f16`
     |                                     |
     |                                     arguments to this function are incorrect
     |
note: method defined here
    --> /checkout/library/core/src/num/f16.rs:1170:12
     |
1170 |     pub fn total_cmp(&self, other: &Self) -> crate::cmp::Ordering {
     |            ^^^^^^^^^
help: consider borrowing here
     |
1217 |         assert_eq!(Ordering::Equal, Float::total_cmp(&-Float::MIN_POSITIVE, &-Float::MIN_POSITIVE));
     |                                                      +

error[E0308]: mismatched types
##[error]    --> coretests/tests/floats/mod.rs:1218:54
     |
1218 |         assert_eq!(Ordering::Equal, Float::total_cmp(-Float::MAX_SUBNORMAL, &-Float::MAX_SUBNORMAL));
     |                                     ---------------- ^^^^^^^^^^^^^^^^^^^^^ expected `&f16`, found `f16`
     |                                     |
     |                                     arguments to this function are incorrect
     |
note: method defined here
    --> /checkout/library/core/src/num/f16.rs:1170:12
     |
1170 |     pub fn total_cmp(&self, other: &Self) -> crate::cmp::Ordering {
     |            ^^^^^^^^^
help: consider borrowing here
     |
1218 |         assert_eq!(Ordering::Equal, Float::total_cmp(&-Float::MAX_SUBNORMAL, &-Float::MAX_SUBNORMAL));
     |                                                      +

error[E0308]: mismatched types
##[error]    --> coretests/tests/floats/mod.rs:1219:54
     |
1219 |         assert_eq!(Ordering::Equal, Float::total_cmp(-Float::TINY, &-Float::TINY));
     |                                     ---------------- ^^^^^^^^^^^^ expected `&f16`, found `f16`
     |                                     |
     |                                     arguments to this function are incorrect
     |
note: method defined here
    --> /checkout/library/core/src/num/f16.rs:1170:12
     |
1170 |     pub fn total_cmp(&self, other: &Self) -> crate::cmp::Ordering {
     |            ^^^^^^^^^
help: consider borrowing here
     |
1219 |         assert_eq!(Ordering::Equal, Float::total_cmp(&-Float::TINY, &-Float::TINY));
     |                                                      +

error[E0308]: mismatched types
##[error]    --> coretests/tests/floats/mod.rs:1220:54
     |
1220 |         assert_eq!(Ordering::Equal, Float::total_cmp(-0.0, &-0.0));
     |                                     ---------------- ^^^^ expected `&f16`, found floating-point number
     |                                     |
     |                                     arguments to this function are incorrect
     |
note: method defined here
    --> /checkout/library/core/src/num/f16.rs:1170:12
     |
1170 |     pub fn total_cmp(&self, other: &Self) -> crate::cmp::Ordering {
     |            ^^^^^^^^^
help: consider borrowing here
     |
1220 |         assert_eq!(Ordering::Equal, Float::total_cmp(&-0.0, &-0.0));
     |                                                      +

error[E0308]: mismatched types
##[error]    --> coretests/tests/floats/mod.rs:1221:54
     |
1221 |         assert_eq!(Ordering::Equal, Float::total_cmp(0.0, &0.0));
     |                                     ---------------- ^^^ expected `&f16`, found floating-point number
     |                                     |
     |                                     arguments to this function are incorrect
     |
note: method defined here
    --> /checkout/library/core/src/num/f16.rs:1170:12
     |
1170 |     pub fn total_cmp(&self, other: &Self) -> crate::cmp::Ordering {
     |            ^^^^^^^^^
help: consider borrowing here
     |
1221 |         assert_eq!(Ordering::Equal, Float::total_cmp(&0.0, &0.0));
     |                                                      +

error[E0308]: mismatched types
##[error]    --> coretests/tests/floats/mod.rs:1222:54
     |
1222 |         assert_eq!(Ordering::Equal, Float::total_cmp(Float::TINY, &Float::TINY));
     |                                     ---------------- ^^^^^^^^^^^ expected `&f16`, found `f16`
     |                                     |
     |                                     arguments to this function are incorrect
     |
note: method defined here
    --> /checkout/library/core/src/num/f16.rs:1170:12
     |
1170 |     pub fn total_cmp(&self, other: &Self) -> crate::cmp::Ordering {
     |            ^^^^^^^^^
help: consider borrowing here
     |
1222 |         assert_eq!(Ordering::Equal, Float::total_cmp(&Float::TINY, &Float::TINY));
     |                                                      +

error[E0308]: mismatched types
##[error]    --> coretests/tests/floats/mod.rs:1223:54
     |
1223 |         assert_eq!(Ordering::Equal, Float::total_cmp(Float::MAX_SUBNORMAL, &Float::MAX_SUBNORMAL));
     |                                     ---------------- ^^^^^^^^^^^^^^^^^^^^ expected `&f16`, found `f16`
     |                                     |
     |                                     arguments to this function are incorrect
     |
note: method defined here
    --> /checkout/library/core/src/num/f16.rs:1170:12
     |
1170 |     pub fn total_cmp(&self, other: &Self) -> crate::cmp::Ordering {
     |            ^^^^^^^^^
help: consider borrowing here
     |
1223 |         assert_eq!(Ordering::Equal, Float::total_cmp(&Float::MAX_SUBNORMAL, &Float::MAX_SUBNORMAL));
     |                                                      +

error[E0308]: mismatched types
##[error]    --> coretests/tests/floats/mod.rs:1224:54
     |
1224 |         assert_eq!(Ordering::Equal, Float::total_cmp(Float::MIN_POSITIVE, &Float::MIN_POSITIVE));
     |                                     ---------------- ^^^^^^^^^^^^^^^^^^^ expected `&f16`, found `f16`
     |                                     |
     |                                     arguments to this function are incorrect
     |
note: method defined here
    --> /checkout/library/core/src/num/f16.rs:1170:12
     |
1170 |     pub fn total_cmp(&self, other: &Self) -> crate::cmp::Ordering {
     |            ^^^^^^^^^
help: consider borrowing here
     |
1224 |         assert_eq!(Ordering::Equal, Float::total_cmp(&Float::MIN_POSITIVE, &Float::MIN_POSITIVE));
     |                                                      +

error[E0308]: mismatched types
##[error]    --> coretests/tests/floats/mod.rs:1225:54
     |
1225 |         assert_eq!(Ordering::Equal, Float::total_cmp(0.5, &0.5));
     |                                     ---------------- ^^^ expected `&f16`, found floating-point number
     |                                     |
     |                                     arguments to this function are incorrect
     |
note: method defined here
    --> /checkout/library/core/src/num/f16.rs:1170:12
     |
1170 |     pub fn total_cmp(&self, other: &Self) -> crate::cmp::Ordering {
     |            ^^^^^^^^^
help: consider borrowing here
     |
1225 |         assert_eq!(Ordering::Equal, Float::total_cmp(&0.5, &0.5));
     |                                                      +

error[E0308]: mismatched types
##[error]    --> coretests/tests/floats/mod.rs:1226:54
     |
1226 |         assert_eq!(Ordering::Equal, Float::total_cmp(1.0, &1.0));
     |                                     ---------------- ^^^ expected `&f16`, found floating-point number
     |                                     |
     |                                     arguments to this function are incorrect
     |
note: method defined here
    --> /checkout/library/core/src/num/f16.rs:1170:12
     |
1170 |     pub fn total_cmp(&self, other: &Self) -> crate::cmp::Ordering {
     |            ^^^^^^^^^
help: consider borrowing here
     |
1226 |         assert_eq!(Ordering::Equal, Float::total_cmp(&1.0, &1.0));
     |                                                      +

error[E0308]: mismatched types
##[error]    --> coretests/tests/floats/mod.rs:1227:54
     |
1227 |         assert_eq!(Ordering::Equal, Float::total_cmp(1.5, &1.5));
     |                                     ---------------- ^^^ expected `&f16`, found floating-point number
     |                                     |
     |                                     arguments to this function are incorrect
     |
note: method defined here
    --> /checkout/library/core/src/num/f16.rs:1170:12
     |
1170 |     pub fn total_cmp(&self, other: &Self) -> crate::cmp::Ordering {
     |            ^^^^^^^^^
help: consider borrowing here
     |
1227 |         assert_eq!(Ordering::Equal, Float::total_cmp(&1.5, &1.5));
     |                                                      +

error[E0308]: mismatched types
##[error]    --> coretests/tests/floats/mod.rs:1228:54
     |
1228 |         assert_eq!(Ordering::Equal, Float::total_cmp(2.5, &2.5));
     |                                     ---------------- ^^^ expected `&f16`, found floating-point number
     |                                     |
     |                                     arguments to this function are incorrect
     |
note: method defined here
    --> /checkout/library/core/src/num/f16.rs:1170:12
     |
1170 |     pub fn total_cmp(&self, other: &Self) -> crate::cmp::Ordering {
     |            ^^^^^^^^^
help: consider borrowing here
     |
1228 |         assert_eq!(Ordering::Equal, Float::total_cmp(&2.5, &2.5));
     |                                                      +

error[E0308]: mismatched types
##[error]    --> coretests/tests/floats/mod.rs:1229:54
     |
1229 |         assert_eq!(Ordering::Equal, Float::total_cmp(Float::MAX, &Float::MAX));
     |                                     ---------------- ^^^^^^^^^^ expected `&f16`, found `f16`
     |                                     |
     |                                     arguments to this function are incorrect
     |
note: method defined here
    --> /checkout/library/core/src/num/f16.rs:1170:12
     |
1170 |     pub fn total_cmp(&self, other: &Self) -> crate::cmp::Ordering {
     |            ^^^^^^^^^
help: consider borrowing here
     |
1229 |         assert_eq!(Ordering::Equal, Float::total_cmp(&Float::MAX, &Float::MAX));
     |                                                      +

error[E0308]: mismatched types
##[error]    --> coretests/tests/floats/mod.rs:1230:54
     |
1230 |         assert_eq!(Ordering::Equal, Float::total_cmp(Float::INFINITY, &Float::INFINITY));
     |                                     ---------------- ^^^^^^^^^^^^^^^ expected `&f16`, found `f16`
     |                                     |
     |                                     arguments to this function are incorrect
     |
note: method defined here
    --> /checkout/library/core/src/num/f16.rs:1170:12
     |
1170 |     pub fn total_cmp(&self, other: &Self) -> crate::cmp::Ordering {
     |            ^^^^^^^^^
help: consider borrowing here
     |
1230 |         assert_eq!(Ordering::Equal, Float::total_cmp(&Float::INFINITY, &Float::INFINITY));
     |                                                      +

error[E0308]: mismatched types
##[error]    --> coretests/tests/floats/mod.rs:1231:54
     |
1231 |         assert_eq!(Ordering::Equal, Float::total_cmp(q_nan(), &q_nan()));
     |                                     ---------------- ^^^^^^^ expected `&f16`, found `f16`
     |                                     |
     |                                     arguments to this function are incorrect
     |
note: method defined here
    --> /checkout/library/core/src/num/f16.rs:1170:12
     |
1170 |     pub fn total_cmp(&self, other: &Self) -> crate::cmp::Ordering {
     |            ^^^^^^^^^
help: consider borrowing here
     |
1231 |         assert_eq!(Ordering::Equal, Float::total_cmp(&q_nan(), &q_nan()));
     |                                                      +

error[E0308]: mismatched types
##[error]    --> coretests/tests/floats/mod.rs:1233:53
     |
1233 |         assert_eq!(Ordering::Less, Float::total_cmp(-Float::INFINITY, &-Float::MAX));
     |                                    ---------------- ^^^^^^^^^^^^^^^^ expected `&f16`, found `f16`
     |                                    |

@rocurley rocurley marked this pull request as draft August 4, 2025 20:19
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants