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#[unstable(feature = "generic_nonzero", issue = "120257")]
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#[stable(feature = "nonzero", since = "1.28.0")]
32pub use core::num::{NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize};
33
34#[stable(feature = "int_error_matching", since = "1.55.0")]
35pub use core::num::IntErrorKind;
36
37#[cfg(test)]
38use crate::fmt;
39#[cfg(test)]
40use crate::ops::{Add, Div, Mul, Rem, Sub};
41
42/// Helper function for testing numeric operations
43#[cfg(test)]
44pub fn test_num<T>(ten: T, two: T)
45where
46 T: PartialEq
47 + Add<Output = T>
48 + Sub<Output = T>
49 + Mul<Output = T>
50 + Div<Output = T>
51 + Rem<Output = T>
52 + fmt::Debug
53 + Copy,
54{
55 assert_eq!(ten.add(two), ten + two);
56 assert_eq!(ten.sub(two), ten - two);
57 assert_eq!(ten.mul(two), ten * two);
58 assert_eq!(ten.div(two), ten / two);
59 assert_eq!(ten.rem(two), ten % two);
60}
61