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