Automatically detect support for i128/u128

This commit is contained in:
Josh Stone 2018-05-11 15:50:48 -07:00
parent 4e136ddc85
commit 51f6c57c4b
15 changed files with 119 additions and 81 deletions

View File

@ -10,9 +10,10 @@ repository = "https://github.com/rust-num/num-traits"
name = "num-traits"
version = "0.2.3"
readme = "README.md"
build = "build.rs"
[package.metadata.docs.rs]
all-features = true
features = ["std"]
[dependencies]

View File

@ -38,7 +38,9 @@ The `Float` and `Real` traits are only available when `std` is enabled. The
and `f64` also require `std`, as do implementations of signed and floating-
point exponents in `Pow`.
Implementations for `i128` and `u128` are only available when `i128` is enabled.
Implementations for `i128` and `u128` are only available with Rust 1.26 and
later. The build script automatically detects this, but you can make it
mandatory by enabling the `i128` crate feature.
## Releases

35
build.rs Normal file
View File

@ -0,0 +1,35 @@
use std::env;
use std::io::Write;
use std::process::{Command, Stdio};
fn main() {
if probe("fn main() { 0i128; }") {
println!("cargo:rustc-cfg=has_i128");
} else if env::var_os("CARGO_FEATURE_I128").is_some() {
panic!("i128 support was not detected!");
}
}
/// Test if a code snippet can be compiled
fn probe(code: &str) -> bool {
let rustc = env::var_os("RUSTC").unwrap_or_else(|| "rustc".into());
let out_dir = env::var_os("OUT_DIR").expect("environment variable OUT_DIR");
let mut child = Command::new(rustc)
.arg("--out-dir")
.arg(out_dir)
.arg("--emit=obj")
.arg("-")
.stdin(Stdio::piped())
.spawn()
.expect("rustc probe");
child
.stdin
.as_mut()
.expect("rustc stdin")
.write_all(code.as_bytes())
.expect("write rustc stdin");
child.wait().expect("rustc probe").success()
}

View File

