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
113macro_rules! impl_non_zero {
117 ($($t:ident),+) => {
118 $(
119 impl One for $t {
120 const ONE: Self = match Self::new(1) {
121 Some(v) => v,
122 None => unreachable!() };
124 }
125
126 impl Two for $t {
127 const TWO: Self = match Self::new(2) {
128 Some(v) => v,
129 None => unreachable!() };
131 }
132 )+
133 };
134 ($($u:ident && $i:ident),+) => {
135 $(
136 impl_non_zero!($u, $i);
137
138 impl NegativeOne for $i {
139 const NEGATIVE_ONE: Self = match Self::new(-1) {
140 Some(v) => v,
141 None => unreachable!() };
143 }
144 )+
145 }
146}
147
148impl_non_zero!(
149 NonZeroUsize && NonZeroIsize,
150 NonZeroU128 && NonZeroI128,
151 NonZeroU64 && NonZeroI64,
152 NonZeroU32 && NonZeroI32,
153 NonZeroU16 && NonZeroI16,
154 NonZeroU8 && NonZeroI8
155);