Skip to content

Conversation

@xonx4l
Copy link
Contributor

@xonx4l xonx4l commented Oct 28, 2025

In this PR Float tests are deduplicated and are unified in floats/mod.rs, as discussed in #141726.

The moved float tests are:

-> test_powf
-> test_exp
-> test_exp2
-> test_ln
-> test_log_generic
-> test_log2
-> test_log10
-> test_asinh
-> test_acosh
-> test_atanh
-> test_gamma
-> test_ln_gamma

Closes: #141726

r? tgross35

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Oct 28, 2025
@rustbot
Copy link
Collaborator

rustbot commented Oct 28, 2025

tgross35 is currently at their maximum review capacity.
They may take a while to respond.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@xonx4l xonx4l requested a review from bjorn3 November 4, 2025 00:43
@xonx4l
Copy link
Contributor Author

xonx4l commented Nov 11, 2025

Any update @bjorn3 ?

@bjorn3
Copy link
Member

bjorn3 commented Nov 11, 2025

CI is still failing.

@xonx4l
Copy link
Contributor Author

xonx4l commented Nov 11, 2025

CI is still failing.

ok let me fix .

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Nov 14, 2025

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

@xonx4l xonx4l force-pushed the deduplicate-float-tests branch from b802b19 to abd73fd Compare November 14, 2025 08:43
@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

let inf: Float = Float::INFINITY;
let neg_inf: Float = Float::NEG_INFINITY;
assert_biteq!((10.0 as Float).log(10.0), 1.0);
assert_approx_eq!((2.3 as Float).log(3.5), 0.664858, Float::LOG_APPROX);
Copy link
Contributor

@LorrensP-2158466 LorrensP-2158466 Nov 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test here for f128 will fail because the precision is much higher, if you look at the original test, the expected value is much more precise than what you have written:

assert_approx_eq!(2.3f128.log(3.5), 0.66485771361478710036766645911922010272, TOL);

When testing higher precision floats, you need much more precise expected values or the tests will fail, as they do now. In Miri, this is even more strict.

If you look at the source of f16 constants, they use much more digits after the decimal point than needed:

pub const PI: f16 = 3.14159265358979323846264338327950288_f16;

So you should probably do that as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay it makes sense . Thanks

@tgross35
Copy link
Contributor

Thank you for the final cleanup here. Until CI is fixed,
@rustbot author

@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 Nov 19, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 19, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@xonx4l
Copy link
Contributor Author

xonx4l commented Nov 19, 2025

Thank you for the final cleanup here. Until CI is fixed, @rustbot author

Will finish this as soon as possible . A bit busy these days.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@xonx4l xonx4l force-pushed the deduplicate-float-tests branch from 0f27f23 to 507fb72 Compare December 23, 2025 17:59
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@xonx4l xonx4l force-pushed the deduplicate-float-tests branch from 94299f0 to 7feb73a Compare January 9, 2026 09:22
@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@xonx4l
Copy link
Contributor Author

xonx4l commented Jan 9, 2026

@tgross35 I updated the tests as suggested but the aarch64 rustc_codegen_cranelift is still failing at the linker stage.

@bjorn3
Copy link
Member

bjorn3 commented Jan 9, 2026

Looks like cg_clif incorrectly implements these operations for f16: rust-lang/rustc_codegen_cranelift#1622 Feel free to drop a patch file in compiler/rustc_codegen_cranelift/patches with 0029-sysroot_tests- as prefix. The sysroot_tests tells cg_clif's build system to apply the patch when running standard library tests.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@xonx4l
Copy link
Contributor Author

xonx4l commented Jan 10, 2026

@rustbot ready

@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 Jan 10, 2026
Copy link
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few requests for cleanup then I think this should be good. Could you please also squash the commits?

View changes since this review