@ -2,7 +2,7 @@ use core::{usize, u8, u16, u32, u64};
use core::{isize, i8, i16, i32, i64};
use core::{f32, f64};
use core::num::Wrapping;
#[cfg(feature = "i128")]
#[cfg(has_i128)]
use core::{i128, u128};
/// Numbers which have upper and lower bounds
@ -31,7 +31,7 @@ bounded_impl!(u8, u8::MIN, u8::MAX);
bounded_impl!(u16, u16::MIN, u16::MAX);
bounded_impl!(u32, u32::MIN, u32::MAX);
bounded_impl!(u64, u64::MIN, u64::MAX);
#[cfg(feature = "i128")]
#[cfg(has_i128)]
bounded_impl!(u128, u128::MIN, u128::MAX);
bounded_impl!(isize, isize::MIN, isize::MAX);
@ -39,7 +39,7 @@ bounded_impl!(i8, i8::MIN, i8::MAX);
bounded_impl!(i16, i16::MIN, i16::MAX);
bounded_impl!(i32, i32::MIN, i32::MAX);
bounded_impl!(i64, i64::MIN, i64::MAX);
#[cfg(feature = "i128")]
#[cfg(has_i128)]
bounded_impl!(i128, i128::MIN, i128::MAX);
impl<T: Bounded> Bounded for Wrapping<T> {
@ -97,7 +97,7 @@ fn wrapping_bounded() {
test_wrapping_bounded!(usize u8 u16 u32 u64 isize i8 i16 i32 i64);
}
#[cfg(feature = "i128")]
#[cfg(has_i128)]
#[test]
fn wrapping_bounded_i128() {
macro_rules! test_wrapping_bounded {

View File

@ -3,7 +3,7 @@ use core::{u8, u16, u32, u64, usize};
use core::{f32, f64};
use core::mem::size_of;
use core::num::Wrapping;
#[cfg(feature = "i128")]
#[cfg(has_i128)]
use core::{i128, u128};
use float::FloatCore;
@ -44,7 +44,7 @@ pub trait ToPrimitive {
/// The default implementation converts through `to_i64()`. Types implementing
/// this trait should override this method if they can represent a greater range.
#[inline]
#[cfg(feature = "i128")]
#[cfg(has_i128)]
fn to_i128(&self) -> Option<i128> {
self.to_i64().map(From::from)
}
@ -84,7 +84,7 @@ pub trait ToPrimitive {
/// The default implementation converts through `to_u64()`. Types implementing
/// this trait should override this method if they can represent a greater range.
#[inline]
#[cfg(feature = "i128")]
#[cfg(has_i128)]
fn to_u128(&self) -> Option<u128> {
self.to_u64().map(From::from)
}
@ -142,7 +142,7 @@ macro_rules! impl_to_primitive_int {
fn to_i16 -> i16;
fn to_i32 -> i32;
fn to_i64 -> i64;
#[cfg(feature = "i128")]
#[cfg(has_i128)]
fn to_i128 -> i128;
}
@ -152,7 +152,7 @@ macro_rules! impl_to_primitive_int {
fn to_u16 -> u16;
fn to_u32 -> u32;
fn to_u64 -> u64;
#[cfg(feature = "i128")]
#[cfg(has_i128)]
fn to_u128 -> u128;
}
@ -169,7 +169,7 @@ impl_to_primitive_int!(i8);
impl_to_primitive_int!(i16);
impl_to_primitive_int!(i32);
impl_to_primitive_int!(i64);
#[cfg(feature = "i128")]
#[cfg(has_i128)]
impl_to_primitive_int!(i128);
macro_rules! impl_to_primitive_uint_to_int {
@ -211,7 +211,7 @@ macro_rules! impl_to_primitive_uint {
fn to_i16 -> i16;
fn to_i32 -> i32;
fn to_i64 -> i64;
#[cfg(feature = "i128")]
#[cfg(has_i128)]
fn to_i128 -> i128;
}
@ -221,7 +221,7 @@ macro_rules! impl_to_primitive_uint {
fn to_u16 -> u16;
fn to_u32 -> u32;
fn to_u64 -> u64;
#[cfg(feature = "i128")]
#[cfg(has_i128)]
fn to_u128 -> u128;
}
@ -238,7 +238,7 @@ impl_to_primitive_uint!(u8);
impl_to_primitive_uint!(u16);
impl_to_primitive_uint!(u32);
impl_to_primitive_uint!(u64);
#[cfg(feature = "i128")]
#[cfg(has_i128)]
impl_to_primitive_uint!(u128);
macro_rules! impl_to_primitive_float_to_float {
@ -324,7 +324,7 @@ macro_rules! impl_to_primitive_float {
fn to_i16 -> i16;
fn to_i32 -> i32;
fn to_i64 -> i64;
#[cfg(feature = "i128")]
#[cfg(has_i128)]
fn to_i128 -> i128;
}
@ -334,7 +334,7 @@ macro_rules! impl_to_primitive_float {
fn to_u16 -> u16;
fn to_u32 -> u32;
fn to_u64 -> u64;
#[cfg(feature = "i128")]
#[cfg(has_i128)]
fn to_u128 -> u128;
}
@ -391,7 +391,7 @@ pub trait FromPrimitive: Sized {
/// The default implementation converts through `from_i64()`. Types implementing
/// this trait should override this method if they can represent a greater range.
#[inline]
#[cfg(feature = "i128")]
#[cfg(has_i128)]
fn from_i128(n: i128) -> Option<Self> {
n.to_i64().and_then(FromPrimitive::from_i64)
}
@ -436,7 +436,7 @@ pub trait FromPrimitive: Sized {
/// The default implementation converts through `from_u64()`. Types implementing
/// this trait should override this method if they can represent a greater range.
#[inline]
#[cfg(feature = "i128")]
#[cfg(has_i128)]
fn from_u128(n: u128) -> Option<Self> {
n.to_u64().and_then(FromPrimitive::from_u64)
}
@ -464,14 +464,14 @@ macro_rules! impl_from_primitive {
#[inline] fn from_i16(n: i16) -> Option<$T> { n.$to_ty() }
#[inline] fn from_i32(n: i32) -> Option<$T> { n.$to_ty() }
#[inline] fn from_i64(n: i64) -> Option<$T> { n.$to_ty() }
#[cfg(feature = "i128")]
#[cfg(has_i128)]
#[inline] fn from_i128(n: i128) -> Option<$T> { n.$to_ty() }
#[inline] fn from_u8(n: u8) -> Option<$T> { n.$to_ty() }
#[inline] fn from_u16(n: u16) -> Option<$T> { n.$to_ty() }
#[inline] fn from_u32(n: u32) -> Option<$T> { n.$to_ty() }
#[inline] fn from_u64(n: u64) -> Option<$T> { n.$to_ty() }
#[cfg(feature = "i128")]
#[cfg(has_i128)]
#[inline] fn from_u128(n: u128) -> Option<$T> { n.$to_ty() }
#[inline] fn from_f32(n: f32) -> Option<$T> { n.$to_ty() }
@ -485,14 +485,14 @@ impl_from_primitive!(i8, to_i8);
impl_from_primitive!(i16, to_i16);
impl_from_primitive!(i32, to_i32);
impl_from_primitive!(i64, to_i64);
#[cfg(feature = "i128")]
#[cfg(has_i128)]
impl_from_primitive!(i128, to_i128);
impl_from_primitive!(usize, to_usize);
impl_from_primitive!(u8, to_u8);
impl_from_primitive!(u16, to_u16);
impl_from_primitive!(u32, to_u32);
impl_from_primitive!(u64, to_u64);
#[cfg(feature = "i128")]
#[cfg(has_i128)]
impl_from_primitive!(u128, to_u128);
impl_from_primitive!(f32, to_f32);
impl_from_primitive!(f64, to_f64);
@ -515,7 +515,7 @@ impl<T: ToPrimitive> ToPrimitive for Wrapping<T> {
fn to_i16 -> i16;
fn to_i32 -> i32;
fn to_i64 -> i64;
#[cfg(feature = "i128")]
#[cfg(has_i128)]
fn to_i128 -> i128;
fn to_usize -> usize;
@ -523,7 +523,7 @@ impl<T: ToPrimitive> ToPrimitive for Wrapping<T> {
fn to_u16 -> u16;
fn to_u32 -> u32;
fn to_u64 -> u64;
#[cfg(feature = "i128")]
#[cfg(has_i128)]
fn to_u128 -> u128;
fn to_f32 -> f32;
@ -548,7 +548,7 @@ impl<T: FromPrimitive> FromPrimitive for Wrapping<T> {
fn from_i16(i16);
fn from_i32(i32);
fn from_i64(i64);
#[cfg(feature = "i128")]
#[cfg(has_i128)]
fn from_i128(i128);
fn from_usize(usize);
@ -556,7 +556,7 @@ impl<T: FromPrimitive> FromPrimitive for Wrapping<T> {
fn from_u16(u16);
fn from_u32(u32);
fn from_u64(u64);
#[cfg(feature = "i128")]
#[cfg(has_i128)]
fn from_u128(u128);
fn from_f32(f32);
@ -605,14 +605,14 @@ impl_num_cast!(u8, to_u8);
impl_num_cast!(u16, to_u16);
impl_num_cast!(u32, to_u32);
impl_num_cast!(u64, to_u64);
#[cfg(feature = "i128")]
#[cfg(has_i128)]
impl_num_cast!(u128, to_u128);
impl_num_cast!(usize, to_usize);
impl_num_cast!(i8, to_i8);
impl_num_cast!(i16, to_i16);
impl_num_cast!(i32, to_i32);
impl_num_cast!(i64, to_i64);
#[cfg(feature = "i128")]
#[cfg(has_i128)]
impl_num_cast!(i128, to_i128);
impl_num_cast!(isize, to_isize);
impl_num_cast!(f32, to_f32);
@ -680,9 +680,9 @@ macro_rules! impl_as_primitive {
($T: ty => { $( $U: ty ),* } ) => {
impl_as_primitive!(@ $T => { $( $U ),* });
impl_as_primitive!(@ $T => { u8, u16, u32, u64, usize });
impl_as_primitive!(@ $T => #[cfg(feature = "i128")] impl u128);
impl_as_primitive!(@ $T => #[cfg(has_i128)] impl u128);
impl_as_primitive!(@ $T => { i8, i16, i32, i64, isize });
impl_as_primitive!(@ $T => #[cfg(feature = "i128")] impl i128);
impl_as_primitive!(@ $T => #[cfg(has_i128)] impl i128);
};
}
@ -694,9 +694,9 @@ impl_as_primitive!(u32 => { f32, f64 });
impl_as_primitive!(i32 => { f32, f64 });
impl_as_primitive!(u64 => { f32, f64 });
impl_as_primitive!(i64 => { f32, f64 });
#[cfg(feature = "i128")]
#[cfg(has_i128)]
impl_as_primitive!(u128 => { f32, f64 });
#[cfg(feature = "i128")]
#[cfg(has_i128)]
impl_as_primitive!(i128 => { f32, f64 });
impl_as_primitive!(usize => { f32, f64 });
impl_as_primitive!(isize => { f32, f64 });

View File

@ -41,7 +41,7 @@ zero_impl!(u8, 0);
zero_impl!(u16, 0);
zero_impl!(u32, 0);
zero_impl!(u64, 0);
#[cfg(feature = "i128")]
#[cfg(has_i128)]
zero_impl!(u128, 0);
zero_impl!(isize, 0);
@ -49,7 +49,7 @@ zero_impl!(i8, 0);
zero_impl!(i16, 0);
zero_impl!(i32, 0);
zero_impl!(i64, 0);
#[cfg(feature = "i128")]
#[cfg(has_i128)]
zero_impl!(i128, 0);
zero_impl!(f32, 0.0);
@ -109,7 +109,7 @@ one_impl!(u8, 1);
one_impl!(u16, 1);
one_impl!(u32, 1);
one_impl!(u64, 1);
#[cfg(feature = "i128")]
#[cfg(has_i128)]
one_impl!(u128, 1);
one_impl!(isize, 1);
@ -117,7 +117,7 @@ one_impl!(i8, 1);
one_impl!(i16, 1);
one_impl!(i32, 1);
one_impl!(i64, 1);
#[cfg(feature = "i128")]
#[cfg(has_i128)]
one_impl!(i128, 1);
one_impl!(f32, 1.0);

View File

@ -368,13 +368,13 @@ prim_int_impl!(u8, i8, u8);
prim_int_impl!(u16, i16, u16);
prim_int_impl!(u32, i32, u32);
prim_int_impl!(u64, i64, u64);
#[cfg(feature = "i128")]
#[cfg(has_i128)]
prim_int_impl!(u128, i128, u128);
prim_int_impl!(usize, isize, usize);
prim_int_impl!(i8, i8, u8);
prim_int_impl!(i16, i16, u16);
prim_int_impl!(i32, i32, u32);
prim_int_impl!(i64, i64, u64);
#[cfg(feature = "i128")]
#[cfg(has_i128)]
prim_int_impl!(i128, i128, u128);
prim_int_impl!(isize, isize, usize);

View File

@ -160,7 +160,7 @@ macro_rules! int_trait_impl {
)*)
}
int_trait_impl!(Num for usize u8 u16 u32 u64 isize i8 i16 i32 i64);
#[cfg(feature = "i128")]
#[cfg(has_i128)]
int_trait_impl!(Num for u128 i128);
impl<T: Num> Num for Wrapping<T>

View File

@ -24,7 +24,7 @@ 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(feature = "i128")]
#[cfg(has_i128)]
checked_impl!(CheckedAdd, checked_add, u128);
checked_impl!(CheckedAdd, checked_add, i8);
@ -32,7 +32,7 @@ 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(feature = "i128")]
#[cfg(has_i128)]
checked_impl!(CheckedAdd, checked_add, i128);
/// Performs subtraction that returns `None` instead of wrapping around on underflow.
@ -47,7 +47,7 @@ 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(feature = "i128")]
#[cfg(has_i128)]
checked_impl!(CheckedSub, checked_sub, u128);
checked_impl!(CheckedSub, checked_sub, i8);
@ -55,7 +55,7 @@ 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(feature = "i128")]
#[cfg(has_i128)]
checked_impl!(CheckedSub, checked_sub, i128);
/// Performs multiplication that returns `None` instead of wrapping around on underflow or
@ -71,7 +71,7 @@ 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(feature = "i128")]
#[cfg(has_i128)]
checked_impl!(CheckedMul, checked_mul, u128);
checked_impl!(CheckedMul, checked_mul, i8);
@ -79,7 +79,7 @@ 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(feature = "i128")]
#[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 +95,7 @@ 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(feature = "i128")]
#[cfg(has_i128)]
checked_impl!(CheckedDiv, checked_div, u128);
checked_impl!(CheckedDiv, checked_div, i8);
@ -103,7 +103,7 @@ 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(feature = "i128")]
#[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 +136,7 @@ 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(feature = "i128")]
#[cfg(has_i128)]
checked_impl!(CheckedRem, checked_rem, u128);
checked_impl!(CheckedRem, checked_rem, i8);
@ -144,7 +144,7 @@ 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(feature = "i128")]
#[cfg(has_i128)]
checked_impl!(CheckedRem, checked_rem, i128);
macro_rules! checked_impl_unary {
@ -184,7 +184,7 @@ 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(feature = "i128")]
#[cfg(has_i128)]
checked_impl_unary!(CheckedNeg, checked_neg, u128);
checked_impl_unary!(CheckedNeg, checked_neg, i8);
@ -192,7 +192,7 @@ 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(feature = "i128")]
#[cfg(has_i128)]
checked_impl_unary!(CheckedNeg, checked_neg, i128);
/// Performs a left shift that returns `None` on overflow.
@ -229,7 +229,7 @@ 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(feature = "i128")]
#[cfg(has_i128)]
checked_shift_impl!(CheckedShl, checked_shl, u128);
checked_shift_impl!(CheckedShl, checked_shl, i8);
@ -237,7 +237,7 @@ 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(feature = "i128")]
#[cfg(has_i128)]
checked_shift_impl!(CheckedShl, checked_shl, i128);
/// Performs a right shift that returns `None` on overflow.
@ -263,7 +263,7 @@ 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(feature = "i128")]
#[cfg(has_i128)]
checked_shift_impl!(CheckedShr, checked_shr, u128);
checked_shift_impl!(CheckedShr, checked_shr, i8);
@ -271,5 +271,5 @@ 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(feature = "i128")]
#[cfg(has_i128)]
checked_shift_impl!(CheckedShr, checked_shr, i128);

View File

@ -67,7 +67,7 @@ macro_rules! mul_add_impl {
}
mul_add_impl!(MulAdd for isize usize i8 u8 i16 u16 i32 u32 i64 u64);
#[cfg(feature = "i128")]
#[cfg(has_i128)]
mul_add_impl!(MulAdd for i128 u128);
#[cfg(feature = "std")]
@ -98,7 +98,7 @@ macro_rules! mul_add_assign_impl {
}
mul_add_assign_impl!(MulAddAssign for isize usize i8 u8 i16 u16 i32 u32 i64 u64);
#[cfg(feature = "i128")]
#[cfg(has_i128)]
mul_add_assign_impl!(MulAddAssign for i128 u128);
#[cfg(test)]

View File

@ -26,5 +26,5 @@ macro_rules! saturating_impl {
}
saturating_impl!(Saturating for isize usize i8 u8 i16 u16 i32 u32 i64 u64);
#[cfg(feature = "i128")]
#[cfg(has_i128)]
saturating_impl!(Saturating for i128 u128);

View File

@ -32,7 +32,7 @@ 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(feature = "i128")]
#[cfg(has_i128)]
wrapping_impl!(WrappingAdd, wrapping_add, u128);
wrapping_impl!(WrappingAdd, wrapping_add, i8);
@ -40,7 +40,7 @@ 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(feature = "i128")]
#[cfg(has_i128)]
wrapping_impl!(WrappingAdd, wrapping_add, i128);
/// Performs subtraction that wraps around on overflow.
@ -55,7 +55,7 @@ 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(feature = "i128")]
#[cfg(has_i128)]
wrapping_impl!(WrappingSub, wrapping_sub, u128);
wrapping_impl!(WrappingSub, wrapping_sub, i8);
@ -63,7 +63,7 @@ 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(feature = "i128")]
#[cfg(has_i128)]
wrapping_impl!(WrappingSub, wrapping_sub, i128);
/// Performs multiplication that wraps around on overflow.
@ -78,7 +78,7 @@ 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(feature = "i128")]
#[cfg(has_i128)]
wrapping_impl!(WrappingMul, wrapping_mul, u128);
wrapping_impl!(WrappingMul, wrapping_mul, i8);
@ -86,7 +86,7 @@ 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(feature = "i128")]
#[cfg(has_i128)]
wrapping_impl!(WrappingMul, wrapping_mul, i128);
// Well this is a bit funny, but all the more appropriate.

