1use traiter::numbers::Abs;
2
3use crate::big_int::BigInt;
4
5use super::types::Fraction;
6
7impl<'a, Digit, const DIGIT_BITNESS: usize> Abs
8 for &'a Fraction<BigInt<Digit, DIGIT_BITNESS>>
9where
10 BigInt<Digit, DIGIT_BITNESS>: Clone,
11 &'a BigInt<Digit, DIGIT_BITNESS>:
12 Abs<Output = BigInt<Digit, DIGIT_BITNESS>>,
13{
14 type Output = Fraction<BigInt<Digit, DIGIT_BITNESS>>;
15
16 fn abs(self) -> Self::Output {
17 Self::Output {
18 numerator: (&self.numerator).abs(),
19 denominator: self.denominator.clone(),
20 }
21 }
22}
23
24impl<Digit, const DIGIT_BITNESS: usize> Abs
25 for Fraction<BigInt<Digit, DIGIT_BITNESS>>
26{
27 type Output = Self;
28
29 fn abs(self) -> Self::Output {
30 Self::Output {
31 numerator: self.numerator.abs(),
32 denominator: self.denominator,
33 }
34 }
35}
36
37macro_rules! signed_integer_fraction_abs_impl {
38 ($($integer:ty)*) => ($(
39 impl Abs for &Fraction<$integer> {
40 type Output = Fraction<$integer>;
41
42 fn abs(self) -> Self::Output {
43 Self::Output {
44 numerator: self.numerator.abs(),
45 denominator: self.denominator,
46 }
47 }
48 }
49
50 impl Abs for Fraction<$integer> {
51 type Output = Self;
52
53 fn abs(self) -> Self::Output {
54 Self::Output {
55 numerator: self.numerator.abs(),
56 denominator: self.denominator,
57 }
58 }
59 }
60 )*)
61}
62
63signed_integer_fraction_abs_impl!(i8 i16 i32 i64 i128 isize);