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 ProuhetThueMorseConstant {
69 const PROUHET_THUE_MORSE_CONSTANT: Self;
70}
71
72pub trait PrimeConstant {
75 const PRIME_CONSTANT: Self;
76}
77
78pub trait Ln2 {
80 const LN_2: Self;
81}
82
83pub trait Log2E {
85 const LOG_2_E: Self;
86}
87
88pub trait Sqrt2 {
90 const SQRT_2: Self;
91}
92
93pub trait Sqrt3 {
95 const SQRT_3: Self;
96}
97
98pub trait Sqrt2Over2 {
100 const SQRT_2_OVER_2: Self;
101}
102
103pub trait Sqrt3Over3 {
105 const SQRT_3_OVER_3: Self;
106}
107
108pub trait Phi {
110 const PHI: Self;
111}
112
113pub trait Pi {
115 const PI: Self;
116}
117
118pub trait Tau {
120 const TAU: Self;
121}
122
123pub trait PiOver2 {
125 const PI_OVER_2: Self;
126}
127
128pub trait PiOver3 {
130 const PI_OVER_3: Self;
131}
132
133pub trait PiOver4 {
135 const PI_OVER_4: Self;
136}
137
138pub trait PiOver6 {
140 const PI_OVER_6: Self;
141}
142
143pub trait PiOver8 {
145 const PI_OVER_8: Self;
146}
147
148pub trait OneOverPi {
150 const ONE_OVER_PI: Self;
151}
152
153pub trait SqrtPi {
155 const SQRT_PI: Self;
156}
157
158pub trait OneOverSqrtPi {
160 const ONE_OVER_SQRT_PI: Self;
161}
162
163pub trait OneOverSqrtTau {
165 const ONE_OVER_SQRT_TAU: Self;
166}
167
168pub trait TwoOverPi {
170 const TWO_OVER_PI: Self;
171}
172
173pub trait TwoOverSqrtPi {
175 const TWO_OVER_SQRT_PI: Self;
176}
177
178pub trait GaussConstant {
183 const GAUSS_CONSTANT: Self;
184}
185
186pub trait LemniscateConstant {
188 const LEMNISCATE_CONSTANT: Self;
189}
190
191macro_rules! impl_non_zero {
195 ($($t:ident),+) => {
196 $(
197 impl One for $t {
198 const ONE: Self = match Self::new(1) {
199 Some(v) => v,
200 None => unreachable!() };
202 }
203
204 impl Two for $t {
205 const TWO: Self = match Self::new(2) {
206 Some(v) => v,
207 None => unreachable!() };
209 }
210 )+
211 };
212 ($($u:ident && $i:ident),+) => {
213 $(
214 impl_non_zero!($u, $i);
215
216 impl NegativeOne for $i {
217 const NEGATIVE_ONE: Self = match Self::new(-1) {
218 Some(v) => v,
219 None => unreachable!() };
221 }
222 )+
223 }
224}
225
226impl_non_zero!(
227 NonZeroUsize && NonZeroIsize,
228 NonZeroU128 && NonZeroI128,
229 NonZeroU64 && NonZeroI64,
230 NonZeroU32 && NonZeroI32,
231 NonZeroU16 && NonZeroI16,
232 NonZeroU8 && NonZeroI8
233);