View File

@ -99,22 +99,22 @@ pow_impl!(i64, u16, u32, i64::pow);
pow_impl!(i64, u32, u32, i64::pow);
pow_impl!(i64, usize);
#[cfg(feature = "i128")]
#[cfg(has_i128)]
pow_impl!(u128, u8, u32, u128::pow);
#[cfg(feature = "i128")]
#[cfg(has_i128)]
pow_impl!(u128, u16, u32, u128::pow);
#[cfg(feature = "i128")]
#[cfg(has_i128)]
pow_impl!(u128, u32, u32, u128::pow);
#[cfg(feature = "i128")]
#[cfg(has_i128)]
pow_impl!(u128, usize);
#[cfg(feature = "i128")]
#[cfg(has_i128)]
pow_impl!(i128, u8, u32, i128::pow);
#[cfg(feature = "i128")]
#[cfg(has_i128)]
pow_impl!(i128, u16, u32, i128::pow);
#[cfg(feature = "i128")]
#[cfg(has_i128)]
pow_impl!(i128, u32, u32, i128::pow);
#[cfg(feature = "i128")]
#[cfg(has_i128)]
pow_impl!(i128, usize);
pow_impl!(usize, u8, u32, usize::pow);
@ -133,9 +133,9 @@ pow_impl!(Wrapping<u32>);
pow_impl!(Wrapping<i32>);
pow_impl!(Wrapping<u64>);
pow_impl!(Wrapping<i64>);
#[cfg(feature = "i128")]
#[cfg(has_i128)]
pow_impl!(Wrapping<u128>);
#[cfg(feature = "i128")]
#[cfg(has_i128)]
pow_impl!(Wrapping<i128>);
pow_impl!(Wrapping<usize>);
pow_impl!(Wrapping<isize>);

