diff options
| author | bors <bors@rust-lang.org> | 2017-06-16 17:52:11 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-06-16 17:52:11 +0000 |
| commit | fe7227f6c8704f0186091085a14fd1027920e4bb (patch) | |
| tree | 8c3cb396146179783cb6d001fa7f4f67c6958575 /src/libcore/tests | |
| parent | b40be00a0cac84d23f51c5c5109c8f824ab19ab3 (diff) | |
| parent | ba6cf1d80ac6f5ff3c36c7f6111197d429369d86 (diff) | |
Auto merge of #42430 - nagisa:core-float, r=alexcrichton
Re-implement float min/max in rust This also adds the relevant implementations into libcore. See #42423
Diffstat (limited to 'src/libcore/tests')
| -rw-r--r-- | src/libcore/tests/lib.rs | 1 | ||||
| -rw-r--r-- | src/libcore/tests/num/mod.rs | 54 |
2 files changed, 55 insertions, 0 deletions
diff --git a/src/libcore/tests/lib.rs b/src/libcore/tests/lib.rs index 77a9307f43e..337f8aa31dc 100644 --- a/src/libcore/tests/lib.rs +++ b/src/libcore/tests/lib.rs @@ -13,6 +13,7 @@ #![feature(box_syntax)] #![feature(char_escape_debug)] #![feature(const_fn)] +#![feature(core_float)] #![feature(core_private_bignum)] #![feature(core_private_diy_float)] #![feature(dec2flt)] diff --git a/src/libcore/tests/num/mod.rs b/src/libcore/tests/num/mod.rs index 8fdcc36a268..f233b649a8f 100644 --- a/src/libcore/tests/num/mod.rs +++ b/src/libcore/tests/num/mod.rs @@ -399,3 +399,57 @@ test_impl_try_from_signed_to_unsigned_err! { test_try_i32u16, i32, u16 } test_impl_try_from_signed_to_unsigned_err! { test_try_i64u8, i64, u8 } test_impl_try_from_signed_to_unsigned_err! { test_try_i64u16, i64, u16 } test_impl_try_from_signed_to_unsigned_err! { test_try_i64u32, i64, u32 } + +macro_rules! test_float { + ($modname: ident, $fty: ty, $inf: expr, $neginf: expr, $nan: expr) => { mod $modname { + use core::num::Float; + // FIXME(nagisa): these tests should test for sign of -0.0 + #[test] + fn min() { + assert_eq!(0.0.min(0.0), 0.0); + assert_eq!((-0.0).min(-0.0), -0.0); + assert_eq!(9.0.min(9.0), 9.0); + assert_eq!((-9.0).min(0.0), -9.0); + assert_eq!(0.0.min(9.0), 0.0); + assert_eq!((-0.0).min(-9.0), -9.0); + assert_eq!($inf.min(9.0), 9.0); + assert_eq!(9.0.min($inf), 9.0); + assert_eq!($inf.min(-9.0), -9.0); + assert_eq!((-9.0).min($inf), -9.0); + assert_eq!($neginf.min(9.0), $neginf); + assert_eq!(9.0.min($neginf), $neginf); + assert_eq!($neginf.min(-9.0), $neginf); + assert_eq!((-9.0).min($neginf), $neginf); + assert_eq!($nan.min(9.0), 9.0); + assert_eq!($nan.min(-9.0), -9.0); + assert_eq!(9.0.min($nan), 9.0); + assert_eq!((-9.0).min($nan), -9.0); + assert!($nan.min($nan).is_nan()); + } + #[test] + fn max() { + assert_eq!(0.0.max(0.0), 0.0); + assert_eq!((-0.0).max(-0.0), -0.0); + assert_eq!(9.0.max(9.0), 9.0); + assert_eq!((-9.0).max(0.0), 0.0); + assert_eq!(0.0.max(9.0), 9.0); + assert_eq!((-0.0).max(-9.0), -0.0); + assert_eq!($inf.max(9.0), $inf); + assert_eq!(9.0.max($inf), $inf); + assert_eq!($inf.max(-9.0), $inf); + assert_eq!((-9.0).max($inf), $inf); + assert_eq!($neginf.max(9.0), 9.0); + assert_eq!(9.0.max($neginf), 9.0); + assert_eq!($neginf.max(-9.0), -9.0); + assert_eq!((-9.0).max($neginf), -9.0); + assert_eq!($nan.max(9.0), 9.0); + assert_eq!($nan.max(-9.0), -9.0); + assert_eq!(9.0.max($nan), 9.0); + assert_eq!((-9.0).max($nan), -9.0); + assert!($nan.max($nan).is_nan()); + } + } } +} + +test_float!(f32, f32, ::core::f32::INFINITY, ::core::f32::NEG_INFINITY, ::core::f32::NAN); +test_float!(f64, f64, ::core::f64::INFINITY, ::core::f64::NEG_INFINITY, ::core::f64::NAN); |
