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 #![stable(feature = "rust1", since = "1.0.0")]
7 #![allow(missing_docs)]
8
9 #[cfg(test)]
10 mod tests;
11
12 #[cfg(test)]
13 mod benches;
14
15 #[unstable(feature = "saturating_int_impl", issue = "87920")]
16 pub use core::num::Saturating;
17 #[stable(feature = "rust1", since = "1.0.0")]
18 pub use core::num::Wrapping;
19 #[stable(feature = "rust1", since = "1.0.0")]
20 pub use core::num::{FpCategory, ParseFloatError, ParseIntError, TryFromIntError};
21
22 #[stable(feature = "signed_nonzero", since = "1.34.0")]
23 pub use core::num::{NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize};
24 #[stable(feature = "nonzero", since = "1.28.0")]
25 pub use core::num::{NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize};
26
27 #[stable(feature = "int_error_matching", since = "1.55.0")]
28 pub use core::num::IntErrorKind;
29
30 #[cfg(test)]
31 use crate::fmt;
32 #[cfg(test)]
33 use crate::ops::{Add, Div, Mul, Rem, Sub};
34
35 /// Helper function for testing numeric operations
36 #[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,37 pub fn test_num<T>(ten: T, two: T)
38 where
39 T: PartialEq
40 + Add<Output = T>
41 + Sub<Output = T>
42 + Mul<Output = T>
43 + Div<Output = T>
44 + Rem<Output = T>
45 + fmt::Debug
46 + Copy,
47 {
48 assert_eq!(ten.add(two), ten + two);
49 assert_eq!(ten.sub(two), ten - two);
50 assert_eq!(ten.mul(two), ten * two);
51 assert_eq!(ten.div(two), ten / two);
52 assert_eq!(ten.rem(two), ten % two);
53 }
54