1use crate::*;
2
3macro_rules! impl_mixed_num_conversion{
4 ( $T1:ty, $T2:ty ) => {
5 impl MixedNumConversion<$T2> for $T1
6 {
7 #[inline(always)]
8 fn mixed_from_num( number:$T2 ) -> Self {
9 return number as Self;
10 }
11 #[inline(always)]
12 fn mixed_to_num( &self ) -> $T2 {
13 return *self as $T2;
14 }
15 }
16 }
17}
18
19macro_rules! impl_mixed_num_for_primitive{
20 ( $T:ty ) => {
21
22 impl MixedNum for $T
23 {
24 }
25
26 impl MixedOps for $T
27 {
28 }
29
30 impl_mixed_num_conversion!($T, f32);
31 impl_mixed_num_conversion!($T, f64);
32
33 impl_mixed_num_conversion!($T, usize);
34 impl_mixed_num_conversion!($T, isize);
35
36 impl_mixed_num_conversion!($T, u8);
37 impl_mixed_num_conversion!($T, u16);
38 impl_mixed_num_conversion!($T, u32);
39 impl_mixed_num_conversion!($T, u64);
40 impl_mixed_num_conversion!($T, u128);
41
42 impl_mixed_num_conversion!($T, i8);
43 impl_mixed_num_conversion!($T, i16);
44 impl_mixed_num_conversion!($T, i32);
45 impl_mixed_num_conversion!($T, i64);
46 impl_mixed_num_conversion!($T, i128);
47
48 impl MixedPowi for $T
49 {
50 #[inline(always)]
51 fn mixed_powi( &self, exp: i32 ) -> Self {
52 return trigonometry::powi( *self, exp as usize );
53 }
54 }
55
56 impl MixedZero for $T
57 {
58 #[inline(always)]
59 fn mixed_zero() -> Self {
60 return 0 as $T;
61 }
62 }
63
64 impl MixedOne for $T
65 {
66 #[inline(always)]
67 fn mixed_one() -> Self {
68 return 1 as $T;
69 }
70 }
71 }
72}
73
74macro_rules! impl_mixed_num_unsigned{
75 ( $T:ty ) => {
76 impl MixedReal for $T
77 {
78 #[inline(always)]
79 fn mixed_max_value() -> Self {
80 return Self::max_value();
81 }
82 #[inline(always)]
83 fn mixed_min_value() -> Self {
84 return Self::min_value();
85 }
86 fn mixed_sign( &self) -> Self {
87 return trigonometry::sign(*self);
88 }
89 #[inline(always)]
90 fn mixed_is_positive( &self) -> bool {
91 return true;
92 }
93 #[inline(always)]
94 fn mixed_is_negative( &self) -> bool {
95 return false;
96 }
97 }
98
99 impl MixedAbs for $T
100 {
101 #[inline(always)]
102 fn mixed_abs( &self ) -> Self {
103 return *self;
104 }
105 }
106 }
107}
108
109macro_rules! impl_mixed_num_signed{
110 ( $T:ty ) => {
111 impl MixedReal for $T
112 {
113 #[inline(always)]
114 fn mixed_max_value() -> Self {
115 return Self::max_value();
116 }
117 #[inline(always)]
118 fn mixed_min_value() -> Self {
119 return Self::min_value();
120 }
121 fn mixed_sign( &self) -> Self {
122 return trigonometry::sign(*self);
123 }
124 #[inline(always)]
125 fn mixed_is_positive( &self) -> bool {
126 return self.is_positive()
127 }
128 #[inline(always)]
129 fn mixed_is_negative( &self) -> bool {
130 return self.is_negative();
131 }
132 }
133
134 impl MixedAbs for $T
135 {
136 #[inline(always)]
137 fn mixed_abs( &self ) -> Self {
138 if 0<=*self
139 {
140 return *self;
141 }
142 else
143 {
144 return -self;
145 }
146 }
147 }
148
149 impl MixedNumSigned for $T
150 {
151 }
152 }
153}
154
155impl_mixed_num_for_primitive!(usize);
156impl_mixed_num_for_primitive!(u8);
157impl_mixed_num_for_primitive!(u16);
158impl_mixed_num_for_primitive!(u32);
159impl_mixed_num_for_primitive!(u64);
160impl_mixed_num_for_primitive!(u128);
161
162impl_mixed_num_unsigned!(usize);
163impl_mixed_num_unsigned!(u8);
164impl_mixed_num_unsigned!(u16);
165impl_mixed_num_unsigned!(u32);
166impl_mixed_num_unsigned!(u64);
167impl_mixed_num_unsigned!(u128);
168
169
170impl_mixed_num_for_primitive!(isize);
171impl_mixed_num_for_primitive!(i8);
172impl_mixed_num_for_primitive!(i16);
173impl_mixed_num_for_primitive!(i32);
174impl_mixed_num_for_primitive!(i64);
175impl_mixed_num_for_primitive!(i128);
176
177impl_mixed_num_signed!(isize);
178impl_mixed_num_signed!(i8);
179impl_mixed_num_signed!(i16);
180impl_mixed_num_signed!(i32);
181impl_mixed_num_signed!(i64);
182impl_mixed_num_signed!(i128);