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
use std::ops::Neg;
use crate::big_int::BigInt;
use super::types::Fraction;
impl<Digit, const DIGIT_BITNESS: usize> Neg
for Fraction<BigInt<Digit, DIGIT_BITNESS>>
where
BigInt<Digit, DIGIT_BITNESS>: Neg<Output = BigInt<Digit, DIGIT_BITNESS>>,
{
type Output = Self;
fn neg(self) -> Self::Output {
Self::Output {
numerator: -self.numerator,
denominator: self.denominator,
}
}
}
impl<Digit, const DIGIT_BITNESS: usize> Neg
for &Fraction<BigInt<Digit, DIGIT_BITNESS>>
where
BigInt<Digit, DIGIT_BITNESS>: Clone,
for<'a> &'a BigInt<Digit, DIGIT_BITNESS>:
Neg<Output = BigInt<Digit, DIGIT_BITNESS>>,
{
type Output = Fraction<BigInt<Digit, DIGIT_BITNESS>>;
fn neg(self) -> Self::Output {
Self::Output {
numerator: -(&self.numerator),
denominator: self.denominator.clone(),
}
}
}
macro_rules! signed_integer_fraction_neg_impl {
($($integer:ty)*) => ($(
impl Neg for Fraction<$integer> {
type Output = Self;
fn neg(self) -> Self::Output {
Self::Output {
numerator: -self.numerator,
denominator: self.denominator,
}
}
}
)*)
}
signed_integer_fraction_neg_impl!(i8 i16 i32 i64 i128 isize);