Browse Source

Merge #240

240: Upgrade to 2018 edition, MSRV 1.31 r=cuviper a=cuviper



Co-authored-by: Josh Stone <[email protected]>
bors[bot] 2 years ago
parent
commit
5397a1c271
25 changed files with 167 additions and 332 deletions
  1. 12 2
      .github/workflows/ci.yaml
  2. 1 1
      .github/workflows/master.yaml
  3. 1 1
      .github/workflows/pr.yaml
  4. 4 0
      Cargo.toml
  5. 2 7
      README.md
  6. 5 4
      bors.toml
  7. 0 9
      build.rs
  8. 1 1
      ci/rustup.sh
  9. 2 4
      ci/test_full.sh
  10. 2 7
      src/bounds.rs
  11. 4 40
      src/cast.rs
  12. 32 52
      src/float.rs
  13. 0 4
      src/identities.rs
  14. 5 8
      src/int.rs
  15. 27 33
      src/lib.rs
  16. 0 16
      src/ops/checked.rs
  17. 14 22
      src/ops/euclid.rs
  18. 8 10
      src/ops/mul_add.rs
  19. 2 10
      src/ops/overflowing.rs
  20. 2 9
      src/ops/saturating.rs
  21. 6 16
      src/ops/wrapping.rs
  22. 5 25
      src/pow.rs
  23. 1 1
      src/real.rs
  24. 9 17
      src/sign.rs
  25. 22 33
      tests/cast.rs

+ 12 - 2
.github/workflows/ci.yaml

@@ -12,7 +12,17 @@ jobs:
     runs-on: ubuntu-latest
     strategy:
       matrix:
-        rust: [1.8.0, 1.15.0, 1.20.0, 1.26.0, 1.31.0, stable, beta, nightly]
+        rust: [
+          1.31.0, # MSRV
+          1.35.0, # has_copysign
+          1.37.0, # has_reverse_bits
+          1.38.0, # has_div_euclid
+          1.44.0, # has_to_int_unchecked
+          1.46.0, # has_leading_trailing_ones
+          stable,
+          beta,
+          nightly,
+        ]
     steps:
       - uses: actions/checkout@v3
       - uses: dtolnay/rust-toolchain@master
@@ -44,7 +54,7 @@ jobs:
       - uses: dtolnay/rust-toolchain@stable
         with:
           target: thumbv6m-none-eabi
-      - run: cargo build --target thumbv6m-none-eabi --no-default-features --features i128
+      - run: cargo build --target thumbv6m-none-eabi --no-default-features
       - run: cargo build --target thumbv6m-none-eabi --no-default-features --features libm
 
   fmt:

+ 1 - 1
.github/workflows/master.yaml

@@ -13,7 +13,7 @@ jobs:
     runs-on: ubuntu-latest
     strategy:
       matrix:
-        rust: [1.8.0, stable]
+        rust: [1.31.0, stable]
     steps:
       - uses: actions/checkout@v3
       - uses: dtolnay/rust-toolchain@master

+ 1 - 1
.github/workflows/pr.yaml

@@ -9,7 +9,7 @@ jobs:
     runs-on: ubuntu-latest
     strategy:
       matrix:
-        rust: [1.8.0, stable]
+        rust: [1.31.0, stable]
     steps:
       - uses: actions/checkout@v3
       - uses: dtolnay/rust-toolchain@master

+ 4 - 0
Cargo.toml

@@ -12,6 +12,8 @@ version = "0.2.15"
 readme = "README.md"
 build = "build.rs"
 exclude = ["/bors.toml", "/ci/*", "/.github/*"]
+edition = "2018"
+rust-version = "1.31"
 
 [package.metadata.docs.rs]
 features = ["std"]
@@ -22,6 +24,8 @@ libm = { version = "0.2.0", optional = true }
 [features]
 default = ["std"]
 std = []
+
+# vestigial features, now always in effect
 i128 = []
 
 [build-dependencies]

+ 2 - 7
README.md