Comment on lines 388 to 520
let two: Float = 2.0;
let ten: Float = 10.0;
let two: Float = flt(2.0);
let ten: Float = flt(10.0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please drop any flt additions where they aren't replacing an as cast. It's only needed in cases where the type is ambiguous (e.g. 4.0.sqrt() could be any float's sqrt), not everywhere we have a literal.

(applies everywhere in the file)

Comment on lines 1774 to 1720
assert!(flt(-0.0).asinh().is_sign_negative());
assert_approx_eq!(flt(2.0).asinh(), flt(1.443635475178810342493276740273105), Float::ASINH_APPROX);
assert_approx_eq!(flt(-2.0).asinh(), flt(-1.443635475178810342493276740273105), Float::ASINH_APPROX);

assert_approx_eq!(flt(-200.0).asinh(), flt(-5.991470797049389), Float::ASINH_APPROX);
if Float::MAX > flt(66000.0) {
assert_approx_eq!(flt(-67452098.07139316).asinh(), flt(-18.720075426274544393985484294000831757220), Float::ASINH_APPROX);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These test cases have some context comments in the original, please preserve them

// issue 63271
assert_approx_eq!(2.0f64.asinh(), 1.443635475178810342493276740273105f64);
assert_approx_eq!((-2.0f64).asinh(), -1.443635475178810342493276740273105f64);
// regression test for the catastrophic cancellation fixed in 72486
assert_approx_eq!((-67452098.07139316f64).asinh(), -18.72007542627454439398548429400083);
// test for low accuracy from issue 104548
assert_approx_eq!(60.0f64, 60.0f64.sinh().asinh());
// mul needed for approximate comparison to be meaningful
assert_approx_eq!(1.0f64, 1e-15f64.sinh().asinh() * 1e15f64);

assert_approx_eq!(flt(3.0).acosh(), flt(1.76274717403908605046521864995958461), Float::ACOSH_APPROX);

if Float::MAX > flt(66000.0) {
assert_approx_eq!(flt(60.0), flt(60.0).cosh().acosh(), Float::ACOSH_APPROX);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto here

// test for low accuracy from issue 104548
assert_approx_eq!(60.0f64, 60.0f64.cosh().acosh());

Comment on lines 637 to 786
assert_biteq!((0.0 as Float).min(0.0), 0.0);
assert_biteq!((-0.0 as Float).min(-0.0), -0.0);
assert_biteq!((9.0 as Float).min(9.0), 9.0);
assert_biteq!((-9.0 as Float).min(0.0), -9.0);
assert_biteq!((0.0 as Float).min(9.0), 0.0);
assert_biteq!((-0.0 as Float).min(9.0), -0.0);
assert_biteq!((-0.0 as Float).min(-9.0), -9.0);
assert_biteq!(Float::INFINITY.min(9.0), 9.0);
assert_biteq!((9.0 as Float).min(Float::INFINITY), 9.0);
assert_biteq!(Float::INFINITY.min(-9.0), -9.0);
assert_biteq!((-9.0 as Float).min(Float::INFINITY), -9.0);
assert_biteq!(Float::NEG_INFINITY.min(9.0), Float::NEG_INFINITY);
assert_biteq!((9.0 as Float).min(Float::NEG_INFINITY), Float::NEG_INFINITY);
assert_biteq!(Float::NEG_INFINITY.min(-9.0), Float::NEG_INFINITY);
assert_biteq!((-9.0 as Float).min(Float::NEG_INFINITY), Float::NEG_INFINITY);
assert_biteq!(Float::NAN.min(9.0), 9.0);
assert_biteq!(Float::NAN.min(-9.0), -9.0);
assert_biteq!((9.0 as Float).min(Float::NAN), 9.0);
assert_biteq!((-9.0 as Float).min(Float::NAN), -9.0);
assert_biteq!(flt(0.0).min(flt(0.0)), flt(0.0));
assert_biteq!(flt(-0.0).min(flt(-0.0)), flt(-0.0));
assert_biteq!(flt(9.0).min(flt(9.0)), flt(9.0));
assert_biteq!(flt(-9.0).min(flt(0.0)), flt(-9.0));
assert_biteq!(flt(0.0).min(flt(9.0)), flt(0.0));
assert_biteq!(flt(-0.0).min(flt(9.0)), flt(-0.0));
assert_biteq!(flt(-0.0).min(flt(-9.0)), flt(-9.0));
assert_biteq!(Float::INFINITY.min(flt(9.0)), flt(9.0));
assert_biteq!(flt(9.0).min(Float::INFINITY), flt(9.0));
assert_biteq!(Float::INFINITY.min(flt(-9.0)), flt(-9.0));
assert_biteq!(flt(-9.0).min(Float::INFINITY), flt(-9.0));
assert_biteq!(Float::NEG_INFINITY.min(flt(9.0)), Float::NEG_INFINITY);
assert_biteq!(flt(9.0).min(Float::NEG_INFINITY), Float::NEG_INFINITY);
assert_biteq!(Float::NEG_INFINITY.min(flt(-9.0)), Float::NEG_INFINITY);
assert_biteq!(flt(-9.0).min(Float::NEG_INFINITY), Float::NEG_INFINITY);
assert_biteq!(Float::NAN.min(flt(9.0)), flt(9.0));
assert_biteq!(Float::NAN.min(flt(-9.0)), flt(-9.0));
assert_biteq!(flt(9.0).min(Float::NAN), flt(9.0));
assert_biteq!(flt(-9.0).min(Float::NAN), flt(-9.0));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing the replacements like 0.0 as Float -> flt(0.0) are good 👍 but the rest wasn't ambiguous, please remove the unneeded flts.

Comment on lines 1610 to 1618
assert_biteq!(flt(1.0).powf(flt(1.0)), flt(1.0));
assert_approx_eq!(flt(3.4).powf(flt(4.5)), flt(246.40818323761892815995637964326426756), Float::POWF_APPROX);
assert_approx_eq!(flt(2.7).powf(flt(-3.2)), flt(0.041652009108526178281070304373500889273), Float::POWF_APPROX);
assert_approx_eq!(flt(-3.1).powf(flt(2.0)), flt(9.6100000000000005506706202140776519387), Float::POWF_APPROX);
assert_approx_eq!(flt(5.9).powf(flt(-2.0)), flt(0.028727377190462507313100483690639638451), Float::POWF_APPROX);
assert_biteq!(flt(8.3).powf(flt(0.0)), flt(1.0));
assert!(nan.powf(flt(2.0)).is_nan());
assert_biteq!(inf.powf(flt(2.0)), inf);
assert_biteq!(neg_inf.powf(flt(3.0)), neg_inf);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, this can be simplified to assert_biteq!(flt(1.0).powf(1.0), 1.0);. Once it knows the type of the first 1.0, the rest of the functions will be the same type.

}

float_test! {
name: log_generic,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original test was just called log

Comment on lines 33 to 47
const FRAC_PI_2: Self;
const FRAC_PI_3: Self;
const FRAC_PI_4: Self;
const FRAC_PI_6: Self;
const FRAC_PI_8: Self;
const FRAC_1_PI: Self;
const FRAC_2_PI: Self;
const FRAC_2_SQRT_PI: Self;
const SQRT_2: Self;
const FRAC_1_SQRT_2: Self;
const E: Self;
const LOG2_E: Self;
const LOG10_E: Self;
const LN_2: Self;
const LN_10: Self;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of these, update the eight test_* functions in https://github.com/xonx4l/rust/blob/fb26a5b86d57a19ef330866fac5c44ca2cf2a97a/library/coretests/tests/floats/mod.rs#L418-L505 to e.g.

            #[test]
            $( $( #[$f16_meta] )+ )?
            fn test_f16() {
                #[allow(unused_imports)]
                use core::f16::consts;
                type $fty = f16;
                #[allow(unused)]
                const fn flt (x: $fty) -> $fty { x }
                $test
            }

(adding the use) then the tests can use e.g. consts::LOG2_E directly.

attrs: {
// FIXME(f16_f128): add math tests when available
const: #[cfg(false)],
f16: #[cfg(any(miri, target_has_reliable_f16))],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
f16: #[cfg(any(miri, target_has_reliable_f16))],
f16: #[cfg(any(miri, target_has_reliable_f16_math))],

Fewer platforms enable reliable_x_math than for reliable_x, the _math option needs to be used whenever there are calls like .sqrt.

@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 Jan 10, 2026
@rust-log-analyzer

This comment has been minimized.

@xonx4l xonx4l force-pushed the deduplicate-float-tests branch from 87f3042 to 2bb4a07 Compare January 13, 2026 17:40
@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Jan 13, 2026

Some changes occurred in GUI tests.

cc @GuillaumeGomez

@rustbot rustbot added the T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. label Jan 13, 2026
@xonx4l xonx4l force-pushed the deduplicate-float-tests branch from b6b949c to eb0704d Compare January 13, 2026 21:03
@rustbot
Copy link
Collaborator

rustbot commented Jan 13, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

block {
call-function: ("check-notable-tooltip-position", {"x": |x|, "i_x": |i_x|})
assert-count: ("//*[@class='tooltip popover']", 0)
assert-count: ("//*[@class='tooltip popover']", 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove these changes.

@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-tools failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
............................................       (144/144)

======== tests/rustdoc-gui/notable-trait.goml ========

[ERROR] line 64
    at `tests/rustdoc-gui/notable-trait.goml` line 39: expected 1 elements, found 0: for command `assert-count: ("//*[@class='tooltip popover']", 1)`
    at <file:///checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc-gui/doc/test_docs/struct.NotableStructWithLongName.html>
[ERROR] line 64
    at `tests/rustdoc-gui/notable-trait.goml` line 58: expected 1 elements, found 0: for command `assert-count: ("//*[@class='tooltip popover']", 1)`
    at <file:///checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc-gui/doc/test_docs/struct.NotableStructWithLongName.html>
[ERROR] line 173
    at `tests/rustdoc-gui/notable-trait.goml` line 39: expected 1 elements, found 0: for command `assert-count: ("//*[@class='tooltip popover']", 1)`
    at <file:///checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc-gui/doc/test_docs/struct.NotableStructWithLongName.html>
[ERROR] line 173
    at `tests/rustdoc-gui/notable-trait.goml` line 58: expected 1 elements, found 0: for command `assert-count: ("//*[@class='tooltip popover']", 1)`
    at <file:///checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc-gui/doc/test_docs/struct.NotableStructWithLongName.html>
[ERROR] line 186: expected 1 elements, found 0: for command `assert-count: ("//*[@class='tooltip popover']", 1)`
    at <file:///checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc-gui/doc/test_docs/struct.NotableStructWithLongName.html>
[ERROR] line 193: expected 1 elements, found 0: for command `assert-count: ("//*[@class='tooltip popover']", 1)`
    at <file:///checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc-gui/doc/test_docs/struct.NotableStructWithLongName.html>
[ERROR] line 207: expected 1 elements, found 0: for command `assert-count: ("//*[@class='tooltip popover']", 1)`
    at <file:///checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc-gui/doc/test_docs/struct.NotableStructWithLongName.html>
[ERROR] line 245: expected 1 elements, found 0: for command `assert-count: ("//*[@class='tooltip popover']", 1)`
    at <file:///checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc-gui/doc/test_docs/struct.NotableStructWithLongName.html#method.create_an_iterator_from_read>
[ERROR] line 251: expected 1 elements, found 0: for command `assert-count: ("//*[@class='tooltip popover']", 1)`
    at <file:///checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc-gui/doc/test_docs/struct.NotableStructWithLongName.html#method.create_an_iterator_from_read>
[ERROR] line 256: expected 1 elements, found 0: for command `assert-count: ("//*[@class='tooltip popover']", 1)`
    at <file:///checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc-gui/doc/test_docs/struct.NotableStructWithLongName.html#method.create_an_iterator_from_read>

======== tests/rustdoc-gui/search-result-display.goml ========

[WARNING] line 39: Delta is 0 for "x", maybe try to use `compare-elements-position` instead?

@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 14, 2026

☔ The latest upstream changes (presumably #151087) made this pull request unmergeable. Please resolve the merge conflicts.

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. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unify and deduplicate float tests

7 participants