Small changes
This commit is contained in:
parent
19b2434789
commit
cc626a6d85
@ -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,
|
||||||
|
@ -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
|
fact
|
||||||
} else {
|
|
||||||
panic!("starting number too big")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fib(n: u64) -> Self {
|
pub fn fib(n: u64) -> Self {
|
||||||
|
Loading…
Reference in New Issue
Block a user