1 //! Additional functionality for numerics.
2 //!
3 //! This module provides some extra types that are useful when doing numerical
4 //! work. See the individual documentation for each piece for more information.
5
6 #![allow(missing_docs)]
7
8 pub use core::num::Saturating;
9 pub use core::num::Wrapping;
10 pub use core::num::{FpCategory, ParseFloatError, ParseIntError, TryFromIntError};
11
12 pub use core::num::{NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize};
13 pub use core::num::{NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize};
14
15 pub use core::num::IntErrorKind;
16
17 #[cfg(test)]
18 use crate::std::fmt;
19 #[cfg(test)]
20 use crate::std::ops::{Add, Div, Mul, Rem, Sub};
21
22 /// Helper function for testing numeric operations
23 #[cfg(test)]
test_num<T>(ten: T, two: T) where T: PartialEq + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T> + Rem<Output = T> + fmt::Debug + Copy,24 pub fn test_num<T>(ten: T, two: T)
25 where
26 T: PartialEq
27 + Add<Output = T>
28 + Sub<Output = T>
29 + Mul<Output = T>
30 + Div<Output = T>
31 + Rem<Output = T>
32 + fmt::Debug
33 + Copy,
34 {
35 assert_eq!(ten.add(two), ten + two);
36 assert_eq!(ten.sub(two), ten - two);
37 assert_eq!(ten.mul(two), ten * two);
38 assert_eq!(ten.div(two), ten / two);
39 assert_eq!(ten.rem(two), ten % two);
40 }
41