View File

@ -74,7 +74,7 @@ macro_rules! signed_impl {
signed_impl!(isize i8 i16 i32 i64);
#[cfg(feature = "i128")]
#[cfg(has_i128)]
signed_impl!(i128);
impl<T: Signed> Signed for Wrapping<T> where Wrapping<T>: Num + Neg<Output=Wrapping<T>>
@ -186,7 +186,7 @@ macro_rules! empty_trait_impl {
}
empty_trait_impl!(Unsigned for usize u8 u16 u32 u64);
#[cfg(feature = "i128")]
#[cfg(has_i128)]
empty_trait_impl!(Unsigned for u128);
impl<T: Unsigned> Unsigned for Wrapping<T> where Wrapping<T>: Num {}

View File

@ -13,7 +13,7 @@ use num_traits::cast::*;
use core::{i8, i16, i32, i64, isize};
use core::{u8, u16, u32, u64, usize};
use core::{f32, f64};
#[cfg(feature = "i128")]
#[cfg(has_i128)]
use core::{i128, u128};
use core::mem;
@ -144,7 +144,7 @@ fn cast_to_unsigned_int_checks_overflow() {
}
#[test]
#[cfg(feature = "i128")]
#[cfg(has_i128)]
fn cast_to_i128_checks_overflow() {
let big_f: f64 = 1.0e123;
let normal_f: f64 = 1.0;
@ -240,7 +240,7 @@ fn cast_float_to_int_edge_cases() {
}
#[test]
#[cfg(feature = "i128")]
#[cfg(has_i128)]
fn cast_float_to_i128_edge_cases() {
float_test_edge!(f32 -> i128 u128);
float_test_edge!(f64 -> i128 u128);
@ -299,7 +299,7 @@ fn cast_int_to_int_edge_cases() {
}
#[test]
#[cfg(feature = "i128")]
#[cfg(has_i128)]
fn cast_int_to_128_edge_cases() {
use core::cmp::Ordering::*;