Rollup merge of #150611 - from-bool-float-test, r=tgross35
Unify and deduplicate From<T> float tests cc rust-lang/rust#141726 Unify the From<bool> tests from f16.rs and f128.rs into a single float_test! in mod.rs.
This commit is contained in:
commit
0cef925c52
3 changed files with 75 additions and 88 deletions
|
|
@ -1,50 +0,0 @@
|
|||
// FIXME(f16_f128): only tested on platforms that have symbols and aren't buggy
|
||||
#![cfg(target_has_reliable_f128)]
|
||||
|
||||
use super::assert_biteq;
|
||||
|
||||
// Note these tolerances make sense around zero, but not for more extreme exponents.
|
||||
|
||||
/// Default tolerances. Works for values that should be near precise but not exact. Roughly
|
||||
/// the precision carried by `100 * 100`.
|
||||
#[allow(unused)]
|
||||
const TOL: f128 = 1e-12;
|
||||
|
||||
/// For operations that are near exact, usually not involving math of different
|
||||
/// signs.
|
||||
#[allow(unused)]
|
||||
const TOL_PRECISE: f128 = 1e-28;
|
||||
|
||||
// FIXME(f16_f128,miri): many of these have to be disabled since miri does not yet support
|
||||
// the intrinsics.
|
||||
|
||||
#[test]
|
||||
fn test_from() {
|
||||
assert_biteq!(f128::from(false), 0.0);
|
||||
assert_biteq!(f128::from(true), 1.0);
|
||||
assert_biteq!(f128::from(u8::MIN), 0.0);
|
||||
assert_biteq!(f128::from(42_u8), 42.0);
|
||||
assert_biteq!(f128::from(u8::MAX), 255.0);
|
||||
assert_biteq!(f128::from(i8::MIN), -128.0);
|
||||
assert_biteq!(f128::from(42_i8), 42.0);
|
||||
assert_biteq!(f128::from(i8::MAX), 127.0);
|
||||
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);
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
// FIXME(f16_f128): only tested on platforms that have symbols and aren't buggy
|
||||
#![cfg(target_has_reliable_f16)]
|
||||
|
||||
use super::assert_biteq;
|
||||
|
||||
/// Tolerance for results on the order of 10.0e-2
|
||||
#[allow(unused)]
|
||||
const TOL_N2: f16 = 0.0001;
|
||||
|
||||
/// Tolerance for results on the order of 10.0e+0
|
||||
#[allow(unused)]
|
||||
const TOL_0: f16 = 0.01;
|
||||
|
||||
/// Tolerance for results on the order of 10.0e+2
|
||||
#[allow(unused)]
|
||||
const TOL_P2: f16 = 0.5;
|
||||
|
||||
/// Tolerance for results on the order of 10.0e+4
|
||||
#[allow(unused)]
|
||||
const TOL_P4: f16 = 10.0;
|
||||
|
||||
// FIXME(f16_f128,miri): many of these have to be disabled since miri does not yet support
|
||||
// the intrinsics.
|
||||
|
||||
#[test]
|
||||
fn test_from() {
|
||||
assert_biteq!(f16::from(false), 0.0);
|
||||
assert_biteq!(f16::from(true), 1.0);
|
||||
assert_biteq!(f16::from(u8::MIN), 0.0);
|
||||
assert_biteq!(f16::from(42_u8), 42.0);
|
||||
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);
|
||||
}
|
||||
|
|
@ -375,9 +375,6 @@ macro_rules! float_test {
|
|||
};
|
||||
}
|
||||
|
||||
mod f128;
|
||||
mod f16;
|
||||
|
||||
float_test! {
|
||||
name: num,
|
||||
attrs: {
|
||||
|
|
@ -1582,3 +1579,78 @@ float_test! {
|
|||
assert_biteq!((flt(-3.2)).mul_add(2.4, neg_inf), neg_inf);
|
||||
}
|
||||
}
|
||||
|
||||
float_test! {
|
||||
name: from,
|
||||
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);
|
||||
|
||||
assert_biteq!(Float::from(u8::MIN), Float::ZERO);
|
||||
assert_biteq!(Float::from(42_u8), 42.0);
|
||||
assert_biteq!(Float::from(u8::MAX), 255.0);
|
||||
|
||||
assert_biteq!(Float::from(i8::MIN), -128.0);
|
||||
assert_biteq!(Float::from(42_i8), 42.0);
|
||||
assert_biteq!(Float::from(i8::MAX), 127.0);
|
||||
}
|
||||
}
|
||||
|
||||
float_test! {
|
||||
name: from_u16_i16,
|
||||
attrs: {
|
||||
f16: #[cfg(false)],
|
||||
const f16: #[cfg(false)],
|
||||
f128: #[cfg(any(miri, target_has_reliable_f128))],
|
||||
},
|
||||
test<Float> {
|
||||
assert_biteq!(Float::from(u16::MIN), Float::ZERO);
|
||||
assert_biteq!(Float::from(42_u16), 42.0);
|
||||
assert_biteq!(Float::from(u16::MAX), 65535.0);
|
||||
assert_biteq!(Float::from(i16::MIN), -32768.0);
|
||||
assert_biteq!(Float::from(42_i16), 42.0);
|
||||
assert_biteq!(Float::from(i16::MAX), 32767.0);
|
||||
}
|
||||
}
|
||||
|
||||
float_test! {
|
||||
name: from_u32_i32,
|
||||
attrs: {
|
||||
f16: #[cfg(false)],
|
||||
const f16: #[cfg(false)],
|
||||
f32: #[cfg(false)],
|
||||
const f32: #[cfg(false)],
|
||||
f128: #[cfg(any(miri, target_has_reliable_f128))],
|
||||
},
|
||||
test<Float> {
|
||||
assert_biteq!(Float::from(u32::MIN), Float::ZERO);
|
||||
assert_biteq!(Float::from(42_u32), 42.0);
|
||||
assert_biteq!(Float::from(u32::MAX), 4294967295.0);
|
||||
assert_biteq!(Float::from(i32::MIN), -2147483648.0);
|
||||
assert_biteq!(Float::from(42_i32), 42.0);
|
||||
assert_biteq!(Float::from(i32::MAX), 2147483647.0);
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME(f16_f128): Uncomment and adapt these tests once the From<{u64,i64}> impls are added.
|
||||
// float_test! {
|
||||
// name: from_u64_i64,
|
||||
// attrs: {
|
||||
// f16: #[cfg(false)],
|
||||
// f32: #[cfg(false)],
|
||||
// f64: #[cfg(false)],
|
||||
// f128: #[cfg(any(miri, target_has_reliable_f128))],
|
||||
// },
|
||||
// test<Float> {
|
||||
// assert_biteq!(Float::from(u64::MIN), Float::ZERO);
|
||||
// assert_biteq!(Float::from(42_u64), 42.0);
|
||||
// assert_biteq!(Float::from(u64::MAX), 18446744073709551615.0);
|
||||
// assert_biteq!(Float::from(i64::MIN), -9223372036854775808.0);
|
||||
// assert_biteq!(Float::from(42_i64), 42.0);
|
||||
// assert_biteq!(Float::from(i64::MAX), 9223372036854775807.0);
|
||||
// }
|
||||
// }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue