devela/num/int/wrapper/
impl_div.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
// devela::num::int::wrapper::impl_div
//
//! Implements division-related methods for [`Int`].
//
// TOC
// - signed|unsigned:
//   - div_rem
//   - div_ceil
//   - div_floor
//   - div_ties_away
//   - div_ties_towards
//   - div_ties_even
//   - div_ties_odd

use super::super::shared_docs::*;
use crate::{iif, paste, Int};

/// Implements division-related methods for [`Int`].
///
/// # Args
/// $t:   the input/output type
/// $cap: the capability feature that enables the given implementation. E.g "_int_i8"
///
/// $d:   the doclink suffix for the method name
macro_rules! impl_div {
    () => {
        impl_div![signed
            i8    :"_int_i8":"",
            i16   :"_int_i16":"-1",
            i32   :"_int_i32":"-2",
            i64   :"_int_i64":"-3",
            i128  :"_int_i128":"-4",
            isize :"_int_isize":"-5"
        ];
        impl_div![unsigned
            u8    :"_int_u8"    :"-6",
            u16   :"_int_u16"   :"-7",
            u32   :"_int_u32"   :"-8",
            u64   :"_int_u64"   :"-9",
            u128  :"_int_u128"  :"-10",
            usize :"_int_usize" :"-11"
        ];
    };
    (signed $( $t:ty : $cap:literal : $d:literal ),+) => {
        $( impl_div![@signed $t:$cap:$d]; )+
    };
    (unsigned $( $t:ty : $cap:literal : $d:literal ),+) => {
        $( impl_div![@unsigned $t:$cap:$d]; )+
    };
    (
    // implements signed ops
    @signed $t:ty : $cap:literal : $d:literal) => { paste! {
        #[doc = crate::doc_availability!(feature = $cap)]
        ///
        #[doc = "# Integer division related methods for `" $t "`\n\n"]
        #[doc = "- [div_rem](#method.div_rem" $d ")"]
        #[doc = "- [div_ceil](#method.div_ceil" $d ")"]
        #[doc = "- [div_floor](#method.div_floor" $d ")"]
        #[doc = "- [div_ties_away](#method.div_ties_away" $d ")"]
        #[doc = "- [div_ties_towards](#method.div_ties_towards" $d ")"]
        #[doc = "- [div_ties_even](#method.div_ties_even" $d ")"]
        #[doc = "- [div_ties_odd](#method.div_ties_odd" $d ")"]
        ///
        #[cfg(feature = $cap )]
        #[cfg_attr(feature = "nightly_doc", doc(cfg(feature = $cap)))]
        impl Int<$t> {
            /// Returns the truncated quotient and the remainder.
            #[must_use]
            pub const fn div_rem(self, b: $t) -> [Int<$t>; 2] {
                let a = self.0; [Int(a / b), Int(a % b)]
            }

            /// Returns the quotient, rounding the result towards positive infinity.
            #[doc = NOTATION_DIV_CEIL!()]
            ///
            /// # Formulation
            #[doc = FORMULA_DIV_CEIL!()]
            /// # Examples
            /// ```
            /// # use devela::Int;
            #[doc = "assert_eq![Int(7_" $t ").div_ceil(3), Int(3)]; // == 2.33…"]
            #[doc = "assert_eq![Int(7_" $t ").div_ceil(-3), Int(-2)];"]
            #[doc = "assert_eq![Int(-7_" $t ").div_ceil(3), Int(-2)];"]
            #[doc = "assert_eq![Int(-7_" $t ").div_ceil(-3), Int(3)];"]
            ///
            #[doc = "assert_eq![Int(7_" $t ").div_ceil(5), Int(2)]; // == 1.4"]
            #[doc = "assert_eq![Int(6_" $t ").div_ceil(4), Int(2)]; // == 1.5"]
            #[doc = "assert_eq![Int(8_" $t ").div_ceil(5), Int(2)]; // == 1.6"]
            #[doc = "assert_eq![Int(5_" $t ").div_ceil(2), Int(3)]; // == 2.5"]
            #[doc = "assert_eq![Int(-7_" $t ").div_ceil(5), Int(-1)]; // == -1.4"]
            #[doc = "assert_eq![Int(-6_" $t ").div_ceil(4), Int(-1)]; // == -1.5"]
            #[doc = "assert_eq![Int(-8_" $t ").div_ceil(5), Int(-1)]; // == -1.6"]
            #[doc = "assert_eq![Int(-5_" $t ").div_ceil(2), Int(-2)]; // == -2.5"]
            /// ```
            // unstable rust implementation for signed integers:
            // WAIT: [int_roundings](https://github.com/rust-lang/rust/issues/88581)
            #[must_use]
            pub const fn div_ceil(self, b: $t) -> Int<$t> {
                let a = self.0; let (d, r) = (a / b, a % b);
                iif![(r > 0 && b > 0) || (r < 0 && b < 0); Int(d + 1); Int(d)]
            }
            // alternative implementation:
            // pub const fn div_ceil(self, b: $t) -> $t {
            //     let a = self.0; iif![a > 0 && b > 0; ((a - 1) / b) + 1 ; a / b ]
            // }

            /// Returns the quotient, rounding the result towards negative infinity.
            #[doc = NOTATION_DIV_FLOOR!()]
            /// # Examples
            /// ```
            /// # use devela::Int;
            #[doc = "assert_eq![Int(7_" $t ").div_floor(3), Int(2)]; // == 2.33…"]
            #[doc = "assert_eq![Int(7_" $t ").div_floor(-3), Int(-3)];"]
            #[doc = "assert_eq![Int(-7_" $t ").div_floor(3), Int(-3)];"]
            #[doc = "assert_eq![Int(-7_" $t ").div_floor(-3), Int(2)];"]
            ///
            #[doc = "assert_eq![Int(7_" $t ").div_floor(5), Int(1)]; // == 1.4"]
            #[doc = "assert_eq![Int(6_" $t ").div_floor(4), Int(1)]; // == 1.5"]
            #[doc = "assert_eq![Int(8_" $t ").div_floor(5), Int(1)]; // == 1.6"]
            #[doc = "assert_eq![Int(5_" $t ").div_floor(2), Int(2)]; // == 2.5"]
            #[doc = "assert_eq![Int(-7_" $t ").div_floor(5), Int(-2)]; // == -1.4"]
            #[doc = "assert_eq![Int(-6_" $t ").div_floor(4), Int(-2)]; // == -1.5"]
            #[doc = "assert_eq![Int(-8_" $t ").div_floor(5), Int(-2)]; // == -1.6"]
            #[doc = "assert_eq![Int(-5_" $t ").div_floor(2), Int(-3)]; // == -2.5"]
            /// ```
            // unstable rust implementation for signed integers:
            // WAIT: [int_roundings](https://github.com/rust-lang/rust/issues/88581)
            #[must_use]
            pub const fn div_floor(self, b: $t) -> Int<$t> {
                let a = self.0; let (d, r) = (a / b, a % b);
                iif![(r > 0 && b < 0) || (r < 0 && b > 0); Int(d - 1); Int(d)]
            }

            /// Returns the quotient, rounding ties away from zero.
            /// # Examples
            /// ```
            /// # use devela::Int;
            #[doc = "assert_eq![Int(7_" $t ").div_ties_away(3), Int(2)]; // == 2.33…"]
            #[doc = "assert_eq![Int(7_" $t ").div_ties_away(-3), Int(-2)];"]
            #[doc = "assert_eq![Int(-7_" $t ").div_ties_away(3), Int(-2)];"]
            #[doc = "assert_eq![Int(-7_" $t ").div_ties_away(-3), Int(2)];"]
            ///
            #[doc = "assert_eq![Int(7_" $t ").div_ties_away(5), Int(1)]; // == 1.4"]
            #[doc = "assert_eq![Int(6_" $t ").div_ties_away(4), Int(2)]; // == 1.5"]
            #[doc = "assert_eq![Int(8_" $t ").div_ties_away(5), Int(2)]; // == 1.6"]
            #[doc = "assert_eq![Int(5_" $t ").div_ties_away(2), Int(3)]; // == 2.5"]
            #[doc = "assert_eq![Int(-7_" $t ").div_ties_away(5), Int(-1)]; // == -1.4"]
            #[doc = "assert_eq![Int(-6_" $t ").div_ties_away(4), Int(-2)]; // == -1.5"]
            #[doc = "assert_eq![Int(-8_" $t ").div_ties_away(5), Int(-2)]; // == -1.6"]
            #[doc = "assert_eq![Int(-5_" $t ").div_ties_away(2), Int(-3)]; // == -2.5"]
            /// ```
            #[must_use]
            pub const fn div_ties_away(self, b: $t) -> Int<$t> {
                let a = self.0; let (d, r) = (a / b, a % b);
                iif![2 * r.abs() >= b.abs();
                    iif![(a > 0) == (b > 0); Int(d + 1); Int(d - 1)]; Int(d)]
            }

            /// Returns the quotient, rounding ties towards zero.
            /// # Examples
            /// ```
            /// # use devela::Int;
            #[doc = "assert_eq![Int(7_" $t ").div_ties_towards(3), Int(2)]; // == 2.33…"]
            #[doc = "assert_eq![Int(7_" $t ").div_ties_towards(-3), Int(-2)];"]
            #[doc = "assert_eq![Int(-7_" $t ").div_ties_towards(3), Int(-2)];"]
            #[doc = "assert_eq![Int(-7_" $t ").div_ties_towards(-3), Int(2)];"]
            ///
            #[doc = "assert_eq![Int(7_" $t ").div_ties_towards(5), Int(1)]; // == 1.4"]
            #[doc = "assert_eq![Int(6_" $t ").div_ties_towards(4), Int(1)]; // == 1.5"]
            #[doc = "assert_eq![Int(8_" $t ").div_ties_towards(5), Int(2)]; // == 1.6"]
            #[doc = "assert_eq![Int(5_" $t ").div_ties_towards(2), Int(2)]; // == 2.5"]
            #[doc = "assert_eq![Int(-7_" $t ").div_ties_towards(5), Int(-1)]; // == -1.4"]
            #[doc = "assert_eq![Int(-6_" $t ").div_ties_towards(4), Int(-1)]; // == -1.5"]
            #[doc = "assert_eq![Int(-8_" $t ").div_ties_towards(5), Int(-2)]; // == -1.6"]
            #[doc = "assert_eq![Int(-5_" $t ").div_ties_towards(2), Int(-2)]; // == -2.5"]
            /// ```
            #[must_use]
            pub const fn div_ties_towards(self, b: $t) -> Int<$t> {
                let a = self.0; let (d, r) = (a / b, a % b);
                iif![2 * r.abs() > b.abs();
                    iif![(a > 0) == (b > 0); Int(d + 1); Int(d - 1)]; Int(d)]
            }

            /// Returns the quotient, rounding ties to the nearest even number.
            /// # Examples
            /// ```
            /// # use devela::Int;
            #[doc = "assert_eq![Int(7_" $t ").div_ties_even(3), Int(2)]; // == 2.33…"]
            #[doc = "assert_eq![Int(7_" $t ").div_ties_even(-3), Int(-2)];"]
            #[doc = "assert_eq![Int(-7_" $t ").div_ties_even(3), Int(-2)];"]
            #[doc = "assert_eq![Int(-7_" $t ").div_ties_even(-3), Int(2)];"]
            ///
            #[doc = "assert_eq![Int(7_" $t ").div_ties_even(5), Int(1)]; // == 1.4"]
            #[doc = "assert_eq![Int(6_" $t ").div_ties_even(4), Int(2)]; // == 1.5"]
            #[doc = "assert_eq![Int(8_" $t ").div_ties_even(5), Int(2)]; // == 1.6"]
            #[doc = "assert_eq![Int(5_" $t ").div_ties_even(2), Int(2)]; // == 2.5"]
            #[doc = "assert_eq![Int(-7_" $t ").div_ties_even(5), Int(-1)]; // == -1.4"]
            #[doc = "assert_eq![Int(-6_" $t ").div_ties_even(4), Int(-2)]; // == -1.5"]
            #[doc = "assert_eq![Int(-8_" $t ").div_ties_even(5), Int(-2)]; // == -1.6"]
            #[doc = "assert_eq![Int(-5_" $t ").div_ties_even(2), Int(-2)]; // == -2.5"]
            /// ```
            #[must_use]
            pub const fn div_ties_even(self, b: $t) -> Int<$t> {
                let a = self.0; let (d, r) = (a / b, a % b);
                // If the remainder is zero or the |remainder| is less than half of
                // |b|, return the quotient.
                iif![r == 0 || 2 * r.abs() < b.abs(); Int(d);
                    // If the |remainder| is greater than half of b,
                    // return the quotient + the sign of a × the sign of b.
                    iif![2 * r.abs() > b.abs(); Int(d + a.signum() * b.signum());
                        // If the quotient is even return it, otherwise return
                        // the quotient + the sign of a × the sign of b.
                        iif![d % 2 == 0; Int(d); Int(d + a.signum() * b.signum())] ] ]
            }

            /// Returns the quotient, rounding ties to the nearest odd number.
            /// # Examples
            /// ```
            /// # use devela::Int;
            #[doc = "assert_eq![Int(7_" $t ").div_ties_odd(3), Int(2)]; // == 2.33…"]
            #[doc = "assert_eq![Int(7_" $t ").div_ties_odd(-3), Int(-2)];"]
            #[doc = "assert_eq![Int(-7_" $t ").div_ties_odd(3), Int(-2)];"]
            #[doc = "assert_eq![Int(-7_" $t ").div_ties_odd(-3), Int(2)];"]
            ///
            #[doc = "assert_eq![Int(7_" $t ").div_ties_odd(5), Int(1)]; // == 1.4"]
            #[doc = "assert_eq![Int(6_" $t ").div_ties_odd(4), Int(1)]; // == 1.5"]
            #[doc = "assert_eq![Int(8_" $t ").div_ties_odd(5), Int(2)]; // == 1.6"]
            #[doc = "assert_eq![Int(5_" $t ").div_ties_odd(2), Int(3)]; // == 2.5"]
            #[doc = "assert_eq![Int(-7_" $t ").div_ties_odd(5), Int(-1)]; // == -1.4"]
            #[doc = "assert_eq![Int(-6_" $t ").div_ties_odd(4), Int(-1)]; // == -1.5"]
            #[doc = "assert_eq![Int(-8_" $t ").div_ties_odd(5), Int(-2)]; // == -1.6"]
            #[doc = "assert_eq![Int(-5_" $t ").div_ties_odd(2), Int(-3)]; // == -2.5"]
            /// ```
            #[must_use]
            pub const fn div_ties_odd(self, b: $t) -> Int<$t> {
                let a = self.0; let (d, r) = (a / b, a % b);
                // If the remainder is zero or the |remainder| is less than half of
                // |b|, return the quotient.
                iif![r == 0 || 2 * r.abs() < b.abs(); Int(d);
                    // If the |remainder| is greater than half of b,
                    // return the quotient + the sign of a × the sign of b.
                    iif![2 * r.abs() > b.abs(); Int(d + a.signum() * b.signum());
                        // If the quotient is odd return it, otherwise return
                        // the quotient + the sign of a × the sign of b.
                        iif![d % 2 != 0; Int(d); Int(d + a.signum() * b.signum())] ] ]
            }
        }
    }};
    (
    // implements unsigned ops
    @unsigned $t:ty : $cap:literal : $d:literal) => { paste! {
        #[doc = crate::doc_availability!(feature = $cap)]
        ///
        #[doc = "# Integer division related methods for `" $t "`\n\n"]
        #[doc = "- [div_rem](#method.div_rem" $d ")"]
        #[doc = "- [div_ceil](#method.div_ceil" $d ")"]
        #[doc = "- [div_floor](#method.div_floor" $d ")"]
        #[doc = "- [div_ties_away](#method.div_ties_away" $d ")"]
        #[doc = "- [div_ties_towards](#method.div_ties_towards" $d ")"]
        #[doc = "- [div_ties_even](#method.div_ties_even" $d ")"]
        #[doc = "- [div_ties_odd](#method.div_ties_odd" $d ")"]
        ///
        #[cfg(feature = $cap )]
        // #[cfg_attr(feature = "nightly_doc", doc(cfg(feature = $cap)))]
        impl Int<$t> {
            /* unsigned division */

            /// Returns the truncated quotient and the remainder.
            #[must_use]
            pub const fn div_rem(self, b: $t) -> [Int<$t>; 2] {
                let a = self.0; [Int(a / b), Int(a % b)]
            }

            /// Returns the quotient, rounding the result towards positive infinity.
            #[doc = NOTATION_DIV_CEIL!()]
            /// # Examples
            /// ```
            /// # use devela::Int;
            #[doc = "assert_eq![Int(7_" $t ").div_ceil(3), Int(3)]; // == 2.33…"]
            ///
            #[doc = "assert_eq![Int(7_" $t ").div_ceil(5), Int(2)]; // == 1.4"]
            #[doc = "assert_eq![Int(6_" $t ").div_ceil(4), Int(2)]; // == 1.5"]
            #[doc = "assert_eq![Int(8_" $t ").div_ceil(5), Int(2)]; // == 1.6"]
            #[doc = "assert_eq![Int(5_" $t ").div_ceil(2), Int(3)]; // == 2.5"]
            /// ```
            // unstable rust implementation for signed integers:
            // WAIT: [int_roundings](https://github.com/rust-lang/rust/issues/88581)
            #[must_use]
            pub const fn div_ceil(self, b: $t) -> Int<$t> {
                let a = self.0; let (d, r) = (a / b, a % b);
                iif![r > 0 && b > 0; Int(d + 1); Int(d)]
            }
            // alternative implementation:
            // pub const fn div_ceil(self, b: $t) -> $t {
            //     let a = self.0; iif![a > 0 && b > 0; ((a - 1) / b) + 1; a / b ]
            // }

            /// Returns the quotient, rounding the result towards negative infinity.
            #[doc = NOTATION_DIV_FLOOR!()]
            /// # Examples
            /// ```
            /// # use devela::Int;
            #[doc = "assert_eq![Int(7_" $t ").div_floor(3), Int(2)]; // == 2.33…"]
            ///
            #[doc = "assert_eq![Int(7_" $t ").div_floor(5), Int(1)]; // == 1.4"]
            #[doc = "assert_eq![Int(6_" $t ").div_floor(4), Int(1)]; // == 1.5"]
            #[doc = "assert_eq![Int(8_" $t ").div_floor(5), Int(1)]; // == 1.6"]
            #[doc = "assert_eq![Int(5_" $t ").div_floor(2), Int(2)]; // == 2.5"]
            /// ```
            // unstable rust implementation for signed integers:
            // WAIT: [int_roundings](https://github.com/rust-lang/rust/issues/88581)
            #[must_use]
            pub const fn div_floor(self, b: $t) -> Int<$t> {
                Int(self.0 / b)
            }

            /// Returns the quotient, rounding ties away from zero.
            /// # Examples
            /// ```
            /// # use devela::Int;
            #[doc = "assert_eq![Int(7_" $t ").div_ties_away(3), Int(2)]; // == 2.33…"]
            ///
            #[doc = "assert_eq![Int(7_" $t ").div_ties_away(5), Int(1)]; // == 1.4"]
            #[doc = "assert_eq![Int(6_" $t ").div_ties_away(4), Int(2)]; // == 1.5"]
            #[doc = "assert_eq![Int(8_" $t ").div_ties_away(5), Int(2)]; // == 1.6"]
            #[doc = "assert_eq![Int(5_" $t ").div_ties_away(2), Int(3)]; // == 2.5"]
            /// ```
            #[must_use]
            pub const fn div_ties_away(self, b: $t) -> Int<$t> {
                let a = self.0; let (d, r) = (a / b, a % b);
                iif![2 * r >= b; iif![a > b; Int(d + 1); Int(d - 1)]; Int(d)]
            }

            /// Returns the quotient, rounding ties towards zero.
            /// # Examples
            /// ```
            /// # use devela::Int;
            #[doc = "assert_eq![Int(7_" $t ").div_ties_towards(3), Int(2)]; // == 2.33…"]
            ///
            #[doc = "assert_eq![Int(7_" $t ").div_ties_towards(5), Int(1)]; // == 1.4"]
            #[doc = "assert_eq![Int(6_" $t ").div_ties_towards(4), Int(1)]; // == 1.5"]
            #[doc = "assert_eq![Int(8_" $t ").div_ties_towards(5), Int(2)]; // == 1.6"]
            #[doc = "assert_eq![Int(5_" $t ").div_ties_towards(2), Int(2)]; // == 2.5"]
            /// ```
            #[must_use]
            pub const fn div_ties_towards(self, b: $t) -> Int<$t> {
                let a = self.0; let (d, r) = (a / b, a % b);
                iif![2 * r > b; Int(d + 1); Int(d)]
            }

            /// Returns the quotient, rounding ties to the nearest even number.
            /// # Examples
            /// ```
            /// # use devela::Int;
            #[doc = "assert_eq![Int(7_" $t ").div_ties_even(3), Int(2)]; // == 2.33…"]
            ///
            #[doc = "assert_eq![Int(7_" $t ").div_ties_even(5), Int(1)]; // == 1.4"]
            #[doc = "assert_eq![Int(6_" $t ").div_ties_even(4), Int(2)]; // == 1.5"]
            #[doc = "assert_eq![Int(8_" $t ").div_ties_even(5), Int(2)]; // == 1.6"]
            #[doc = "assert_eq![Int(5_" $t ").div_ties_even(2), Int(2)]; // == 2.5"]
            /// ```
            #[must_use]
            pub const fn div_ties_even(self, b: $t) -> Int<$t> {
                let a = self.0; let (d, r) = (a / b, a % b);
                // 1. If the remainder is zero or less than half of b, return the quotient.
                // 2. If the remainder is greater than half of b, return the quotient + 1.
                // 3. If the quotient is _EVEN_ return it, otherwise return the quotient + 1.
                iif![r == 0 || 2 * r < b; Int(d);
                    iif![2 * r > b; Int(d + 1);
                        iif![d % 2 == 0; Int(d); Int(d + 1)]]]
            }

            /// Returns the quotient, rounding ties to the nearest even number.
            /// # Examples
            /// ```
            /// # use devela::Int;
            #[doc = "assert_eq![Int(7_" $t ").div_ties_odd(3), Int(2)]; // == 2.33…"]
            ///
            #[doc = "assert_eq![Int(7_" $t ").div_ties_odd(5), Int(1)]; // == 1.4"]
            #[doc = "assert_eq![Int(6_" $t ").div_ties_odd(4), Int(1)]; // == 1.5"]
            #[doc = "assert_eq![Int(8_" $t ").div_ties_odd(5), Int(2)]; // == 1.6"]
            #[doc = "assert_eq![Int(5_" $t ").div_ties_odd(2), Int(3)]; // == 2.5"]
            /// ```
            #[must_use]
            pub const fn div_ties_odd(self, b: $t) -> Int<$t> {
                let a = self.0; let (d, r) = (a / b, a % b);
                // 1. If the remainder is zero or less than half of b, return the quotient.
                // 2. If the remainder is greater than half of b, return the quotient + 1.
                // 3. If the quotient is _ODD_ return it, otherwise return the quotient + 1.
                iif![r == 0 || 2 * r < b; Int(d);
                    iif![2 * r > b; Int(d + 1);
                        iif![d % 2 != 0; Int(d); Int(d + 1)]]]
            }
        }
    }};
}
impl_div!();