Small changes
This commit is contained in:
parent
19b2434789
commit
cc626a6d85
@ -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,
|
||||
|
@ -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;
|
||||
let mut n = Number::from(1);
|
||||
while n <= self {
|
||||
fact *= n.clone();
|
||||
n += 1.into();
|
||||
}
|
||||
fact
|
||||
} else {
|
||||
panic!("starting number too big")
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fib(n: u64) -> Self {
|
||||
|
Loading…
Reference in New Issue
Block a user