-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Move several float tests to floats/mod.rs #143738
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: master
Are you sure you want to change the base?
Conversation
@@ -20,6 +19,31 @@ impl Approx for f128 { | |||
const LIM: Self = 1e-9; | |||
} | |||
|
|||
trait TestableFloat { |
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.
Possibly we should merge Approx
into this?
Alternatively, there could be separate floats for each logical grouping of constants. I don't really like that because it seems like a lot of boilerplate, but it would mean the traits here more meaningful.
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.
Moving LIM
to TestableFloat
sounds good to me 👍 Maybe rename it APPROX
there.
@@ -20,6 +19,31 @@ impl Approx for f128 { | |||
const LIM: Self = 1e-9; | |||
} | |||
|
|||
trait TestableFloat { |
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.
Moving LIM
to TestableFloat
sounds good to me 👍 Maybe rename it APPROX
there.
test<Float> { | ||
let neg_zero: Float = -0.0; | ||
assert!(0.0 == neg_zero); | ||
assert_biteq!(-0.0, neg_zero); | ||
assert!(!neg_zero.is_infinite()); | ||
assert!(neg_zero.is_finite()); | ||
assert!(!neg_zero.is_sign_positive()); | ||
assert!(neg_zero.is_sign_negative()); | ||
assert!(!neg_zero.is_nan()); | ||
assert!(!neg_zero.is_normal()); | ||
assert!(matches!(neg_zero.classify(), Fp::Zero)); | ||
} |
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.
Could you indent this to match?
impl TestableFloat for f16 { | ||
const SMALL_NORMAL: Self = 1e-4; | ||
const SUBNORMAL: Self = 1e-5; | ||
} | ||
|
||
impl TestableFloat for f32 { | ||
const SMALL_NORMAL: Self = 1e-37; | ||
const SUBNORMAL: Self = 1e-38; | ||
} | ||
|
||
impl TestableFloat for f64 { | ||
const SMALL_NORMAL: Self = 1e-307; | ||
const SUBNORMAL: Self = 1e-308; | ||
} | ||
|
||
impl TestableFloat for f128 { | ||
const SMALL_NORMAL: Self = 1e-4931; | ||
const SUBNORMAL: Self = 1e-4932; | ||
} |
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.
Could you rename SMALL_NORMAL
to MIN_POSITIVE_NORMAL
? Then these can just be f32::MIN_POSITIVE
rather than a handwritten value. You could also use MIN_POSITIVE
directly, but that name is confusing.
SUBNORMAL
can similarly be renamed to MAX_SUBNORMAL
with a value f32::MIN_POSITIVE.next_down()
.
@rustbot review |
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.
Couple of other small things.
After this, please clean up history by squashing the fixup commits. Or just squash everything together, if that's easier.
assert!(!0.0f32.is_nan()); | ||
assert!(!5.3f32.is_nan()); | ||
assert!(!(-10.732f32).is_nan()); |
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 are all f32
so you'll need to bind them to a variable of type Float
assert!(matches!(neg_inf.classify(), Fp::Infinite)); | ||
assert!(matches!(zero.classify(), Fp::Zero)); | ||
assert!(matches!(neg_zero.classify(), Fp::Zero)); | ||
assert!(matches!(1f32.classify(), Fp::Normal)); |
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.
Same here, this isn't the right type.
If it makes things easier you could add ZERO
, ONE
, NEG_ZERO
and NEG_ONE
to the trait since those specific values are used in multiple functions.
261da66
to
79769f2
Compare
Oof, thanks for catching those. Should be fixed now, and I've squashed the fixes into the appropriate original commits. It seems like keeping the commit history clean is important here. I'm curious about the motivation: are the PR commits not squashed when merging into master? @rustbot review |
They are not, the option would be nice but unfortunately Bors doesn't support it. Feel free to squash this if you get the chance before Bors picks it up since the commits are pretty tiny. No worries if you don't get to it since at least the history is clean. @bors r+ |
…=tgross35 Move several float tests to floats/mod.rs This PR moves several tests to `floats/mod.rs`, as discussed in rust-lang#141726. The tests moved are: - `test_num_f*` - `test_infinity` - `test_neg_infinity` - `test_zero` - `test_neg_zero` - `test_one` - `test_is_nan` - `test_is_infinite` - `test_is_finite` - `test_is_normal` - `test_classify` Each test is its own commit, so it may be easiest to review each commit individually. r? tgross35
Rollup of 17 pull requests Successful merges: - #142885 (core: Add `BorrowedCursor::with_unfilled_buf`) - #143217 (Port #[link_ordinal] to the new attribute parsing infrastructure) - #143355 (wrapping shift: remove first bitmask and table) - #143448 (remote-test-client: Exit code `128 + <signal-number>` instead of `3`) - #143681 (bootstrap/miri: avoid rebuilds for test builds) - #143710 (Updates to random number generation APIs) - #143724 (Tidy cleanup) - #143738 (Move several float tests to floats/mod.rs) - #143820 (Fixed a core crate compilation failure when enabling the `optimize_for_size` feature on some targets) - #143850 (Compiletest: Simplify {Html,Json}DocCk directive handling) - #143855 (Port `#[omit_gdb_pretty_printer_section]` to the new attribute parsing) - #143868 (warn on align on fields to avoid breaking changes) - #143875 (update issue number for `const_trait_impl`) - #143881 (Use zero for initialized Once state) - #143887 (Run bootstrap tests sooner in the `x test` pipeline) - #143893 (Don't require `eh_personality` lang item on targets that have a personality) - #143901 (Region constraint nits) Failed merges: - #143878 (Port `#[pointee]` to the new attribute parsing infrastructure) - #143891 (Port `#[coverage]` to the new attribute system) r? `@ghost` `@rustbot` modify labels: rollup
This PR moves several tests to
floats/mod.rs
, as discussed in #141726. The tests moved are:test_num_f*
test_infinity
test_neg_infinity
test_zero
test_neg_zero
test_one
test_is_nan
test_is_infinite
test_is_finite
test_is_normal
test_classify
Each test is its own commit, so it may be easiest to review each commit individually.
r? tgross35