]> git.lizzy.rs Git - rust.git/blob - library/std/src/num.rs
std: move "mod tests/benches" to separate files
[rust.git] / library / std / src / num.rs
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 #[stable(feature = "rust1", since = "1.0.0")]
16 pub use core::num::Wrapping;
17 #[stable(feature = "rust1", since = "1.0.0")]
18 pub use core::num::{FpCategory, ParseFloatError, ParseIntError, TryFromIntError};
19
20 #[stable(feature = "signed_nonzero", since = "1.34.0")]
21 pub use core::num::{NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize};
22 #[stable(feature = "nonzero", since = "1.28.0")]
23 pub use core::num::{NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize};
24
25 #[unstable(
26     feature = "int_error_matching",
27     reason = "it can be useful to match errors when making error messages \
28               for integer parsing",
29     issue = "22639"
30 )]
31 pub use core::num::IntErrorKind;
32
33 #[cfg(test)]
34 use crate::fmt;
35 #[cfg(test)]
36 use crate::ops::{Add, Div, Mul, Rem, Sub};
37
38 /// Helper function for testing numeric operations
39 #[cfg(test)]
40 pub fn test_num<T>(ten: T, two: T)
41 where
42     T: PartialEq
43         + Add<Output = T>
44         + Sub<Output = T>
45         + Mul<Output = T>
46         + Div<Output = T>
47         + Rem<Output = T>
48         + fmt::Debug
49         + Copy,
50 {
51     assert_eq!(ten.add(two), ten + two);
52     assert_eq!(ten.sub(two), ten - two);
53     assert_eq!(ten.mul(two), ten * two);
54     assert_eq!(ten.div(two), ten / two);
55     assert_eq!(ten.rem(two), ten % two);
56 }