-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Deduplicated float tests and unified in floats/mod.rs #148206
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
base: main
Are you sure you want to change the base?
Conversation
|
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Any update @bjorn3 ? |
|
CI is still failing. |
ok let me fix . |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 |
b802b19 to
abd73fd
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
|
Thank you for the final cleanup here. Until CI is fixed, |
|
Reminder, once the PR becomes ready for a review, use |
Will finish this as soon as possible . A bit busy these days. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
0f27f23 to
507fb72
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
94299f0 to
7feb73a
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@tgross35 I updated the tests as suggested but the aarch64 rustc_codegen_cranelift is still failing at the linker stage. |
|
Looks like cg_clif incorrectly implements these operations for f16: rust-lang/rustc_codegen_cranelift#1622 Feel free to drop a patch file in |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@rustbot ready |
There was a problem hiding this 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?
| let two: Float = 2.0; | ||
| let ten: Float = 10.0; | ||
| let two: Float = flt(2.0); | ||
| let ten: Float = flt(10.0); |
There was a problem hiding this comment.
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)
| 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); | ||
| } |
There was a problem hiding this comment.
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
rust/library/std/tests/floats/f64.rs
Lines 135 to 144 in f57eac1
| // 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto here
rust/library/std/tests/floats/f64.rs
Lines 161 to 162 in f57eac1
| // test for low accuracy from issue 104548 | |
| assert_approx_eq!(60.0f64, 60.0f64.cosh().acosh()); |
| 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)); |
There was a problem hiding this comment.
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.
| 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); |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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
| 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; |
There was a problem hiding this comment.
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))], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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.
This comment has been minimized.
This comment has been minimized.
87f3042 to
2bb4a07
Compare
This comment has been minimized.
This comment has been minimized.
|
Some changes occurred in GUI tests. |
b6b949c to
eb0704d
Compare
|
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove these changes.
|
The job Click to see the possible cause of the failure (guessed by this bot) |
|
☔ The latest upstream changes (presumably #151087) made this pull request unmergeable. Please resolve the merge conflicts. |
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