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 {
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() {
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,

View File

@ -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 {