-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Unify and deduplicate From<T> float tests #150611
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?
Unify and deduplicate From<T> float tests #150611
Conversation
This comment has been minimized.
This comment has been minimized.
3f94742 to
357ec46
Compare
|
@rustbot reroll |
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.
| assert_biteq!(f16::from(u8::MAX), 255.0); | ||
| assert_biteq!(f16::from(i8::MIN), -128.0); | ||
| assert_biteq!(f16::from(42_i8), 42.0); | ||
| assert_biteq!(f16::from(i8::MAX), 127.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.
Why only the bools, and not the rest of the cases here?
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.
Probably because they want to know whether they are on the right track, given this is their first PR here.
Are you saying they are on the right track and should add more?
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.
Tried to keep it minimal at first.
Added the u8/i8 cases now
|
Reminder, once the PR becomes ready for a review, use |
|
I believe this will be superseded by #148206 |
|
@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.
| float_test! { | ||
| name: from_bool, | ||
| attrs: { | ||
| f16: #[cfg(any(miri, target_has_reliable_f16))], | ||
| f128: #[cfg(any(miri, target_has_reliable_f128))], | ||
| }, | ||
| test<Float> { | ||
| assert_biteq!(Float::from(false), Float::ZERO); | ||
| assert_biteq!(Float::from(true), Float::ONE); | ||
| } | ||
| } | ||
|
|
||
| float_test! { | ||
| name: from_u8, | ||
| attrs: { | ||
| f16: #[cfg(any(miri, target_has_reliable_f16))], | ||
| f128: #[cfg(any(miri, target_has_reliable_f128))], | ||
| }, | ||
| test<Float> { | ||
| assert_biteq!(Float::from(u8::MIN), Float::ZERO); | ||
| assert_biteq!(Float::from(42_u8), 42.0); | ||
| assert_biteq!(Float::from(u8::MAX), 255.0); | ||
| } | ||
| } | ||
|
|
||
| float_test! { | ||
| name: from_i8, | ||
| attrs: { | ||
| f16: #[cfg(any(miri, target_has_reliable_f16))], | ||
| f128: #[cfg(any(miri, target_has_reliable_f128))], | ||
| }, | ||
| test<Float> { | ||
| assert_biteq!(Float::from(i8::MIN), -128.0); | ||
| assert_biteq!(Float::from(42_i8), 42.0); | ||
| assert_biteq!(Float::from(i8::MAX), 127.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.
No need to split the tests up, leaving them in a single function as they are currently is fine.
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.
I kept bool/u8/i8 together, but had to split u16/u32 since f16/f32 lack those From impls, otherwise it fails with E0277.
| assert_biteq!(f128::from(u16::MIN), 0.0); | ||
| assert_biteq!(f128::from(42_u16), 42.0); | ||
| assert_biteq!(f128::from(u16::MAX), 65535.0); | ||
| assert_biteq!(f128::from(i16::MIN), -32768.0); | ||
| assert_biteq!(f128::from(42_i16), 42.0); | ||
| assert_biteq!(f128::from(i16::MAX), 32767.0); | ||
| assert_biteq!(f128::from(u32::MIN), 0.0); | ||
| assert_biteq!(f128::from(42_u32), 42.0); | ||
| assert_biteq!(f128::from(u32::MAX), 4294967295.0); | ||
| assert_biteq!(f128::from(i32::MIN), -2147483648.0); | ||
| assert_biteq!(f128::from(42_i32), 42.0); | ||
| assert_biteq!(f128::from(i32::MAX), 2147483647.0); | ||
| // FIXME(f16_f128): Uncomment these tests once the From<{u64,i64}> impls are added. | ||
| // assert_eq!(f128::from(u64::MIN), 0.0); | ||
| // assert_eq!(f128::from(42_u64), 42.0); | ||
| // assert_eq!(f128::from(u64::MAX), 18446744073709551615.0); | ||
| // assert_eq!(f128::from(i64::MIN), -9223372036854775808.0); | ||
| // assert_eq!(f128::from(42_i64), 42.0); | ||
| // assert_eq!(f128::from(i64::MAX), 9223372036854775807.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.
Bring these tests over as well. Just gate them as needed:
if Float::BITS >= 32 {
// ...
}
if Float::BITS >= 64 {
// ...
}
if Float::BITS >= 128 {
// ...
}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.
I see RawFloat has BITS but TestableFloat doesn't, and the f16 lacks From<u16/u32> so trait bounds still fail. Is cfg(false) ok here?
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 entire file can be deleted since it is no longer used. Ditto for f128 with the above change.
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.
Done! Also I'll update the PR title since it's not only From<bool>
|
r? tgross35 |
Co-authored-by: ericinB <[email protected]>
6085df8 to
1123177
Compare
|
@rustbot ready |
cc #141726
Unify the From tests from f16.rs and f128.rs into a single float_test! in mod.rs.