Small changes

This commit is contained in:
Fabian Schmidt 2024-11-28 11:02:14 +01:00
parent 19b2434789
commit cc626a6d85
2 changed files with 8 additions and 9 deletions

View File

@ -19,7 +19,7 @@ pub struct Rational {
} }
impl Fraction { impl Fraction {
pub fn new(numerator: Number, denominator: Number) -> Result<Self, Box<dyn Error>> { pub fn new(mut numerator: Number, mut denominator: Number) -> Result<Self, Box<dyn Error>> {
if denominator == 0.into() { if denominator == 0.into() {
return Err(Box::from("Division by 0")); return Err(Box::from("Division by 0"));
} }
@ -33,6 +33,8 @@ impl Fraction {
Sign::Negatif => Sign::Positif, Sign::Negatif => Sign::Positif,
}, },
}; };
numerator.sign = Sign::Positif;
denominator.sign = Sign::Positif;
let mut f = Fraction { let mut f = Fraction {
numerator, numerator,
denominator, denominator,

View File

@ -57,15 +57,12 @@ impl Number {
pub fn fact(self) -> Self { pub fn fact(self) -> Self {
let mut fact = Number::from(1); let mut fact = Number::from(1);
if ((self.digits.len() * 8) as u32) < isize::BITS { let mut n = Number::from(1);
let max = isize::try_from(self).unwrap(); while n <= self {
for n in 1..=max { fact *= n.clone();
fact = fact * n; n += 1.into();
}
fact
} else {
panic!("starting number too big")
} }
fact
} }
pub fn fib(n: u64) -> Self { pub fn fib(n: u64) -> Self {