1use crate::ops::AsProxy;
2use crate::ops::Rem;
3use crate::ops::Value;
4
5impl Rem<Value> for Value {
7 type Output = Value;
8 fn op_rem(self, rhs: Value) -> Self::Output {
9 match self {
10 Value::Int32(s) => {
11 let rhs = rhs.i32();
12 return Value::Int32(s % rhs);
13 }
14 Value::Int64(s) => {
15 let rhs = rhs.i64();
16 return Value::Int64(s % rhs);
17 }
18 Value::UInt32(s) => {
19 let rhs = rhs.u32();
20 return Value::UInt32(s % rhs);
21 }
22 Value::UInt64(s) => {
23 let rhs = rhs.u64();
24 return Value::UInt64(s % rhs);
25 }
26 Value::Double(s) => {
27 let rhs = rhs.as_f64().unwrap_or_default();
28 return Value::Double(s % rhs);
29 }
30 _ => {
31 return Value::Null;
32 }
33 };
34 }
35}
36
37impl Rem<&Value> for Value {
38 type Output = Value;
39 fn op_rem(self, rhs: &Value) -> Self::Output {
40 match self {
41 Value::Int32(s) => {
42 let rhs = rhs.i32();
43 return Value::Int32(s % rhs);
44 }
45 Value::Int64(s) => {
46 let rhs = rhs.i64();
47 return Value::Int64(s % rhs);
48 }
49 Value::UInt32(s) => {
50 let rhs = rhs.u32();
51 return Value::UInt32(s % rhs);
52 }
53 Value::UInt64(s) => {
54 let rhs = rhs.u64();
55 return Value::UInt64(s % rhs);
56 }
57 Value::Double(s) => {
58 let rhs = rhs.as_f64().unwrap_or_default();
59 return Value::Double(s % rhs);
60 }
61 _ => {
62 return Value::Null;
63 }
64 };
65 }
66}
67
68impl Rem<&&Value> for Value {
69 type Output = Value;
70 fn op_rem(self, rhs: &&Value) -> Self::Output {
71 match self {
72 Value::Int32(s) => {
73 let rhs = rhs.i32();
74 return Value::Int32(s % rhs);
75 }
76 Value::Int64(s) => {
77 let rhs = rhs.i64();
78 return Value::Int64(s % rhs);
79 }
80 Value::UInt32(s) => {
81 let rhs = rhs.u32();
82 return Value::UInt32(s % rhs);
83 }
84 Value::UInt64(s) => {
85 let rhs = rhs.u64();
86 return Value::UInt64(s % rhs);
87 }
88 Value::Double(s) => {
89 let rhs = rhs.as_f64().unwrap_or_default();
90 return Value::Double(s % rhs);
91 }
92 _ => {
93 return Value::Null;
94 }
95 };
96 }
97}
98
99impl Rem<Value> for &Value {
100 type Output = Value;
101 fn op_rem(self, rhs: Value) -> Self::Output {
102 match self {
103 Value::Int32(s) => {
104 let rhs = rhs.i32();
105 return Value::Int32(s % rhs);
106 }
107 Value::Int64(s) => {
108 let rhs = rhs.i64();
109 return Value::Int64(s % rhs);
110 }
111 Value::UInt32(s) => {
112 let rhs = rhs.u32();
113 return Value::UInt32(s % rhs);
114 }
115 Value::UInt64(s) => {
116 let rhs = rhs.u64();
117 return Value::UInt64(s % rhs);
118 }
119 Value::Double(s) => {
120 let rhs = rhs.as_f64().unwrap_or_default();
121 return Value::Double(s % rhs);
122 }
123 _ => {
124 return Value::Null;
125 }
126 };
127 }
128}
129
130impl Rem<&Value> for &Value {
131 type Output = Value;
132 fn op_rem(self, rhs: &Value) -> Self::Output {
133 match self {
134 Value::Int32(s) => {
135 let rhs = rhs.i32();
136 return Value::Int32(s % rhs);
137 }
138 Value::Int64(s) => {
139 let rhs = rhs.i64();
140 return Value::Int64(s % rhs);
141 }
142 Value::UInt32(s) => {
143 let rhs = rhs.u32();
144 return Value::UInt32(s % rhs);
145 }
146 Value::UInt64(s) => {
147 let rhs = rhs.u64();
148 return Value::UInt64(s % rhs);
149 }
150 Value::Double(s) => {
151 let rhs = rhs.as_f64().unwrap_or_default();
152 return Value::Double(s % rhs);
153 }
154 _ => {
155 return Value::Null;
156 }
157 };
158 }
159}
160
161impl Rem<&&Value> for &Value {
162 type Output = Value;
163 fn op_rem(self, rhs: &&Value) -> Self::Output {
164 match self {
165 Value::Int32(s) => {
166 let rhs = rhs.i32();
167 return Value::Int32(s % rhs);
168 }
169 Value::Int64(s) => {
170 let rhs = rhs.i64();
171 return Value::Int64(s % rhs);
172 }
173 Value::UInt32(s) => {
174 let rhs = rhs.u32();
175 return Value::UInt32(s % rhs);
176 }
177 Value::UInt64(s) => {
178 let rhs = rhs.u64();
179 return Value::UInt64(s % rhs);
180 }
181 Value::Double(s) => {
182 let rhs = rhs.as_f64().unwrap_or_default();
183 return Value::Double(s % rhs);
184 }
185 _ => {
186 return Value::Null;
187 }
188 };
189 }
190}
191
192fn op_rem_u64(value: &Value, other: u64) -> u64 {
193 value.u64() % other
194}
195
196fn op_rem_i64(value: &Value, other: i64) -> i64 {
197 value.i64() % other
198}
199
200fn op_rem_f64(value: &Value, other: f64) -> f64 {
201 value.f64() % other
202}
203
204fn op_rem_u64_value(value: &Value, other: u64) -> u64 {
205 other % value.u64()
206}
207
208fn op_rem_i64_value(value: &Value, other: i64) -> i64 {
209 other % value.i64()
210}
211
212fn op_rem_f64_value(value: &Value, other: f64) -> f64 {
213 other % value.f64()
214}
215
216macro_rules! impl_numeric_rem {
217 ($($rem:ident,$rem_value:ident [$($ty:ty)*]-> $return_ty:ty)*) => {
218 $($(
219 impl Rem<$ty> for Value {
220 type Output = $return_ty;
221 fn op_rem(self, other: $ty) -> Self::Output {
222 $rem(&self, other as _)
223 }
224 }
225
226 impl Rem<Value> for $ty {
227 type Output = $return_ty;
228 fn op_rem(self, other: Value) -> Self::Output {
229 $rem_value(&other, self as _)
230 }
231 }
232
233 impl Rem<&Value> for $ty {
234 type Output = $return_ty;
235 fn op_rem(self, other: &Value) -> Self::Output {
236 $rem_value(other, self as _)
237 }
238 }
239
240 impl Rem<&&Value> for $ty {
241 type Output = $return_ty;
242 fn op_rem(self, other: &&Value) -> Self::Output {
243 $rem_value(*other, self as _)
244 }
245 }
246
247 impl<'a> Rem<$ty> for &'a Value {
248 type Output = $return_ty;
249 fn op_rem(self, other: $ty) -> Self::Output {
250 $rem(self, other as _)
251 }
252 }
253 )*)*
254 }
255}
256
257impl_numeric_rem! {
258 op_rem_u64,op_rem_u64_value[u8 u16 u32 u64] -> u64
259 op_rem_i64,op_rem_i64_value[i8 i16 i32 i64 isize] -> i64
260 op_rem_f64,op_rem_f64_value[f32 f64] -> f64
261}
262
263macro_rules! rem_self {
264 ([$($ty:ty)*]) => {
265 $(
266impl Rem<$ty> for $ty{
267 type Output = $ty;
268 fn op_rem(self, rhs: $ty) -> Self::Output {
269 self % rhs
270 }
271 }
272impl Rem<&$ty> for $ty{
273 type Output = $ty;
274 fn op_rem(self, rhs: &$ty) -> Self::Output {
275 self % *rhs
276 }
277 }
278impl Rem<$ty> for &$ty{
279 type Output = $ty;
280 fn op_rem(self, rhs: $ty) -> Self::Output {
281 *self % rhs
282 }
283 }
284impl Rem<&$ty> for &$ty{
285 type Output = $ty;
286 fn op_rem(self, rhs: &$ty) -> Self::Output {
287 *self % *rhs
288 }
289 }
290 )*
291 };
292}
293rem_self!([u8 u16 u32 u64]);
294rem_self!([i8 i16 i32 i64 isize]);
295rem_self!([f32 f64]);