@@ -2,7 +2,7 @@
 
 [![crate](https://img.shields.io/crates/v/num-traits.svg)](https://crates.io/crates/num-traits)
 [![documentation](https://docs.rs/num-traits/badge.svg)](https://docs.rs/num-traits)
-[![minimum rustc 1.8](https://img.shields.io/badge/rustc-1.8+-red.svg)](https://rust-lang.github.io/rfcs/2495-min-rust-version.html)
+[![minimum rustc 1.31](https://img.shields.io/badge/rustc-1.31+-red.svg)](https://rust-lang.github.io/rfcs/2495-min-rust-version.html)
 [![build status](https://github.com/rust-num/num-traits/workflows/master/badge.svg)](https://github.com/rust-num/num-traits/actions)
 
 Numeric traits for generic mathematics in Rust.
@@ -29,23 +29,18 @@ default-features = false
 ```
 
 The `Float` and `Real` traits are only available when either `std` or `libm` is enabled.  
-The `libm` feature is only available with Rust 1.31 and later ([see PR #99](https://github.com/rust-num/num-traits/pull/99)).
 
 The `FloatCore` trait is always available.  `MulAdd` and `MulAddAssign` for `f32`
 and `f64` also require `std` or `libm`, as do implementations of signed and floating-
 point exponents in `Pow`.
 
-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
 
 Release notes are available in [RELEASES.md](RELEASES.md).
 
 ## Compatibility
 
-The `num-traits` crate is tested for rustc 1.8 and greater.
+The `num-traits` crate is tested for rustc 1.31 and greater.
 
 ## License
 

+ 5 - 4
bors.toml

@@ -1,9 +1,10 @@
 status = [
-  "Test (1.8.0)",
-  "Test (1.15.0)",
-  "Test (1.20.0)",
-  "Test (1.26.0)",
   "Test (1.31.0)",
+  "Test (1.35.0)",
+  "Test (1.37.0)",
+  "Test (1.38.0)",
+  "Test (1.44.0)",
+  "Test (1.46.0)",
   "Test (stable)",
   "Test (beta)",
   "Test (nightly)",

+ 0 - 9
build.rs

@@ -1,16 +1,8 @@
-extern crate autocfg;
-
 use std::env;
 
 fn main() {
     let ac = autocfg::new();
 
-    // If the "i128" feature is explicity requested, don't bother probing for it.
-    // It will still cause a build error if that was set improperly.
-    if env::var_os("CARGO_FEATURE_I128").is_some() || ac.probe_type("i128") {
-        autocfg::emit("has_i128");
-    }
-
     ac.emit_expression_cfg(
         "unsafe { 1f64.to_int_unchecked::<i32>() }",
         "has_to_int_unchecked",
@@ -18,7 +10,6 @@ fn main() {
 
     ac.emit_expression_cfg("1u32.reverse_bits()", "has_reverse_bits");
     ac.emit_expression_cfg("1u32.trailing_ones()", "has_leading_trailing_ones");
-    ac.emit_expression_cfg("{ let mut x = 1; x += &2; }", "has_int_assignop_ref");
     ac.emit_expression_cfg("1u32.div_euclid(1u32)", "has_div_euclid");
 
     if env::var_os("CARGO_FEATURE_STD").is_some() {

+ 1 - 1
ci/rustup.sh

@@ -5,6 +5,6 @@
 set -ex
 
 ci=$(dirname $0)
-for version in 1.8.0 1.15.0 1.20.0 1.26.0 1.31.0 stable beta nightly; do
+for version in 1.31.0 1.35.0 1.37.0 1.38.0 1.44.0 1.46.0 stable beta nightly; do
     rustup run "$version" "$ci/test_full.sh"
 done

+ 2 - 4
ci/test_full.sh

@@ -3,7 +3,7 @@
 set -e
 
 CRATE=num-traits
-MSRV=1.8
+MSRV=1.31
 
 get_rust_version() {
   local array=($(rustc --version));
@@ -27,9 +27,7 @@ if ! check_version $MSRV ; then
   exit 1
 fi
 
-FEATURES=()
-check_version 1.26 && FEATURES+=(i128)
-check_version 1.27 && FEATURES+=(libm)
+FEATURES=(libm)
 echo "Testing supported features: ${FEATURES[*]}"
 
 set -x

+ 2 - 7
src/bounds.rs

@@ -1,9 +1,7 @@
 use core::num::Wrapping;
 use core::{f32, f64};
-#[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};
 
 /// Numbers which have upper and lower bounds
 pub trait Bounded {
@@ -61,7 +59,6 @@ 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(has_i128)]
 bounded_impl!(u128, u128::MIN, u128::MAX);
 
 bounded_impl!(isize, isize::MIN, isize::MAX);
@@ -69,7 +66,6 @@ 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(has_i128)]
 bounded_impl!(i128, i128::MIN, i128::MAX);
 
 impl<T: Bounded> Bounded for Wrapping<T> {
@@ -130,7 +126,6 @@ fn wrapping_bounded() {
     test_wrapping_bounded!(usize u8 u16 u32 u64 isize i8 i16 i32 i64);
 }
 
-#[cfg(has_i128)]
 #[test]
 fn wrapping_bounded_i128() {
     macro_rules! test_wrapping_bounded {

+ 4 - 40
src/cast.rs

@@ -1,10 +1,8 @@
 use core::mem::size_of;
 use core::num::Wrapping;
 use core::{f32, f64};
-#[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};
 
 /// A generic trait for converting a value to a number.
 ///
@@ -53,12 +51,9 @@ pub trait ToPrimitive {
     /// represented by an `i128` (`i64` under the default implementation), then
     /// `None` is returned.
     ///
-    /// This method is only available with feature `i128` enabled on Rust >= 1.26.
-    ///
     /// The default implementation converts through `to_i64()`. Types implementing
     /// this trait should override this method if they can represent a greater range.
     #[inline]
-    #[cfg(has_i128)]
     fn to_i128(&self) -> Option<i128> {
         self.to_i64().map(From::from)
     }
@@ -99,12 +94,9 @@ pub trait ToPrimitive {
     /// represented by a `u128` (`u64` under the default implementation), then
     /// `None` is returned.
     ///
-    /// This method is only available with feature `i128` enabled on Rust >= 1.26.
-    ///
     /// The default implementation converts through `to_u64()`. Types implementing
     /// this trait should override this method if they can represent a greater range.
     #[inline]
-    #[cfg(has_i128)]
     fn to_u128(&self) -> Option<u128> {
         self.to_u64().map(From::from)
     }
@@ -173,7 +165,6 @@ macro_rules! impl_to_primitive_int {
                 fn to_i16 -> i16;
                 fn to_i32 -> i32;
                 fn to_i64 -> i64;
-                #[cfg(has_i128)]
                 fn to_i128 -> i128;
             }
 
@@ -183,7 +174,6 @@ macro_rules! impl_to_primitive_int {
                 fn to_u16 -> u16;
                 fn to_u32 -> u32;
                 fn to_u64 -> u64;
-                #[cfg(has_i128)]
                 fn to_u128 -> u128;
             }
 
@@ -204,7 +194,6 @@ impl_to_primitive_int!(i8);
 impl_to_primitive_int!(i16);
 impl_to_primitive_int!(i32);
 impl_to_primitive_int!(i64);
-#[cfg(has_i128)]
 impl_to_primitive_int!(i128);
 
 macro_rules! impl_to_primitive_uint_to_int {
@@ -246,7 +235,6 @@ macro_rules! impl_to_primitive_uint {
                 fn to_i16 -> i16;
                 fn to_i32 -> i32;
                 fn to_i64 -> i64;
-                #[cfg(has_i128)]
                 fn to_i128 -> i128;
             }
 
@@ -256,7 +244,6 @@ macro_rules! impl_to_primitive_uint {
                 fn to_u16 -> u16;
                 fn to_u32 -> u32;
                 fn to_u64 -> u64;
-                #[cfg(has_i128)]
                 fn to_u128 -> u128;
             }
 
@@ -277,7 +264,6 @@ impl_to_primitive_uint!(u8);
 impl_to_primitive_uint!(u16);
 impl_to_primitive_uint!(u32);
 impl_to_primitive_uint!(u64);
-#[cfg(has_i128)]
 impl_to_primitive_uint!(u128);
 
 macro_rules! impl_to_primitive_float_to_float {
@@ -373,7 +359,6 @@ macro_rules! impl_to_primitive_float {
                 fn to_i16 -> i16;
                 fn to_i32 -> i32;
                 fn to_i64 -> i64;
-                #[cfg(has_i128)]
                 fn to_i128 -> i128;
             }
 
@@ -383,7 +368,6 @@ macro_rules! impl_to_primitive_float {
                 fn to_u16 -> u16;
                 fn to_u32 -> u32;
                 fn to_u64 -> u64;
-                #[cfg(has_i128)]
                 fn to_u128 -> u128;
             }
 
@@ -444,12 +428,9 @@ pub trait FromPrimitive: Sized {
     /// Converts an `i128` to return an optional value of this type. If the
     /// value cannot be represented by this type, then `None` is returned.
     ///
-    /// This method is only available with feature `i128` enabled on Rust >= 1.26.
-    ///
     /// The default implementation converts through `from_i64()`. Types implementing
     /// this trait should override this method if they can represent a greater range.
     #[inline]
-    #[cfg(has_i128)]
     fn from_i128(n: i128) -> Option<Self> {
         n.to_i64().and_then(FromPrimitive::from_i64)
     }
@@ -489,12 +470,9 @@ pub trait FromPrimitive: Sized {
     /// Converts an `u128` to return an optional value of this type. If the
     /// value cannot be represented by this type, then `None` is returned.
     ///
-    /// This method is only available with feature `i128` enabled on Rust >= 1.26.
-    ///
     /// The default implementation converts through `from_u64()`. Types implementing
     /// this trait should override this method if they can represent a greater range.
     #[inline]
-    #[cfg(has_i128)]
     fn from_u128(n: u128) -> Option<Self> {
         n.to_u64().and_then(FromPrimitive::from_u64)
     }
@@ -545,7 +523,6 @@ macro_rules! impl_from_primitive {
             fn from_i64(n: i64) -> Option<$T> {
                 n.$to_ty()
             }
-            #[cfg(has_i128)]
             #[inline]
             fn from_i128(n: i128) -> Option<$T> {
                 n.$to_ty()
@@ -571,7 +548,6 @@ macro_rules! impl_from_primitive {
             fn from_u64(n: u64) -> Option<$T> {
                 n.$to_ty()
             }
-            #[cfg(has_i128)]
             #[inline]
             fn from_u128(n: u128) -> Option<$T> {
                 n.$to_ty()
@@ -594,14 +570,12 @@ 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(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(has_i128)]
 impl_from_primitive!(u128, to_u128);
 impl_from_primitive!(f32, to_f32);
 impl_from_primitive!(f64, to_f64);
@@ -623,7 +597,6 @@ impl<T: ToPrimitive> ToPrimitive for Wrapping<T> {
         fn to_i16 -> i16;
         fn to_i32 -> i32;
         fn to_i64 -> i64;
-        #[cfg(has_i128)]
         fn to_i128 -> i128;
 
         fn to_usize -> usize;
@@ -631,7 +604,6 @@ impl<T: ToPrimitive> ToPrimitive for Wrapping<T> {
         fn to_u16 -> u16;
         fn to_u32 -> u32;
         fn to_u64 -> u64;
-        #[cfg(has_i128)]
         fn to_u128 -> u128;
 
         fn to_f32 -> f32;
@@ -656,7 +628,6 @@ impl<T: FromPrimitive> FromPrimitive for Wrapping<T> {
         fn from_i16(i16);
         fn from_i32(i32);
         fn from_i64(i64);
-        #[cfg(has_i128)]
         fn from_i128(i128);
 
         fn from_usize(usize);
@@ -664,7 +635,6 @@ impl<T: FromPrimitive> FromPrimitive for Wrapping<T> {
         fn from_u16(u16);
         fn from_u32(u32);
         fn from_u64(u64);
-        #[cfg(has_i128)]
         fn from_u128(u128);
 
         fn from_f32(f32);
@@ -722,14 +692,12 @@ 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(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(has_i128)]
 impl_num_cast!(i128, to_i128);
 impl_num_cast!(isize, to_isize);
 impl_num_cast!(f32, to_f32);
@@ -787,10 +755,8 @@ 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(has_i128)] impl u128);
-        impl_as_primitive!(@ $T => { i8, i16, i32, i64, isize });
-        impl_as_primitive!(@ $T => #[cfg(has_i128)] impl i128);
+        impl_as_primitive!(@ $T => { u8, u16, u32, u64, u128, usize });
+        impl_as_primitive!(@ $T => { i8, i16, i32, i64, i128, isize });
     };
 }
 
@@ -802,9 +768,7 @@ 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(has_i128)]
 impl_as_primitive!(u128 => { f32, f64 });
-#[cfg(has_i128)]
 impl_as_primitive!(i128 => { f32, f64 });
 impl_as_primitive!(usize => { f32, f64 });
 impl_as_primitive!(isize => { f32, f64 });

+ 32 - 52
src/float.rs

@@ -1,14 +1,10 @@
-use core::mem;
 use core::num::FpCategory;
 use core::ops::{Add, Div, Neg};
 
 use core::f32;
 use core::f64;
 
-use {Num, NumCast, ToPrimitive};
-
-#[cfg(all(not(feature = "std"), feature = "libm"))]
-use libm;
+use crate::{Num, NumCast, ToPrimitive};
 
 /// Generic trait for floating point numbers that works with `no_std`.
 ///
@@ -170,6 +166,7 @@ pub trait FloatCore: Num + NumCast + Neg<Output = Self> + PartialOrd + Copy {
     /// check(0.0f64, false);
     /// ```
     #[inline]
+    #[allow(clippy::eq_op)]
     fn is_nan(self) -> bool {
         self != self
     }
@@ -370,12 +367,10 @@ pub trait FloatCore: Num + NumCast + Neg<Output = Self> + PartialOrd + Copy {
             } else {
                 self - f + one
             }
+        } else if -f < h {
+            self - f
         } else {
-            if -f < h {
-                self - f
-            } else {
-                self - f - one
-            }
+            self - f - one
         }
     }
 
@@ -508,8 +503,7 @@ pub trait FloatCore: Num + NumCast + Neg<Output = Self> + PartialOrd + Copy {
     }
 
     /// Returns `true` if `self` is positive, including `+0.0` and
-    /// `FloatCore::infinity()`, and since Rust 1.20 also
-    /// `FloatCore::nan()`.
+    /// `FloatCore::infinity()`, and `FloatCore::nan()`.
     ///
     /// # Examples
     ///
@@ -527,6 +521,7 @@ pub trait FloatCore: Num + NumCast + Neg<Output = Self> + PartialOrd + Copy {
     /// check(-0.0f64, false);
     /// check(f64::NEG_INFINITY, false);
     /// check(f64::MIN_POSITIVE, true);
+    /// check(f64::NAN, true);
     /// check(-f64::NAN, false);
     /// ```
     #[inline]
@@ -535,8 +530,7 @@ pub trait FloatCore: Num + NumCast + Neg<Output = Self> + PartialOrd + Copy {
     }
 
     /// Returns `true` if `self` is negative, including `-0.0` and
-    /// `FloatCore::neg_infinity()`, and since Rust 1.20 also
-    /// `-FloatCore::nan()`.
+    /// `FloatCore::neg_infinity()`, and `-FloatCore::nan()`.
     ///
     /// # Examples
     ///
@@ -555,6 +549,7 @@ pub trait FloatCore: Num + NumCast + Neg<Output = Self> + PartialOrd + Copy {
     /// check(f64::NEG_INFINITY, true);
     /// check(f64::MIN_POSITIVE, false);
     /// check(f64::NAN, false);
+    /// check(-f64::NAN, true);
     /// ```
     #[inline]
     fn is_sign_negative(self) -> bool {
@@ -769,9 +764,7 @@ impl FloatCore for f32 {
         const EXP_MASK: u32 = 0x7f800000;
         const MAN_MASK: u32 = 0x007fffff;
 
-        // Safety: this identical to the implementation of f32::to_bits(),
-        // which is only available starting at Rust 1.20
-        let bits: u32 = unsafe { mem::transmute(self) };
+        let bits: u32 = self.to_bits();
         match (bits & MAN_MASK, bits & EXP_MASK) {
             (0, 0) => FpCategory::Zero,
             (_, 0) => FpCategory::Subnormal,
@@ -786,10 +779,7 @@ impl FloatCore for f32 {
     fn is_sign_negative(self) -> bool {
         const SIGN_MASK: u32 = 0x80000000;
 
-        // Safety: this identical to the implementation of f32::to_bits(),
-        // which is only available starting at Rust 1.20
-        let bits: u32 = unsafe { mem::transmute(self) };
-        bits & SIGN_MASK != 0
+        self.to_bits() & SIGN_MASK != 0
     }
 
     #[inline]
@@ -871,9 +861,7 @@ impl FloatCore for f64 {
         const EXP_MASK: u64 = 0x7ff0000000000000;
         const MAN_MASK: u64 = 0x000fffffffffffff;
 
-        // Safety: this identical to the implementation of f64::to_bits(),
-        // which is only available starting at Rust 1.20
-        let bits: u64 = unsafe { mem::transmute(self) };
+        let bits: u64 = self.to_bits();
         match (bits & MAN_MASK, bits & EXP_MASK) {
             (0, 0) => FpCategory::Zero,
             (_, 0) => FpCategory::Subnormal,
@@ -888,10 +876,7 @@ impl FloatCore for f64 {
     fn is_sign_negative(self) -> bool {
         const SIGN_MASK: u64 = 0x8000000000000000;
 
-        // Safety: this identical to the implementation of f64::to_bits(),
-        // which is only available starting at Rust 1.20
-        let bits: u64 = unsafe { mem::transmute(self) };
-        bits & SIGN_MASK != 0
+        self.to_bits() & SIGN_MASK != 0
     }
 
     #[inline]
@@ -1266,12 +1251,13 @@ pub trait Float: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
     fn signum(self) -> Self;
 
     /// Returns `true` if `self` is positive, including `+0.0`,
-    /// `Float::infinity()`, and since Rust 1.20 also `Float::nan()`.
+    /// `Float::infinity()`, and `Float::nan()`.
     ///
     /// ```
     /// use num_traits::Float;
     /// use std::f64;
     ///
+    /// let nan: f64 = f64::NAN;
     /// let neg_nan: f64 = -f64::NAN;
     ///
     /// let f = 7.0;
@@ -1279,18 +1265,20 @@ pub trait Float: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
     ///
     /// assert!(f.is_sign_positive());
     /// assert!(!g.is_sign_positive());
+    /// assert!(nan.is_sign_positive());
     /// assert!(!neg_nan.is_sign_positive());
     /// ```
     fn is_sign_positive(self) -> bool;
 
     /// Returns `true` if `self` is negative, including `-0.0`,
-    /// `Float::neg_infinity()`, and since Rust 1.20 also `-Float::nan()`.
+    /// `Float::neg_infinity()`, and `-Float::nan()`.
     ///
     /// ```
     /// use num_traits::Float;
     /// use std::f64;
     ///
     /// let nan: f64 = f64::NAN;
+    /// let neg_nan: f64 = -f64::NAN;
     ///
     /// let f = 7.0;
     /// let g = -7.0;
@@ -1298,6 +1286,7 @@ pub trait Float: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
     /// assert!(!f.is_sign_negative());
     /// assert!(g.is_sign_negative());
     /// assert!(!nan.is_sign_negative());
+    /// assert!(neg_nan.is_sign_negative());
     /// ```
     fn is_sign_negative(self) -> bool;
 
@@ -2025,9 +2014,7 @@ macro_rules! float_impl_libm {
 }
 
 fn integer_decode_f32(f: f32) -> (u64, i16, i8) {
-    // Safety: this identical to the implementation of f32::to_bits(),
-    // which is only available starting at Rust 1.20
-    let bits: u32 = unsafe { mem::transmute(f) };
+    let bits: u32 = f.to_bits();
     let sign: i8 = if bits >> 31 == 0 { 1 } else { -1 };
     let mut exponent: i16 = ((bits >> 23) & 0xff) as i16;
     let mantissa = if exponent == 0 {
@@ -2041,9 +2028,7 @@ fn integer_decode_f32(f: f32) -> (u64, i16, i8) {
 }
 
 fn integer_decode_f64(f: f64) -> (u64, i16, i8) {
-    // Safety: this identical to the implementation of f64::to_bits(),
-    // which is only available starting at Rust 1.20
-    let bits: u64 = unsafe { mem::transmute(f) };
+    let bits: u64 = f.to_bits();
     let sign: i8 = if bits >> 63 == 0 { 1 } else { -1 };
     let mut exponent: i16 = ((bits >> 52) & 0x7ff) as i16;
     let mantissa = if exponent == 0 {
@@ -2244,7 +2229,7 @@ mod tests {
 
     #[test]
     fn convert_deg_rad() {
-        use float::FloatCore;
+        use crate::float::FloatCore;
 
         for &(deg, rad) in &DEG_RAD_PAIRS {
             assert!((FloatCore::to_degrees(rad) - deg).abs() < 1e-6);
@@ -2260,7 +2245,7 @@ mod tests {
     #[test]
     fn convert_deg_rad_std() {
         for &(deg, rad) in &DEG_RAD_PAIRS {
-            use Float;
+            use crate::Float;
 
             assert!((Float::to_degrees(rad) - deg).abs() < 1e-6);
             assert!((Float::to_radians(deg) - rad).abs() < 1e-6);
@@ -2272,11 +2257,8 @@ mod tests {
     }
 
     #[test]
-    // This fails with the forwarded `std` implementation in Rust 1.8.
-    // To avoid the failure, the test is limited to `no_std` builds.
-    #[cfg(not(feature = "std"))]
     fn to_degrees_rounding() {
-        use float::FloatCore;
+        use crate::float::FloatCore;
 
         assert_eq!(
             FloatCore::to_degrees(1_f32),
@@ -2287,7 +2269,7 @@ mod tests {
     #[test]
     #[cfg(any(feature = "std", feature = "libm"))]
     fn extra_logs() {
-        use float::{Float, FloatConst};
+        use crate::float::{Float, FloatConst};
 
         fn check<F: Float + FloatConst>(diff: F) {
             let _2 = F::from(2.0).unwrap();
@@ -2306,7 +2288,7 @@ mod tests {
     #[test]
     #[cfg(any(feature = "std", feature = "libm"))]
     fn copysign() {
-        use float::Float;
+        use crate::float::Float;
         test_copysign_generic(2.0_f32, -2.0_f32, f32::nan());
         test_copysign_generic(2.0_f64, -2.0_f64, f64::nan());
         test_copysignf(2.0_f32, -2.0_f32, f32::nan());
@@ -2314,8 +2296,8 @@ mod tests {
 
     #[cfg(any(feature = "std", feature = "libm"))]
     fn test_copysignf(p: f32, n: f32, nan: f32) {
+        use crate::float::Float;
         use core::ops::Neg;
-        use float::Float;
 
         assert!(p.is_sign_positive());
         assert!(n.is_sign_negative());
@@ -2327,13 +2309,12 @@ mod tests {
         assert_eq!(n, Float::copysign(n, n));
         assert_eq!(n.neg(), Float::copysign(n, p));
 
-        // FIXME: is_sign... only works on NaN starting in Rust 1.20
-        // assert!(Float::copysign(nan, p).is_sign_positive());
-        // assert!(Float::copysign(nan, n).is_sign_negative());
+        assert!(Float::copysign(nan, p).is_sign_positive());
+        assert!(Float::copysign(nan, n).is_sign_negative());
     }
 
     #[cfg(any(feature = "std", feature = "libm"))]
-    fn test_copysign_generic<F: ::float::Float + ::core::fmt::Debug>(p: F, n: F, nan: F) {
+    fn test_copysign_generic<F: crate::float::Float + ::core::fmt::Debug>(p: F, n: F, nan: F) {
         assert!(p.is_sign_positive());
         assert!(n.is_sign_negative());
         assert!(nan.is_nan());
@@ -2344,8 +2325,7 @@ mod tests {
         assert_eq!(n, n.copysign(n));
         assert_eq!(n.neg(), n.copysign(p));
 
-        // FIXME: is_sign... only works on NaN starting in Rust 1.20
-        // assert!(nan.copysign(p).is_sign_positive());
-        // assert!(nan.copysign(n).is_sign_negative());
+        assert!(nan.copysign(p).is_sign_positive());
+        assert!(nan.copysign(n).is_sign_negative());
     }
 }

+ 0 - 4
src/identities.rs

@@ -48,7 +48,6 @@ zero_impl!(u8, 0);
 zero_impl!(u16, 0);
 zero_impl!(u32, 0);
 zero_impl!(u64, 0);
-#[cfg(has_i128)]
 zero_impl!(u128, 0);
 
 zero_impl!(isize, 0);
@@ -56,7 +55,6 @@ zero_impl!(i8, 0);
 zero_impl!(i16, 0);
 zero_impl!(i32, 0);
 zero_impl!(i64, 0);
-#[cfg(has_i128)]
 zero_impl!(i128, 0);
 
 zero_impl!(f32, 0.0);
@@ -137,7 +135,6 @@ one_impl!(u8, 1);
 one_impl!(u16, 1);
 one_impl!(u32, 1);
 one_impl!(u64, 1);
-#[cfg(has_i128)]
 one_impl!(u128, 1);
 
 one_impl!(isize, 1);
@@ -145,7 +142,6 @@ one_impl!(i8, 1);
 one_impl!(i16, 1);
 one_impl!(i32, 1);
 one_impl!(i64, 1);
-#[cfg(has_i128)]
 one_impl!(i128, 1);
 
 one_impl!(f32, 1.0);

+ 5 - 8
src/int.rs

@@ -1,9 +1,9 @@
 use core::ops::{BitAnd, BitOr, BitXor, Not, Shl, Shr};
 
-use bounds::Bounded;
-use ops::checked::*;
-use ops::saturating::Saturating;
-use {Num, NumCast};
+use crate::bounds::Bounded;
+use crate::ops::checked::*;
+use crate::ops::saturating::Saturating;
+use crate::{Num, NumCast};
 
 /// Generic trait for primitive integers.
 ///
@@ -500,20 +500,18 @@ 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(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(has_i128)]
 prim_int_impl!(i128, i128, u128);
 prim_int_impl!(isize, isize, usize);
 
 #[cfg(test)]
 mod tests {
-    use int::PrimInt;
+    use crate::int::PrimInt;
 
     #[test]
     pub fn reverse_bits() {
@@ -554,7 +552,6 @@ mod tests {
     }
 
     #[test]
-    #[cfg(has_i128)]
     pub fn reverse_bits_i128() {
         use core::i128;
 

+ 27 - 33
src/lib.rs

@@ -12,43 +12,41 @@
 //!
 //! ## Compatibility
 //!
-//! The `num-traits` crate is tested for rustc 1.8 and greater.
+//! The `num-traits` crate is tested for rustc 1.31 and greater.
 
 #![doc(html_root_url = "https://docs.rs/num-traits/0.2")]
 #![deny(unconditional_recursion)]
 #![no_std]
+
+// Need to explicitly bring the crate in for inherent float methods
 #[cfg(feature = "std")]
 extern crate std;
 
-// Only `no_std` builds actually use `libm`.
-#[cfg(all(not(feature = "std"), feature = "libm"))]
-extern crate libm;
-
 use core::fmt;
 use core::num::Wrapping;
 use core::ops::{Add, Div, Mul, Rem, Sub};
 use core::ops::{AddAssign, DivAssign, MulAssign, RemAssign, SubAssign};
 
-pub use bounds::Bounded;
+pub use crate::bounds::Bounded;
 #[cfg(any(feature = "std", feature = "libm"))]
-pub use float::Float;
-pub use float::FloatConst;
+pub use crate::float::Float;
+pub use crate::float::FloatConst;
 // pub use real::{FloatCore, Real}; // NOTE: Don't do this, it breaks `use num_traits::*;`.
-pub use cast::{cast, AsPrimitive, FromPrimitive, NumCast, ToPrimitive};
-pub use identities::{one, zero, One, Zero};
-pub use int::PrimInt;
-pub use ops::checked::{
+pub use crate::cast::{cast, AsPrimitive, FromPrimitive, NumCast, ToPrimitive};
+pub use crate::identities::{one, zero, One, Zero};
+pub use crate::int::PrimInt;
+pub use crate::ops::checked::{
     CheckedAdd, CheckedDiv, CheckedMul, CheckedNeg, CheckedRem, CheckedShl, CheckedShr, CheckedSub,
 };
-pub use ops::euclid::{CheckedEuclid, Euclid};
-pub use ops::inv::Inv;
-pub use ops::mul_add::{MulAdd, MulAddAssign};
-pub use ops::saturating::{Saturating, SaturatingAdd, SaturatingMul, SaturatingSub};
-pub use ops::wrapping::{
+pub use crate::ops::euclid::{CheckedEuclid, Euclid};
+pub use crate::ops::inv::Inv;
+pub use crate::ops::mul_add::{MulAdd, MulAddAssign};
+pub use crate::ops::saturating::{Saturating, SaturatingAdd, SaturatingMul, SaturatingSub};
+pub use crate::ops::wrapping::{
     WrappingAdd, WrappingMul, WrappingNeg, WrappingShl, WrappingShr, WrappingSub,
 };
-pub use pow::{checked_pow, pow, Pow};
-pub use sign::{abs, abs_sub, signum, Signed, Unsigned};
+pub use crate::pow::{checked_pow, pow, Pow};
+pub use crate::sign::{abs, abs_sub, signum, Signed, Unsigned};
 
 #[macro_use]
 mod macros;
@@ -172,9 +170,8 @@ macro_rules! int_trait_impl {
         }
     )*)
 }
-int_trait_impl!(Num for usize u8 u16 u32 u64 isize i8 i16 i32 i64);
-#[cfg(has_i128)]
-int_trait_impl!(Num for u128 i128);
+int_trait_impl!(Num for usize u8 u16 u32 u64 u128);
+int_trait_impl!(Num for isize i8 i16 i32 i64 i128);
 
 impl<T: Num> Num for Wrapping<T>
 where
@@ -199,7 +196,7 @@ pub struct ParseFloatError {
 }
 
 impl fmt::Display for ParseFloatError {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         let description = match self.kind {
             FloatErrorKind::Empty => "cannot parse float from empty string",
             FloatErrorKind::Invalid => "invalid float literal",
@@ -255,11 +252,7 @@ macro_rules! float_trait_impl {
 
                 fn slice_shift_char(src: &str) -> Option<(char, &str)> {
                     let mut chars = src.chars();
-                    if let Some(ch) = chars.next() {
-                        Some((ch, chars.as_str()))
-                    } else {
-                        None
-                    }
+                    Some((chars.next()?, chars.as_str()))
                 }
 
                 let (is_positive, src) =  match slice_shift_char(src) {
@@ -282,13 +275,13 @@ macro_rules! float_trait_impl {
                     match c.to_digit(radix) {
                         Some(digit) => {
                             // shift significand one digit left
-                            sig = sig * (radix as $t);
+                            sig *= radix as $t;
 
                             // add/subtract current digit depending on sign
                             if is_positive {
-                                sig = sig + ((digit as isize) as $t);
+                                sig += (digit as isize) as $t;
                             } else {
-                                sig = sig - ((digit as isize) as $t);
+                                sig -= (digit as isize) as $t;
                             }
 
                             // Detect overflow by comparing to last value, except
@@ -330,7 +323,7 @@ macro_rules! float_trait_impl {
                         match c.to_digit(radix) {
                             Some(digit) => {
                                 // Decrease power one order of magnitude
-                                power = power / (radix as $t);
+                                power /= radix as $t;
                                 // add/subtract current digit depending on sign
                                 sig = if is_positive {
                                     sig + (digit as $t) * power
@@ -424,6 +417,7 @@ pub fn clamp<T: PartialOrd>(input: T, min: T, max: T) -> T {
 ///
 /// **Panics** in debug mode if `!(min == min)`. (This occurs if `min` is `NAN`.)
 #[inline]
+#[allow(clippy::eq_op)]
 pub fn clamp_min<T: PartialOrd>(input: T, min: T) -> T {
     debug_assert!(min == min, "min must not be NAN");
     if input < min {
@@ -441,6 +435,7 @@ pub fn clamp_min<T: PartialOrd>(input: T, min: T) -> T {
 ///
 /// **Panics** in debug mode if `!(max == max)`. (This occurs if `max` is `NAN`.)
 #[inline]
+#[allow(clippy::eq_op)]
 pub fn clamp_max<T: PartialOrd>(input: T, max: T) -> T {
     debug_assert!(max == max, "max must not be NAN");
     if input > max {
@@ -625,7 +620,6 @@ fn check_numassign_ops() {
     assert_eq!(compute(1, 2), 1)
 }
 
-#[cfg(has_int_assignop_ref)]
 #[test]
 fn check_numassignref_ops() {
     fn compute<T: NumAssignRef + Copy>(mut x: T, y: &T) -> T {

+ 0 - 16
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,7 +181,6 @@ 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
@@ -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,7 +225,6 @@ 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
@@ -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);

+ 14 - 22
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);
     }
 }

+ 8 - 10
src/ops/mul_add.rs

@@ -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 {

+ 2 - 10
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]

+ 2 - 9
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.

+ 6 - 16
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() {

+ 5 - 25
src/pow.rs

@@ -1,6 +1,6 @@
+use crate::{CheckedMul, One};
 use core::num::Wrapping;
 use core::ops::Mul;
-use {CheckedMul, One};
 
 /// Binary operator for raising a value to a power.
 pub trait Pow<RHS> {
@@ -99,22 +99,14 @@ pow_impl!(i64, u16, u32, i64::pow);
 pow_impl!(i64, u32, u32, i64::pow);
 pow_impl!(i64, usize);
 
-#[cfg(has_i128)]
 pow_impl!(u128, u8, u32, u128::pow);
-#[cfg(has_i128)]
 pow_impl!(u128, u16, u32, u128::pow);
-#[cfg(has_i128)]
 pow_impl!(u128, u32, u32, u128::pow);
-#[cfg(has_i128)]
 pow_impl!(u128, usize);
 
-#[cfg(has_i128)]
 pow_impl!(i128, u8, u32, i128::pow);
-#[cfg(has_i128)]
 pow_impl!(i128, u16, u32, i128::pow);
-#[cfg(has_i128)]
 pow_impl!(i128, u32, u32, i128::pow);
-#[cfg(has_i128)]
 pow_impl!(i128, usize);
 
 pow_impl!(usize, u8, u32, usize::pow);
@@ -133,9 +125,7 @@ pow_impl!(Wrapping<u32>);
 pow_impl!(Wrapping<i32>);
 pow_impl!(Wrapping<u64>);
 pow_impl!(Wrapping<i64>);
-#[cfg(has_i128)]
 pow_impl!(Wrapping<u128>);
-#[cfg(has_i128)]
 pow_impl!(Wrapping<i128>);
 pow_impl!(Wrapping<usize>);
 pow_impl!(Wrapping<isize>);
@@ -155,7 +145,7 @@ pow_impl!(Wrapping<isize>);
 #[cfg(any(feature = "std", feature = "libm"))]
 mod float_impls {
     use super::Pow;
-    use Float;
+    use crate::Float;
 
     pow_impl!(f32, i8, i32, <f32 as Float>::powi);
     pow_impl!(f32, u8, i32, <f32 as Float>::powi);
@@ -232,18 +222,8 @@ pub fn checked_pow<T: Clone + One + CheckedMul>(mut base: T, mut exp: usize) ->
         return Some(T::one());
     }
 
-    macro_rules! optry {
-        ($expr:expr) => {
-            if let Some(val) = $expr {
-                val
-            } else {
-                return None;
-            }
-        };
-    }
-
     while exp & 1 == 0 {
-        base = optry!(base.checked_mul(&base));
+        base = base.checked_mul(&base)?;
         exp >>= 1;
     }
     if exp == 1 {
@@ -253,9 +233,9 @@ pub fn checked_pow<T: Clone + One + CheckedMul>(mut base: T, mut exp: usize) ->
     let mut acc = base.clone();
     while exp > 1 {
         exp >>= 1;
-        base = optry!(base.checked_mul(&base));
+        base = base.checked_mul(&base)?;
         if exp & 1 == 1 {
-            acc = optry!(acc.checked_mul(&base));
+            acc = acc.checked_mul(&base)?;
         }
     }
     Some(acc)

+ 1 - 1
src/real.rs

@@ -2,7 +2,7 @@
 
 use core::ops::Neg;
 
-use {Float, Num, NumCast};
+use crate::{Float, Num, NumCast};
 
 // NOTE: These doctests have the same issue as those in src/float.rs.
 // They're testing the inherent methods directly, and not those of `Real`.

+ 9 - 17
src/sign.rs

@@ -1,8 +1,8 @@
 use core::num::Wrapping;
 use core::ops::Neg;
 
-use float::FloatCore;
-use Num;
+use crate::float::FloatCore;
+use crate::Num;
 
 /// Useful functions for signed numbers (i.e. numbers that can be negative).
 pub trait Signed: Sized + Num + Neg<Output = Self> {
@@ -72,10 +72,7 @@ macro_rules! signed_impl {
     )*)
 }
 
-signed_impl!(isize i8 i16 i32 i64);
-
-#[cfg(has_i128)]
-signed_impl!(i128);
+signed_impl!(isize i8 i16 i32 i64 i128);
 
 impl<T: Signed> Signed for Wrapping<T>
 where
@@ -202,9 +199,7 @@ macro_rules! empty_trait_impl {
     )*)
 }
 
-empty_trait_impl!(Unsigned for usize u8 u16 u32 u64);
-#[cfg(has_i128)]
-empty_trait_impl!(Unsigned for u128);
+empty_trait_impl!(Unsigned for usize u8 u16 u32 u64 u128);
 
 impl<T: Unsigned> Unsigned for Wrapping<T> where Wrapping<T>: Num {}
 
@@ -214,11 +209,8 @@ fn unsigned_wrapping_is_unsigned() {
     require_unsigned(&Wrapping(42_u32));
 }
 
-// Commenting this out since it doesn't compile on Rust 1.8,
-// because on this version Wrapping doesn't implement Neg and therefore can't
-// implement Signed.
-// #[test]
-// fn signed_wrapping_is_signed() {
-//     fn require_signed<T: Signed>(_: &T) {}
-//     require_signed(&Wrapping(-42));
-// }
+#[test]
+fn signed_wrapping_is_signed() {
+    fn require_signed<T: Signed>(_: &T) {}
+    require_signed(&Wrapping(-42));
+}

+ 22 - 33
tests/cast.rs

@@ -1,21 +1,13 @@
 //! Tests of `num_traits::cast`.
 
-#![no_std]
-
-#[cfg(feature = "std")]
-#[macro_use]
-extern crate std;
-
-extern crate num_traits;
+#![cfg_attr(not(feature = "std"), no_std)]
 
 use num_traits::cast::*;
 use num_traits::Bounded;
 
 use core::{f32, f64};
-#[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};
 
 use core::fmt::Debug;
 use core::mem;
@@ -147,7 +139,6 @@ fn cast_to_unsigned_int_checks_overflow() {
 }
 
 #[test]
-#[cfg(has_i128)]
 fn cast_to_i128_checks_overflow() {
     let big_f: f64 = 1.0e123;
     let normal_f: f64 = 1.0;
@@ -163,7 +154,7 @@ fn cast_to_i128_checks_overflow() {
 }
 
 #[cfg(feature = "std")]
-fn dbg(args: ::core::fmt::Arguments) {
+fn dbg(args: ::core::fmt::Arguments<'_>) {
     println!("{}", args);
 }
 
@@ -180,9 +171,9 @@ macro_rules! float_test_edge {
         let small = if $t::MIN == 0 || mem::size_of::<$t>() < mem::size_of::<$f>() {
             $t::MIN as $f - 1.0
         } else {
-            ($t::MIN as $f).raw_offset(1).floor()
+            ($t::MIN as $f).raw_inc().floor()
         };
-        let fmin = small.raw_offset(-1);
+        let fmin = small.raw_dec();
         dbg!("  testing min {}\n\tvs. {:.0}\n\tand {:.0}", $t::MIN, fmin, small);
         assert_eq!(Some($t::MIN), cast::<$f, $t>($t::MIN as $f));
         assert_eq!(Some($t::MIN), cast::<$f, $t>(fmin));
@@ -192,11 +183,11 @@ macro_rules! float_test_edge {
             ($t::MAX, $t::MAX as $f + 1.0)
         } else {
             let large = $t::MAX as $f; // rounds up!
-            let max = large.raw_offset(-1) as $t; // the next smallest possible
+            let max = large.raw_dec() as $t; // the next smallest possible
             assert_eq!(max.count_ones(), $f::MANTISSA_DIGITS);
             (max, large)
         };
-        let fmax = large.raw_offset(-1);
+        let fmax = large.raw_dec();
         dbg!("  testing max {}\n\tvs. {:.0}\n\tand {:.0}", max, fmax, large);
         assert_eq!(Some(max), cast::<$f, $t>(max as $f));
         assert_eq!(Some(max), cast::<$f, $t>(fmax));
@@ -210,27 +201,27 @@ macro_rules! float_test_edge {
 }
 
 trait RawOffset: Sized {
-    type Raw;
-    fn raw_offset(self, offset: Self::Raw) -> Self;
+    fn raw_inc(self) -> Self;
+    fn raw_dec(self) -> Self;
 }
 
 impl RawOffset for f32 {
-    type Raw = i32;
-    fn raw_offset(self, offset: Self::Raw) -> Self {
-        unsafe {
-            let raw: Self::Raw = mem::transmute(self);
-            mem::transmute(raw + offset)
-        }
+    fn raw_inc(self) -> Self {
+        Self::from_bits(self.to_bits() + 1)
+    }
+
+    fn raw_dec(self) -> Self {
+        Self::from_bits(self.to_bits() - 1)
     }
 }
 
 impl RawOffset for f64 {
-    type Raw = i64;
-    fn raw_offset(self, offset: Self::Raw) -> Self {
-        unsafe {
-            let raw: Self::Raw = mem::transmute(self);
-            mem::transmute(raw + offset)
-        }
+    fn raw_inc(self) -> Self {
+        Self::from_bits(self.to_bits() + 1)
+    }
+
+    fn raw_dec(self) -> Self {
+        Self::from_bits(self.to_bits() - 1)
     }
 }
 
@@ -243,7 +234,6 @@ fn cast_float_to_int_edge_cases() {
 }
 
 #[test]
-#[cfg(has_i128)]
 fn cast_float_to_i128_edge_cases() {
     float_test_edge!(f32 -> i128 u128);
     float_test_edge!(f64 -> i128 u128);
@@ -302,7 +292,6 @@ fn cast_int_to_int_edge_cases() {
 }
 
 #[test]
-#[cfg(has_i128)]
 fn cast_int_to_128_edge_cases() {
     use core::cmp::Ordering::*;