malachite_base/num/basic/
traits.rs1use core::num::*;
12
13#[allow(clippy::declare_interior_mutable_const)]
15pub trait Zero {
16 const ZERO: Self;
17}
18
19#[allow(clippy::declare_interior_mutable_const)]
21pub trait One {
22 const ONE: Self;
23}
24
25#[allow(clippy::declare_interior_mutable_const)]
27pub trait Two {
28 const TWO: Self;
29}
30
31#[allow(clippy::declare_interior_mutable_const)]
33pub trait NegativeOne {
34 const NEGATIVE_ONE: Self;
35}
36
37#[allow(clippy::declare_interior_mutable_const)]
39pub trait OneHalf {
40 const ONE_HALF: Self;
41}
42
43#[allow(clippy::declare_interior_mutable_const)]
45pub trait NegativeZero {
46 const NEGATIVE_ZERO: Self;
47}
48
49#[allow(clippy::declare_interior_mutable_const)]
51pub trait Infinity {
52 const INFINITY: Self;
53}
54
55#[allow(clippy::declare_interior_mutable_const)]
57pub trait NegativeInfinity {
58 const NEGATIVE_INFINITY: Self;
59}
60
61#[allow(clippy::declare_interior_mutable_const)]
63pub trait NaN {
64 const NAN: Self;
65}
66
67pub trait ThueMorseConstant {
69 const THUE_MORSE_CONSTANT: Self;
70}
71
72pub trait PrimeConstant {
75 const PRIME_CONSTANT: Self;
76}
77
78macro_rules! impl_non_zero {
82 ($($t:ident),+) => {
83 $(
84 impl One for $t {
85 const ONE: Self = match Self::new(1) {
86 Some(v) => v,
87 None => unreachable!() };
89 }
90
91 impl Two for $t {
92 const TWO: Self = match Self::new(2) {
93 Some(v) => v,
94 None => unreachable!() };
96 }
97 )+
98 };
99 ($($u:ident && $i:ident),+) => {
100 $(
101 impl_non_zero!($u, $i);
102
103 impl NegativeOne for $i {
104 const NEGATIVE_ONE: Self = match Self::new(-1) {
105 Some(v) => v,
106 None => unreachable!() };
108 }
109 )+
110 }
111}
112
113impl_non_zero!(
114 NonZeroUsize && NonZeroIsize,
115 NonZeroU128 && NonZeroI128,
116 NonZeroU64 && NonZeroI64,
117 NonZeroU32 && NonZeroI32,
118 NonZeroU16 && NonZeroI16,
119 NonZeroU8 && NonZeroI8
120);