From 51f6c57c4b2f6e3483164af7cad32690e4013b06 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 11 May 2018 15:50:48 -0700 Subject: [PATCH 1/2] Automatically detect support for i128/u128 --- Cargo.toml | 3 ++- README.md | 4 +++- build.rs | 35 ++++++++++++++++++++++++++++ src/bounds.rs | 8 +++---- src/cast.rs | 54 +++++++++++++++++++++---------------------- src/identities.rs | 8 +++---- src/int.rs | 4 ++-- src/lib.rs | 2 +- src/ops/checked.rs | 32 ++++++++++++------------- src/ops/mul_add.rs | 4 ++-- src/ops/saturating.rs | 2 +- src/ops/wrapping.rs | 12 +++++----- src/pow.rs | 20 ++++++++-------- src/sign.rs | 4 ++-- tests/cast.rs | 8 +++---- 15 files changed, 119 insertions(+), 81 deletions(-) create mode 100644 build.rs diff --git a/Cargo.toml b/Cargo.toml index b183e51..7b01de5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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] diff --git a/README.md b/README.md index 2c16617..d2ea0d0 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..fd60866 --- /dev/null +++ b/build.rs @@ -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() +} diff --git a/src/bounds.rs b/src/bounds.rs index cbc3152..744c5ba 100644 --- a/src/bounds.rs +++ b/src/bounds.rs @@ -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 Bounded for Wrapping { @@ -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 { diff --git a/src/cast.rs b/src/cast.rs index ce21c81..a8c8484 100644 --- a/src/cast.rs +++ b/src/cast.rs @@ -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 { 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 { 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 { 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 { 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 ToPrimitive for Wrapping { 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 ToPrimitive for Wrapping { 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 FromPrimitive for Wrapping { 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 FromPrimitive for Wrapping { 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 }); diff --git a/src/identities.rs b/src/identities.rs index 33b3818..8ef9ff1 100644 --- a/src/identities.rs +++ b/src/identities.rs @@ -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); diff --git a/src/int.rs b/src/int.rs index 4f4d0b9..1e8275f 100644 --- a/src/int.rs +++ b/src/int.rs @@ -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); diff --git a/src/lib.rs b/src/lib.rs index 47a3bfa..53d55a5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 Num for Wrapping diff --git a/src/ops/checked.rs b/src/ops/checked.rs index 8ed8e6b..1c2b2f5 100644 --- a/src/ops/checked.rs +++ b/src/ops/checked.rs @@ -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); diff --git a/src/ops/mul_add.rs b/src/ops/mul_add.rs index cf7bd2c..f7cb71f 100644 --- a/src/ops/mul_add.rs +++ b/src/ops/mul_add.rs @@ -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)] diff --git a/src/ops/saturating.rs b/src/ops/saturating.rs index 84e3908..fdce189 100644 --- a/src/ops/saturating.rs +++ b/src/ops/saturating.rs @@ -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); diff --git a/src/ops/wrapping.rs b/src/ops/wrapping.rs index fc44678..b6bd136 100644 --- a/src/ops/wrapping.rs +++ b/src/ops/wrapping.rs @@ -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. diff --git a/src/pow.rs b/src/pow.rs index 63e859d..2c0723d 100644 --- a/src/pow.rs +++ b/src/pow.rs @@ -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); pow_impl!(Wrapping); pow_impl!(Wrapping); pow_impl!(Wrapping); -#[cfg(feature = "i128")] +#[cfg(has_i128)] pow_impl!(Wrapping); -#[cfg(feature = "i128")] +#[cfg(has_i128)] pow_impl!(Wrapping); pow_impl!(Wrapping); pow_impl!(Wrapping); diff --git a/src/sign.rs b/src/sign.rs index 769609f..779d058 100644 --- a/src/sign.rs +++ b/src/sign.rs @@ -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 Signed for Wrapping where Wrapping: Num + Neg> @@ -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 Unsigned for Wrapping where Wrapping: Num {} diff --git a/tests/cast.rs b/tests/cast.rs index 773cc24..edac185 100644 --- a/tests/cast.rs +++ b/tests/cast.rs @@ -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::*; From c00ae2046eafc74e3327122a492577fd898afd47 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 11 May 2018 16:01:25 -0700 Subject: [PATCH 2/2] Release 0.2.4 --- Cargo.toml | 2 +- RELEASES.md | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 7b01de5..5a15f5f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ categories = ["algorithms", "science", "no-std"] license = "MIT/Apache-2.0" repository = "https://github.com/rust-num/num-traits" name = "num-traits" -version = "0.2.3" +version = "0.2.4" readme = "README.md" build = "build.rs" diff --git a/RELEASES.md b/RELEASES.md index cdec035..cbf64da 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,3 +1,13 @@ +# Release 0.2.4 + +- [Support for 128-bit integers is now automatically detected and enabled.][69] + Setting the `i128` crate feature now causes the build script to panic if such + support is not detected. + +**Contributors**: @cuviper + +[69]: https://github.com/rust-num/num-traits/pull/69 + # Release 0.2.3 - [The new `CheckedNeg` and `CheckedRem` traits][63] perform checked `Neg` and