diff options
Diffstat (limited to 'vendor/num-traits/src/ops')
-rw-r--r-- | vendor/num-traits/src/ops/bytes.rs | 403 | ||||
-rw-r--r-- | vendor/num-traits/src/ops/checked.rs | 20 | ||||
-rw-r--r-- | vendor/num-traits/src/ops/euclid.rs | 36 | ||||
-rw-r--r-- | vendor/num-traits/src/ops/mod.rs | 1 | ||||
-rw-r--r-- | vendor/num-traits/src/ops/mul_add.rs | 24 | ||||
-rw-r--r-- | vendor/num-traits/src/ops/overflowing.rs | 12 | ||||
-rw-r--r-- | vendor/num-traits/src/ops/saturating.rs | 11 | ||||
-rw-r--r-- | vendor/num-traits/src/ops/wrapping.rs | 22 |
8 files changed, 441 insertions, 88 deletions
diff --git a/vendor/num-traits/src/ops/bytes.rs b/vendor/num-traits/src/ops/bytes.rs new file mode 100644 index 000000000..4df9ecd08 --- /dev/null +++ b/vendor/num-traits/src/ops/bytes.rs @@ -0,0 +1,403 @@ +use core::borrow::{Borrow, BorrowMut}; +use core::cmp::{Eq, Ord, PartialEq, PartialOrd}; +use core::fmt::Debug; +use core::hash::Hash; +#[cfg(not(has_int_to_from_bytes))] +use core::mem::transmute; + +pub trait NumBytes: + Debug + + AsRef<[u8]> + + AsMut<[u8]> + + PartialEq + + Eq + + PartialOrd + + Ord + + Hash + + Borrow<[u8]> + + BorrowMut<[u8]> +{ +} + +impl<T> NumBytes for T where + T: Debug + + AsRef<[u8]> + + AsMut<[u8]> + + PartialEq + + Eq + + PartialOrd + + Ord + + Hash + + Borrow<[u8]> + + BorrowMut<[u8]> + + ?Sized +{ +} + +pub trait ToBytes { + type Bytes: NumBytes; + + /// Return the memory representation of this number as a byte array in big-endian byte order. + /// + /// # Examples + /// + /// ``` + /// use num_traits::ToBytes; + /// + /// let bytes = ToBytes::to_be_bytes(&0x12345678u32); + /// assert_eq!(bytes, [0x12, 0x34, 0x56, 0x78]); + /// ``` + fn to_be_bytes(&self) -> Self::Bytes; + + /// Return the memory representation of this number as a byte array in little-endian byte order. + /// + /// # Examples + /// + /// ``` + /// use num_traits::ToBytes; + /// + /// let bytes = ToBytes::to_le_bytes(&0x12345678u32); + /// assert_eq!(bytes, [0x78, 0x56, 0x34, 0x12]); + /// ``` + fn to_le_bytes(&self) -> Self::Bytes; + + /// Return the memory representation of this number as a byte array in native byte order. + /// + /// As the target platform's native endianness is used, + /// portable code should use [`to_be_bytes`] or [`to_le_bytes`], as appropriate, instead. + /// + /// [`to_be_bytes`]: #method.to_be_bytes + /// [`to_le_bytes`]: #method.to_le_bytes + /// + /// # Examples + /// + /// ``` + /// use num_traits::ToBytes; + /// + /// #[cfg(target_endian = "big")] + /// let expected = [0x12, 0x34, 0x56, 0x78]; + /// + /// #[cfg(target_endian = "little")] + /// let expected = [0x78, 0x56, 0x34, 0x12]; + /// + /// let bytes = ToBytes::to_ne_bytes(&0x12345678u32); + /// assert_eq!(bytes, expected) + /// ``` + fn to_ne_bytes(&self) -> Self::Bytes { + #[cfg(target_endian = "big")] + let bytes = self.to_be_bytes(); + #[cfg(target_endian = "little")] + let bytes = self.to_le_bytes(); + bytes + } +} + +pub trait FromBytes: Sized { + type Bytes: NumBytes + ?Sized; + + /// Create a number from its representation as a byte array in big endian. + /// + /// # Examples + /// + /// ``` + /// use num_traits::FromBytes; + /// + /// let value: u32 = FromBytes::from_be_bytes(&[0x12, 0x34, 0x56, 0x78]); + /// assert_eq!(value, 0x12345678); + /// ``` + fn from_be_bytes(bytes: &Self::Bytes) -> Self; + + /// Create a number from its representation as a byte array in little endian. + /// + /// # Examples + /// + /// ``` + /// use num_traits::FromBytes; + /// + /// let value: u32 = FromBytes::from_le_bytes(&[0x78, 0x56, 0x34, 0x12]); + /// assert_eq!(value, 0x12345678); + /// ``` + fn from_le_bytes(bytes: &Self::Bytes) -> Self; + + /// Create a number from its memory representation as a byte array in native endianness. + /// + /// As the target platform's native endianness is used, + /// portable code likely wants to use [`from_be_bytes`] or [`from_le_bytes`], as appropriate instead. + /// + /// [`from_be_bytes`]: #method.from_be_bytes + /// [`from_le_bytes`]: #method.from_le_bytes + /// + /// # Examples + /// + /// ``` + /// use num_traits::FromBytes; + /// + /// #[cfg(target_endian = "big")] + /// let bytes = [0x12, 0x34, 0x56, 0x78]; + /// + /// #[cfg(target_endian = "little")] + /// let bytes = [0x78, 0x56, 0x34, 0x12]; + /// + /// let value: u32 = FromBytes::from_ne_bytes(&bytes); + /// assert_eq!(value, 0x12345678) + /// ``` + fn from_ne_bytes(bytes: &Self::Bytes) -> Self { + #[cfg(target_endian = "big")] + let this = Self::from_be_bytes(bytes); + #[cfg(target_endian = "little")] + let this = Self::from_le_bytes(bytes); + this + } +} + +macro_rules! float_to_from_bytes_impl { + ($T:ty, $L:expr) => { + #[cfg(has_float_to_from_bytes)] + impl ToBytes for $T { + type Bytes = [u8; $L]; + + #[inline] + fn to_be_bytes(&self) -> Self::Bytes { + <$T>::to_be_bytes(*self) + } + + #[inline] + fn to_le_bytes(&self) -> Self::Bytes { + <$T>::to_le_bytes(*self) + } + + #[inline] + fn to_ne_bytes(&self) -> Self::Bytes { + <$T>::to_ne_bytes(*self) + } + } + + #[cfg(has_float_to_from_bytes)] + impl FromBytes for $T { + type Bytes = [u8; $L]; + + #[inline] + fn from_be_bytes(bytes: &Self::Bytes) -> Self { + <$T>::from_be_bytes(*bytes) + } + + #[inline] + fn from_le_bytes(bytes: &Self::Bytes) -> Self { + <$T>::from_le_bytes(*bytes) + } + + #[inline] + fn from_ne_bytes(bytes: &Self::Bytes) -> Self { + <$T>::from_ne_bytes(*bytes) + } + } + + #[cfg(not(has_float_to_from_bytes))] + impl ToBytes for $T { + type Bytes = [u8; $L]; + + #[inline] + fn to_be_bytes(&self) -> Self::Bytes { + ToBytes::to_be_bytes(&self.to_bits()) + } + + #[inline] + fn to_le_bytes(&self) -> Self::Bytes { + ToBytes::to_le_bytes(&self.to_bits()) + } + + #[inline] + fn to_ne_bytes(&self) -> Self::Bytes { + ToBytes::to_ne_bytes(&self.to_bits()) + } + } + + #[cfg(not(has_float_to_from_bytes))] + impl FromBytes for $T { + type Bytes = [u8; $L]; + + #[inline] + fn from_be_bytes(bytes: &Self::Bytes) -> Self { + Self::from_bits(FromBytes::from_be_bytes(bytes)) + } + + #[inline] + fn from_le_bytes(bytes: &Self::Bytes) -> Self { + Self::from_bits(FromBytes::from_le_bytes(bytes)) + } + + #[inline] + fn from_ne_bytes(bytes: &Self::Bytes) -> Self { + Self::from_bits(FromBytes::from_ne_bytes(bytes)) + } + } + }; +} + +macro_rules! int_to_from_bytes_impl { + ($T:ty, $L:expr) => { + #[cfg(has_int_to_from_bytes)] + impl ToBytes for $T { + type Bytes = [u8; $L]; + + #[inline] + fn to_be_bytes(&self) -> Self::Bytes { + <$T>::to_be_bytes(*self) + } + + #[inline] + fn to_le_bytes(&self) -> Self::Bytes { + <$T>::to_le_bytes(*self) + } + + #[inline] + fn to_ne_bytes(&self) -> Self::Bytes { + <$T>::to_ne_bytes(*self) + } + } + + #[cfg(has_int_to_from_bytes)] + impl FromBytes for $T { + type Bytes = [u8; $L]; + + #[inline] + fn from_be_bytes(bytes: &Self::Bytes) -> Self { + <$T>::from_be_bytes(*bytes) + } + + #[inline] + fn from_le_bytes(bytes: &Self::Bytes) -> Self { + <$T>::from_le_bytes(*bytes) + } + + #[inline] + fn from_ne_bytes(bytes: &Self::Bytes) -> Self { + <$T>::from_ne_bytes(*bytes) + } + } + + #[cfg(not(has_int_to_from_bytes))] + impl ToBytes for $T { + type Bytes = [u8; $L]; + + #[inline] + fn to_be_bytes(&self) -> Self::Bytes { + <$T as ToBytes>::to_ne_bytes(&<$T>::to_be(*self)) + } + + #[inline] + fn to_le_bytes(&self) -> Self::Bytes { + <$T as ToBytes>::to_ne_bytes(&<$T>::to_le(*self)) + } + + #[inline] + fn to_ne_bytes(&self) -> Self::Bytes { + unsafe { transmute(*self) } + } + } + + #[cfg(not(has_int_to_from_bytes))] + impl FromBytes for $T { + type Bytes = [u8; $L]; + + #[inline] + fn from_be_bytes(bytes: &Self::Bytes) -> Self { + Self::from_be(<Self as FromBytes>::from_ne_bytes(bytes)) + } + + #[inline] + fn from_le_bytes(bytes: &Self::Bytes) -> Self { + Self::from_le(<Self as FromBytes>::from_ne_bytes(bytes)) + } + + #[inline] + fn from_ne_bytes(bytes: &Self::Bytes) -> Self { + unsafe { transmute(*bytes) } + } + } + }; +} + +int_to_from_bytes_impl!(u8, 1); +int_to_from_bytes_impl!(u16, 2); +int_to_from_bytes_impl!(u32, 4); +int_to_from_bytes_impl!(u64, 8); +int_to_from_bytes_impl!(u128, 16); +#[cfg(target_pointer_width = "64")] +int_to_from_bytes_impl!(usize, 8); +#[cfg(target_pointer_width = "32")] +int_to_from_bytes_impl!(usize, 4); + +int_to_from_bytes_impl!(i8, 1); +int_to_from_bytes_impl!(i16, 2); +int_to_from_bytes_impl!(i32, 4); +int_to_from_bytes_impl!(i64, 8); +int_to_from_bytes_impl!(i128, 16); +#[cfg(target_pointer_width = "64")] +int_to_from_bytes_impl!(isize, 8); +#[cfg(target_pointer_width = "32")] +int_to_from_bytes_impl!(isize, 4); + +float_to_from_bytes_impl!(f32, 4); +float_to_from_bytes_impl!(f64, 8); + +#[cfg(test)] +mod tests { + use super::*; + + macro_rules! check_to_from_bytes { + ($( $ty:ty )+) => {$({ + let n = 1; + let be = <$ty as ToBytes>::to_be_bytes(&n); + let le = <$ty as ToBytes>::to_le_bytes(&n); + let ne = <$ty as ToBytes>::to_ne_bytes(&n); + + assert_eq!(*be.last().unwrap(), 1); + assert_eq!(*le.first().unwrap(), 1); + if cfg!(target_endian = "big") { + assert_eq!(*ne.last().unwrap(), 1); + } else { + assert_eq!(*ne.first().unwrap(), 1); + } + + assert_eq!(<$ty as FromBytes>::from_be_bytes(&be), n); + assert_eq!(<$ty as FromBytes>::from_le_bytes(&le), n); + if cfg!(target_endian = "big") { + assert_eq!(<$ty as FromBytes>::from_ne_bytes(&be), n); + } else { + assert_eq!(<$ty as FromBytes>::from_ne_bytes(&le), n); + } + })+} + } + + #[test] + fn convert_between_int_and_bytes() { + check_to_from_bytes!(u8 u16 u32 u64 u128 usize); + check_to_from_bytes!(i8 i16 i32 i64 i128 isize); + } + + #[test] + fn convert_between_float_and_bytes() { + macro_rules! check_to_from_bytes { + ($( $ty:ty )+) => {$( + let n: $ty = 3.14; + + let be = <$ty as ToBytes>::to_be_bytes(&n); + let le = <$ty as ToBytes>::to_le_bytes(&n); + let ne = <$ty as ToBytes>::to_ne_bytes(&n); + + assert_eq!(<$ty as FromBytes>::from_be_bytes(&be), n); + assert_eq!(<$ty as FromBytes>::from_le_bytes(&le), n); + if cfg!(target_endian = "big") { + assert_eq!(ne, be); + assert_eq!(<$ty as FromBytes>::from_ne_bytes(&be), n); + } else { + assert_eq!(ne, le); + assert_eq!(<$ty as FromBytes>::from_ne_bytes(&le), n); + } + )+} + } + + check_to_from_bytes!(f32 f64); + } +} diff --git a/vendor/num-traits/src/ops/checked.rs b/vendor/num-traits/src/ops/checked.rs index 386557003..da1eb3eae 100644 --- a/vendor/num-traits/src/ops/checked.rs +++ b/vendor/num-traits/src/ops/checked.rs @@ -24,7 +24,6 @@ checked_impl!(CheckedAdd, checked_add, u16); checked_impl!(CheckedAdd, checked_add, u32); checked_impl!(CheckedAdd, checked_add, u64); checked_impl!(CheckedAdd, checked_add, usize); -#[cfg(has_i128)] checked_impl!(CheckedAdd, checked_add, u128); checked_impl!(CheckedAdd, checked_add, i8); @@ -32,7 +31,6 @@ checked_impl!(CheckedAdd, checked_add, i16); checked_impl!(CheckedAdd, checked_add, i32); checked_impl!(CheckedAdd, checked_add, i64); checked_impl!(CheckedAdd, checked_add, isize); -#[cfg(has_i128)] checked_impl!(CheckedAdd, checked_add, i128); /// Performs subtraction that returns `None` instead of wrapping around on underflow. @@ -47,7 +45,6 @@ checked_impl!(CheckedSub, checked_sub, u16); checked_impl!(CheckedSub, checked_sub, u32); checked_impl!(CheckedSub, checked_sub, u64); checked_impl!(CheckedSub, checked_sub, usize); -#[cfg(has_i128)] checked_impl!(CheckedSub, checked_sub, u128); checked_impl!(CheckedSub, checked_sub, i8); @@ -55,7 +52,6 @@ checked_impl!(CheckedSub, checked_sub, i16); checked_impl!(CheckedSub, checked_sub, i32); checked_impl!(CheckedSub, checked_sub, i64); checked_impl!(CheckedSub, checked_sub, isize); -#[cfg(has_i128)] checked_impl!(CheckedSub, checked_sub, i128); /// Performs multiplication that returns `None` instead of wrapping around on underflow or @@ -71,7 +67,6 @@ checked_impl!(CheckedMul, checked_mul, u16); checked_impl!(CheckedMul, checked_mul, u32); checked_impl!(CheckedMul, checked_mul, u64); checked_impl!(CheckedMul, checked_mul, usize); -#[cfg(has_i128)] checked_impl!(CheckedMul, checked_mul, u128); checked_impl!(CheckedMul, checked_mul, i8); @@ -79,7 +74,6 @@ checked_impl!(CheckedMul, checked_mul, i16); checked_impl!(CheckedMul, checked_mul, i32); checked_impl!(CheckedMul, checked_mul, i64); checked_impl!(CheckedMul, checked_mul, isize); -#[cfg(has_i128)] checked_impl!(CheckedMul, checked_mul, i128); /// Performs division that returns `None` instead of panicking on division by zero and instead of @@ -95,7 +89,6 @@ checked_impl!(CheckedDiv, checked_div, u16); checked_impl!(CheckedDiv, checked_div, u32); checked_impl!(CheckedDiv, checked_div, u64); checked_impl!(CheckedDiv, checked_div, usize); -#[cfg(has_i128)] checked_impl!(CheckedDiv, checked_div, u128); checked_impl!(CheckedDiv, checked_div, i8); @@ -103,7 +96,6 @@ checked_impl!(CheckedDiv, checked_div, i16); checked_impl!(CheckedDiv, checked_div, i32); checked_impl!(CheckedDiv, checked_div, i64); checked_impl!(CheckedDiv, checked_div, isize); -#[cfg(has_i128)] checked_impl!(CheckedDiv, checked_div, i128); /// Performs an integral remainder that returns `None` instead of panicking on division by zero and @@ -136,7 +128,6 @@ checked_impl!(CheckedRem, checked_rem, u16); checked_impl!(CheckedRem, checked_rem, u32); checked_impl!(CheckedRem, checked_rem, u64); checked_impl!(CheckedRem, checked_rem, usize); -#[cfg(has_i128)] checked_impl!(CheckedRem, checked_rem, u128); checked_impl!(CheckedRem, checked_rem, i8); @@ -144,7 +135,6 @@ checked_impl!(CheckedRem, checked_rem, i16); checked_impl!(CheckedRem, checked_rem, i32); checked_impl!(CheckedRem, checked_rem, i64); checked_impl!(CheckedRem, checked_rem, isize); -#[cfg(has_i128)] checked_impl!(CheckedRem, checked_rem, i128); macro_rules! checked_impl_unary { @@ -184,7 +174,6 @@ checked_impl_unary!(CheckedNeg, checked_neg, u16); checked_impl_unary!(CheckedNeg, checked_neg, u32); checked_impl_unary!(CheckedNeg, checked_neg, u64); checked_impl_unary!(CheckedNeg, checked_neg, usize); -#[cfg(has_i128)] checked_impl_unary!(CheckedNeg, checked_neg, u128); checked_impl_unary!(CheckedNeg, checked_neg, i8); @@ -192,11 +181,10 @@ checked_impl_unary!(CheckedNeg, checked_neg, i16); checked_impl_unary!(CheckedNeg, checked_neg, i32); checked_impl_unary!(CheckedNeg, checked_neg, i64); checked_impl_unary!(CheckedNeg, checked_neg, isize); -#[cfg(has_i128)] checked_impl_unary!(CheckedNeg, checked_neg, i128); /// Performs a left shift that returns `None` on shifts larger than -/// the type width. +/// or equal to the type width. pub trait CheckedShl: Sized + Shl<u32, Output = Self> { /// Checked shift left. Computes `self << rhs`, returning `None` /// if `rhs` is larger than or equal to the number of bits in `self`. @@ -230,7 +218,6 @@ checked_shift_impl!(CheckedShl, checked_shl, u16); checked_shift_impl!(CheckedShl, checked_shl, u32); checked_shift_impl!(CheckedShl, checked_shl, u64); checked_shift_impl!(CheckedShl, checked_shl, usize); -#[cfg(has_i128)] checked_shift_impl!(CheckedShl, checked_shl, u128); checked_shift_impl!(CheckedShl, checked_shl, i8); @@ -238,11 +225,10 @@ checked_shift_impl!(CheckedShl, checked_shl, i16); checked_shift_impl!(CheckedShl, checked_shl, i32); checked_shift_impl!(CheckedShl, checked_shl, i64); checked_shift_impl!(CheckedShl, checked_shl, isize); -#[cfg(has_i128)] checked_shift_impl!(CheckedShl, checked_shl, i128); /// Performs a right shift that returns `None` on shifts larger than -/// the type width. +/// or equal to the type width. pub trait CheckedShr: Sized + Shr<u32, Output = Self> { /// Checked shift right. Computes `self >> rhs`, returning `None` /// if `rhs` is larger than or equal to the number of bits in `self`. @@ -265,7 +251,6 @@ checked_shift_impl!(CheckedShr, checked_shr, u16); checked_shift_impl!(CheckedShr, checked_shr, u32); checked_shift_impl!(CheckedShr, checked_shr, u64); checked_shift_impl!(CheckedShr, checked_shr, usize); -#[cfg(has_i128)] checked_shift_impl!(CheckedShr, checked_shr, u128); checked_shift_impl!(CheckedShr, checked_shr, i8); @@ -273,5 +258,4 @@ checked_shift_impl!(CheckedShr, checked_shr, i16); checked_shift_impl!(CheckedShr, checked_shr, i32); checked_shift_impl!(CheckedShr, checked_shr, i64); checked_shift_impl!(CheckedShr, checked_shr, isize); -#[cfg(has_i128)] checked_shift_impl!(CheckedShr, checked_shr, i128); diff --git a/vendor/num-traits/src/ops/euclid.rs b/vendor/num-traits/src/ops/euclid.rs index 99b51279f..4547feeaa 100644 --- a/vendor/num-traits/src/ops/euclid.rs +++ b/vendor/num-traits/src/ops/euclid.rs @@ -116,12 +116,8 @@ macro_rules! euclid_uint_impl { )*} } -euclid_int_impl!(isize i8 i16 i32 i64); -euclid_uint_impl!(usize u8 u16 u32 u64); -#[cfg(has_i128)] -euclid_int_impl!(i128); -#[cfg(has_i128)] -euclid_uint_impl!(u128); +euclid_int_impl!(isize i8 i16 i32 i64 i128); +euclid_uint_impl!(usize u8 u16 u32 u64 u128); #[cfg(all(has_div_euclid, feature = "std"))] euclid_forward_impl!(f32 f64); @@ -130,7 +126,7 @@ euclid_forward_impl!(f32 f64); impl Euclid for f32 { #[inline] fn div_euclid(&self, v: &f32) -> f32 { - let q = <f32 as ::float::FloatCore>::trunc(self / v); + let q = <f32 as crate::float::FloatCore>::trunc(self / v); if self % v < 0.0 { return if *v > 0.0 { q - 1.0 } else { q + 1.0 }; } @@ -141,7 +137,7 @@ impl Euclid for f32 { fn rem_euclid(&self, v: &f32) -> f32 { let r = self % v; if r < 0.0 { - r + <f32 as ::float::FloatCore>::abs(*v) + r + <f32 as crate::float::FloatCore>::abs(*v) } else { r } @@ -152,7 +148,7 @@ impl Euclid for f32 { impl Euclid for f64 { #[inline] fn div_euclid(&self, v: &f64) -> f64 { - let q = <f64 as ::float::FloatCore>::trunc(self / v); + let q = <f64 as crate::float::FloatCore>::trunc(self / v); if self % v < 0.0 { return if *v > 0.0 { q - 1.0 } else { q + 1.0 }; } @@ -163,7 +159,7 @@ impl Euclid for f64 { fn rem_euclid(&self, v: &f64) -> f64 { let r = self % v; if r < 0.0 { - r + <f64 as ::float::FloatCore>::abs(*v) + r + <f64 as crate::float::FloatCore>::abs(*v) } else { r } @@ -251,12 +247,8 @@ macro_rules! checked_euclid_uint_impl { )*} } -checked_euclid_int_impl!(isize i8 i16 i32 i64); -checked_euclid_uint_impl!(usize u8 u16 u32 u64); -#[cfg(has_i128)] -checked_euclid_int_impl!(i128); -#[cfg(has_i128)] -checked_euclid_uint_impl!(u128); +checked_euclid_int_impl!(isize i8 i16 i32 i64 i128); +checked_euclid_uint_impl!(usize u8 u16 u32 u64 u128); #[cfg(test)] mod tests { @@ -300,7 +292,7 @@ mod tests { }; } - test_euclid!(isize i8 i16 i32 i64); + test_euclid!(isize i8 i16 i32 i64 i128); } #[test] @@ -312,13 +304,13 @@ mod tests { let x: $t = 12.1; let y: $t = 3.2; assert!(Euclid::div_euclid(&x, &y) * y + Euclid::rem_euclid(&x, &y) - x - <= 46.4 * <$t as ::float::FloatCore>::epsilon()); + <= 46.4 * <$t as crate::float::FloatCore>::epsilon()); assert!(Euclid::div_euclid(&x, &-y) * -y + Euclid::rem_euclid(&x, &-y) - x - <= 46.4 * <$t as ::float::FloatCore>::epsilon()); + <= 46.4 * <$t as crate::float::FloatCore>::epsilon()); assert!(Euclid::div_euclid(&-x, &y) * y + Euclid::rem_euclid(&-x, &y) + x - <= 46.4 * <$t as ::float::FloatCore>::epsilon()); + <= 46.4 * <$t as crate::float::FloatCore>::epsilon()); assert!(Euclid::div_euclid(&-x, &-y) * -y + Euclid::rem_euclid(&-x, &-y) + x - <= 46.4 * <$t as ::float::FloatCore>::epsilon()); + <= 46.4 * <$t as crate::float::FloatCore>::epsilon()); } )+ }; @@ -342,6 +334,6 @@ mod tests { }; } - test_euclid_checked!(isize i8 i16 i32 i64); + test_euclid_checked!(isize i8 i16 i32 i64 i128); } } diff --git a/vendor/num-traits/src/ops/mod.rs b/vendor/num-traits/src/ops/mod.rs index 585879f6f..2128d86a2 100644 --- a/vendor/num-traits/src/ops/mod.rs +++ b/vendor/num-traits/src/ops/mod.rs @@ -1,3 +1,4 @@ +pub mod bytes; pub mod checked; pub mod euclid; pub mod inv; diff --git a/vendor/num-traits/src/ops/mul_add.rs b/vendor/num-traits/src/ops/mul_add.rs index c5835d3d0..51beb5572 100644 --- a/vendor/num-traits/src/ops/mul_add.rs +++ b/vendor/num-traits/src/ops/mul_add.rs @@ -24,13 +24,13 @@ pub trait MulAdd<A = Self, B = Self> { /// The resulting type after applying the fused multiply-add. type Output; - /// Performs the fused multiply-add operation. + /// Performs the fused multiply-add operation `(self * a) + b` fn mul_add(self, a: A, b: B) -> Self::Output; } -/// The fused multiply-add assignment operation. +/// The fused multiply-add assignment operation `*self = (*self * a) + b` pub trait MulAddAssign<A = Self, B = Self> { - /// Performs the fused multiply-add operation. + /// Performs the fused multiply-add assignment operation `*self = (*self * a) + b` fn mul_add_assign(&mut self, a: A, b: B); } @@ -40,7 +40,7 @@ impl MulAdd<f32, f32> for f32 { #[inline] fn mul_add(self, a: Self, b: Self) -> Self::Output { - <Self as ::Float>::mul_add(self, a, b) + <Self as crate::Float>::mul_add(self, a, b) } } @@ -50,7 +50,7 @@ impl MulAdd<f64, f64> for f64 { #[inline] fn mul_add(self, a: Self, b: Self) -> Self::Output { - <Self as ::Float>::mul_add(self, a, b) + <Self as crate::Float>::mul_add(self, a, b) } } @@ -67,15 +67,14 @@ macro_rules! mul_add_impl { )*} } -mul_add_impl!(MulAdd for isize usize i8 u8 i16 u16 i32 u32 i64 u64); -#[cfg(has_i128)] -mul_add_impl!(MulAdd for i128 u128); +mul_add_impl!(MulAdd for isize i8 i16 i32 i64 i128); +mul_add_impl!(MulAdd for usize u8 u16 u32 u64 u128); #[cfg(any(feature = "std", feature = "libm"))] impl MulAddAssign<f32, f32> for f32 { #[inline] fn mul_add_assign(&mut self, a: Self, b: Self) { - *self = <Self as ::Float>::mul_add(*self, a, b) + *self = <Self as crate::Float>::mul_add(*self, a, b) } } @@ -83,7 +82,7 @@ impl MulAddAssign<f32, f32> for f32 { impl MulAddAssign<f64, f64> for f64 { #[inline] fn mul_add_assign(&mut self, a: Self, b: Self) { - *self = <Self as ::Float>::mul_add(*self, a, b) + *self = <Self as crate::Float>::mul_add(*self, a, b) } } @@ -98,9 +97,8 @@ macro_rules! mul_add_assign_impl { )*} } -mul_add_assign_impl!(MulAddAssign for isize usize i8 u8 i16 u16 i32 u32 i64 u64); -#[cfg(has_i128)] -mul_add_assign_impl!(MulAddAssign for i128 u128); +mul_add_assign_impl!(MulAddAssign for isize i8 i16 i32 i64 i128); +mul_add_assign_impl!(MulAddAssign for usize u8 u16 u32 u64 u128); #[cfg(test)] mod tests { diff --git a/vendor/num-traits/src/ops/overflowing.rs b/vendor/num-traits/src/ops/overflowing.rs index 56118a032..c7a35a51c 100644 --- a/vendor/num-traits/src/ops/overflowing.rs +++ b/vendor/num-traits/src/ops/overflowing.rs @@ -1,8 +1,6 @@ use core::ops::{Add, Mul, Sub}; -#[cfg(has_i128)] -use core::{i128, u128}; -use core::{i16, i32, i64, i8, isize}; -use core::{u16, u32, u64, u8, usize}; +use core::{i128, i16, i32, i64, i8, isize}; +use core::{u128, u16, u32, u64, u8, usize}; macro_rules! overflowing_impl { ($trait_name:ident, $method:ident, $t:ty) => { @@ -27,7 +25,6 @@ overflowing_impl!(OverflowingAdd, overflowing_add, u16); overflowing_impl!(OverflowingAdd, overflowing_add, u32); overflowing_impl!(OverflowingAdd, overflowing_add, u64); overflowing_impl!(OverflowingAdd, overflowing_add, usize); -#[cfg(has_i128)] overflowing_impl!(OverflowingAdd, overflowing_add, u128); overflowing_impl!(OverflowingAdd, overflowing_add, i8); @@ -35,7 +32,6 @@ overflowing_impl!(OverflowingAdd, overflowing_add, i16); overflowing_impl!(OverflowingAdd, overflowing_add, i32); overflowing_impl!(OverflowingAdd, overflowing_add, i64); overflowing_impl!(OverflowingAdd, overflowing_add, isize); -#[cfg(has_i128)] overflowing_impl!(OverflowingAdd, overflowing_add, i128); /// Performs substraction with a flag for overflow. @@ -50,7 +46,6 @@ overflowing_impl!(OverflowingSub, overflowing_sub, u16); overflowing_impl!(OverflowingSub, overflowing_sub, u32); overflowing_impl!(OverflowingSub, overflowing_sub, u64); overflowing_impl!(OverflowingSub, overflowing_sub, usize); -#[cfg(has_i128)] overflowing_impl!(OverflowingSub, overflowing_sub, u128); overflowing_impl!(OverflowingSub, overflowing_sub, i8); @@ -58,7 +53,6 @@ overflowing_impl!(OverflowingSub, overflowing_sub, i16); overflowing_impl!(OverflowingSub, overflowing_sub, i32); overflowing_impl!(OverflowingSub, overflowing_sub, i64); overflowing_impl!(OverflowingSub, overflowing_sub, isize); -#[cfg(has_i128)] overflowing_impl!(OverflowingSub, overflowing_sub, i128); /// Performs multiplication with a flag for overflow. @@ -73,7 +67,6 @@ overflowing_impl!(OverflowingMul, overflowing_mul, u16); overflowing_impl!(OverflowingMul, overflowing_mul, u32); overflowing_impl!(OverflowingMul, overflowing_mul, u64); overflowing_impl!(OverflowingMul, overflowing_mul, usize); -#[cfg(has_i128)] overflowing_impl!(OverflowingMul, overflowing_mul, u128); overflowing_impl!(OverflowingMul, overflowing_mul, i8); @@ -81,7 +74,6 @@ overflowing_impl!(OverflowingMul, overflowing_mul, i16); overflowing_impl!(OverflowingMul, overflowing_mul, i32); overflowing_impl!(OverflowingMul, overflowing_mul, i64); overflowing_impl!(OverflowingMul, overflowing_mul, isize); -#[cfg(has_i128)] overflowing_impl!(OverflowingMul, overflowing_mul, i128); #[test] diff --git a/vendor/num-traits/src/ops/saturating.rs b/vendor/num-traits/src/ops/saturating.rs index e39cfd7b6..16a004576 100644 --- a/vendor/num-traits/src/ops/saturating.rs +++ b/vendor/num-traits/src/ops/saturating.rs @@ -28,9 +28,8 @@ macro_rules! deprecated_saturating_impl { )*} } -deprecated_saturating_impl!(Saturating for isize usize i8 u8 i16 u16 i32 u32 i64 u64); -#[cfg(has_i128)] -deprecated_saturating_impl!(Saturating for i128 u128); +deprecated_saturating_impl!(Saturating for isize i8 i16 i32 i64 i128); +deprecated_saturating_impl!(Saturating for usize u8 u16 u32 u64 u128); macro_rules! saturating_impl { ($trait_name:ident, $method:ident, $t:ty) => { @@ -55,7 +54,6 @@ saturating_impl!(SaturatingAdd, saturating_add, u16); saturating_impl!(SaturatingAdd, saturating_add, u32); saturating_impl!(SaturatingAdd, saturating_add, u64); saturating_impl!(SaturatingAdd, saturating_add, usize); -#[cfg(has_i128)] saturating_impl!(SaturatingAdd, saturating_add, u128); saturating_impl!(SaturatingAdd, saturating_add, i8); @@ -63,7 +61,6 @@ saturating_impl!(SaturatingAdd, saturating_add, i16); saturating_impl!(SaturatingAdd, saturating_add, i32); saturating_impl!(SaturatingAdd, saturating_add, i64); saturating_impl!(SaturatingAdd, saturating_add, isize); -#[cfg(has_i128)] saturating_impl!(SaturatingAdd, saturating_add, i128); /// Performs subtraction that saturates at the numeric bounds instead of overflowing. @@ -78,7 +75,6 @@ saturating_impl!(SaturatingSub, saturating_sub, u16); saturating_impl!(SaturatingSub, saturating_sub, u32); saturating_impl!(SaturatingSub, saturating_sub, u64); saturating_impl!(SaturatingSub, saturating_sub, usize); -#[cfg(has_i128)] saturating_impl!(SaturatingSub, saturating_sub, u128); saturating_impl!(SaturatingSub, saturating_sub, i8); @@ -86,7 +82,6 @@ saturating_impl!(SaturatingSub, saturating_sub, i16); saturating_impl!(SaturatingSub, saturating_sub, i32); saturating_impl!(SaturatingSub, saturating_sub, i64); saturating_impl!(SaturatingSub, saturating_sub, isize); -#[cfg(has_i128)] saturating_impl!(SaturatingSub, saturating_sub, i128); /// Performs multiplication that saturates at the numeric bounds instead of overflowing. @@ -101,7 +96,6 @@ saturating_impl!(SaturatingMul, saturating_mul, u16); saturating_impl!(SaturatingMul, saturating_mul, u32); saturating_impl!(SaturatingMul, saturating_mul, u64); saturating_impl!(SaturatingMul, saturating_mul, usize); -#[cfg(has_i128)] saturating_impl!(SaturatingMul, saturating_mul, u128); saturating_impl!(SaturatingMul, saturating_mul, i8); @@ -109,7 +103,6 @@ saturating_impl!(SaturatingMul, saturating_mul, i16); saturating_impl!(SaturatingMul, saturating_mul, i32); saturating_impl!(SaturatingMul, saturating_mul, i64); saturating_impl!(SaturatingMul, saturating_mul, isize); -#[cfg(has_i128)] saturating_impl!(SaturatingMul, saturating_mul, i128); // TODO: add SaturatingNeg for signed integer primitives once the saturating_neg() API is stable. diff --git a/vendor/num-traits/src/ops/wrapping.rs b/vendor/num-traits/src/ops/wrapping.rs index 265b8f3bb..3a8b33116 100644 --- a/vendor/num-traits/src/ops/wrapping.rs +++ b/vendor/num-traits/src/ops/wrapping.rs @@ -32,7 +32,6 @@ wrapping_impl!(WrappingAdd, wrapping_add, u16); wrapping_impl!(WrappingAdd, wrapping_add, u32); wrapping_impl!(WrappingAdd, wrapping_add, u64); wrapping_impl!(WrappingAdd, wrapping_add, usize); -#[cfg(has_i128)] wrapping_impl!(WrappingAdd, wrapping_add, u128); wrapping_impl!(WrappingAdd, wrapping_add, i8); @@ -40,7 +39,6 @@ wrapping_impl!(WrappingAdd, wrapping_add, i16); wrapping_impl!(WrappingAdd, wrapping_add, i32); wrapping_impl!(WrappingAdd, wrapping_add, i64); wrapping_impl!(WrappingAdd, wrapping_add, isize); -#[cfg(has_i128)] wrapping_impl!(WrappingAdd, wrapping_add, i128); /// Performs subtraction that wraps around on overflow. @@ -55,7 +53,6 @@ wrapping_impl!(WrappingSub, wrapping_sub, u16); wrapping_impl!(WrappingSub, wrapping_sub, u32); wrapping_impl!(WrappingSub, wrapping_sub, u64); wrapping_impl!(WrappingSub, wrapping_sub, usize); -#[cfg(has_i128)] wrapping_impl!(WrappingSub, wrapping_sub, u128); wrapping_impl!(WrappingSub, wrapping_sub, i8); @@ -63,7 +60,6 @@ wrapping_impl!(WrappingSub, wrapping_sub, i16); wrapping_impl!(WrappingSub, wrapping_sub, i32); wrapping_impl!(WrappingSub, wrapping_sub, i64); wrapping_impl!(WrappingSub, wrapping_sub, isize); -#[cfg(has_i128)] wrapping_impl!(WrappingSub, wrapping_sub, i128); /// Performs multiplication that wraps around on overflow. @@ -78,7 +74,6 @@ wrapping_impl!(WrappingMul, wrapping_mul, u16); wrapping_impl!(WrappingMul, wrapping_mul, u32); wrapping_impl!(WrappingMul, wrapping_mul, u64); wrapping_impl!(WrappingMul, wrapping_mul, usize); -#[cfg(has_i128)] wrapping_impl!(WrappingMul, wrapping_mul, u128); wrapping_impl!(WrappingMul, wrapping_mul, i8); @@ -86,7 +81,6 @@ wrapping_impl!(WrappingMul, wrapping_mul, i16); wrapping_impl!(WrappingMul, wrapping_mul, i32); wrapping_impl!(WrappingMul, wrapping_mul, i64); wrapping_impl!(WrappingMul, wrapping_mul, isize); -#[cfg(has_i128)] wrapping_impl!(WrappingMul, wrapping_mul, i128); macro_rules! wrapping_unary_impl { @@ -127,14 +121,12 @@ wrapping_unary_impl!(WrappingNeg, wrapping_neg, u16); wrapping_unary_impl!(WrappingNeg, wrapping_neg, u32); wrapping_unary_impl!(WrappingNeg, wrapping_neg, u64); wrapping_unary_impl!(WrappingNeg, wrapping_neg, usize); -#[cfg(has_i128)] wrapping_unary_impl!(WrappingNeg, wrapping_neg, u128); wrapping_unary_impl!(WrappingNeg, wrapping_neg, i8); wrapping_unary_impl!(WrappingNeg, wrapping_neg, i16); wrapping_unary_impl!(WrappingNeg, wrapping_neg, i32); wrapping_unary_impl!(WrappingNeg, wrapping_neg, i64); wrapping_unary_impl!(WrappingNeg, wrapping_neg, isize); -#[cfg(has_i128)] wrapping_unary_impl!(WrappingNeg, wrapping_neg, i128); macro_rules! wrapping_shift_impl { @@ -172,7 +164,6 @@ wrapping_shift_impl!(WrappingShl, wrapping_shl, u16); wrapping_shift_impl!(WrappingShl, wrapping_shl, u32); wrapping_shift_impl!(WrappingShl, wrapping_shl, u64); wrapping_shift_impl!(WrappingShl, wrapping_shl, usize); -#[cfg(has_i128)] wrapping_shift_impl!(WrappingShl, wrapping_shl, u128); wrapping_shift_impl!(WrappingShl, wrapping_shl, i8); @@ -180,7 +171,6 @@ wrapping_shift_impl!(WrappingShl, wrapping_shl, i16); wrapping_shift_impl!(WrappingShl, wrapping_shl, i32); wrapping_shift_impl!(WrappingShl, wrapping_shl, i64); wrapping_shift_impl!(WrappingShl, wrapping_shl, isize); -#[cfg(has_i128)] wrapping_shift_impl!(WrappingShl, wrapping_shl, i128); /// Performs a right shift that does not panic. @@ -207,7 +197,6 @@ wrapping_shift_impl!(WrappingShr, wrapping_shr, u16); wrapping_shift_impl!(WrappingShr, wrapping_shr, u32); wrapping_shift_impl!(WrappingShr, wrapping_shr, u64); wrapping_shift_impl!(WrappingShr, wrapping_shr, usize); -#[cfg(has_i128)] wrapping_shift_impl!(WrappingShr, wrapping_shr, u128); wrapping_shift_impl!(WrappingShr, wrapping_shr, i8); @@ -215,7 +204,6 @@ wrapping_shift_impl!(WrappingShr, wrapping_shr, i16); wrapping_shift_impl!(WrappingShr, wrapping_shr, i32); wrapping_shift_impl!(WrappingShr, wrapping_shr, i64); wrapping_shift_impl!(WrappingShr, wrapping_shr, isize); -#[cfg(has_i128)] wrapping_shift_impl!(WrappingShr, wrapping_shr, i128); // Well this is a bit funny, but all the more appropriate. @@ -297,8 +285,7 @@ fn test_wrapping_traits() { assert_eq!(wrapping_add(255, 1), (Wrapping(255u8) + Wrapping(1u8)).0); assert_eq!(wrapping_sub(0, 1), (Wrapping(0u8) - Wrapping(1u8)).0); assert_eq!(wrapping_mul(255, 2), (Wrapping(255u8) * Wrapping(2u8)).0); - // TODO: Test for Wrapping::Neg. Not possible yet since core::ops::Neg was - // only added to core::num::Wrapping<_> in Rust 1.10. + assert_eq!(wrapping_neg(255), (-Wrapping(255u8)).0); assert_eq!(wrapping_shl(255, 8), (Wrapping(255u8) << 8).0); assert_eq!(wrapping_shr(255, 8), (Wrapping(255u8) >> 8).0); } @@ -321,8 +308,11 @@ fn wrapping_is_wrappingmul() { require_wrappingmul(&Wrapping(42)); } -// TODO: Test for Wrapping::Neg. Not possible yet since core::ops::Neg was -// only added to core::num::Wrapping<_> in Rust 1.10. +#[test] +fn wrapping_is_wrappingneg() { + fn require_wrappingneg<T: WrappingNeg>(_: &T) {} + require_wrappingneg(&Wrapping(42)); +} #[test] fn wrapping_is_wrappingshl() { |