From cc626a6d85ae4543243e35cc863d5dbfda04d8ca Mon Sep 17 00:00:00 2001 From: Fabian Schmidt Date: Thu, 28 Nov 2024 11:02:14 +0100 Subject: [PATCH] Small changes --- src/fraction.rs | 4 +++- src/number.rs | 13 +++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/fraction.rs b/src/fraction.rs index b3ed0d8..fe64736 100644 --- a/src/fraction.rs +++ b/src/fraction.rs @@ -19,7 +19,7 @@ pub struct Rational { } impl Fraction { - pub fn new(numerator: Number, denominator: Number) -> Result> { + pub fn new(mut numerator: Number, mut denominator: Number) -> Result> { if denominator == 0.into() { return Err(Box::from("Division by 0")); } @@ -33,6 +33,8 @@ impl Fraction { Sign::Negatif => Sign::Positif, }, }; + numerator.sign = Sign::Positif; + denominator.sign = Sign::Positif; let mut f = Fraction { numerator, denominator, diff --git a/src/number.rs b/src/number.rs index 41a1df3..40ffe45 100644 --- a/src/number.rs +++ b/src/number.rs @@ -57,15 +57,12 @@ impl Number { pub fn fact(self) -> Self { let mut fact = Number::from(1); - if ((self.digits.len() * 8) as u32) < isize::BITS { - let max = isize::try_from(self).unwrap(); - for n in 1..=max { - fact = fact * n; - } - fact - } else { - panic!("starting number too big") + let mut n = Number::from(1); + while n <= self { + fact *= n.clone(); + n += 1.into(); } + fact } pub fn fib(n: u64) -> Self {