Some minimal progress on div
This commit is contained in:
parent
50b2aa8932
commit
cad2d2b910
@ -16,6 +16,10 @@ impl Number {
|
||||
if n2_len > n1_len {
|
||||
return Ok((Number::from(0), n2));
|
||||
}
|
||||
let sign = match (n1.sign, n2.sign) {
|
||||
(Sign::Positif, Sign::Positif) | (Sign::Negatif, Sign::Negatif) => Sign::Positif,
|
||||
(Sign::Positif, Sign::Negatif) | (Sign::Negatif, Sign::Positif) => Sign::Negatif,
|
||||
};
|
||||
let dividend = n1.digits[..n2_len].to_vec();
|
||||
let mut quotient = vec![];
|
||||
let mut remainder = Number {
|
||||
@ -31,8 +35,13 @@ impl Number {
|
||||
quotient.push(factor);
|
||||
break;
|
||||
}
|
||||
remainder = temp_remainder;
|
||||
factor += 1;
|
||||
if temp_remainder == 0.into() {
|
||||
remainder = temp_remainder;
|
||||
quotient.push(factor);
|
||||
break;
|
||||
}
|
||||
remainder = temp_remainder;
|
||||
}
|
||||
if n1_len == n2_len + iteration - 1 {
|
||||
break;
|
||||
@ -40,21 +49,25 @@ impl Number {
|
||||
remainder.digits.push(n1.digits[n2_len + iteration - 1]);
|
||||
iteration += 1;
|
||||
}
|
||||
let mut res = Number {
|
||||
digits: quotient,
|
||||
sign: Sign::Positif,
|
||||
};
|
||||
for digit in res.clone().digits {
|
||||
if digit != 0 || res.digits.len() == 1 {
|
||||
println!("{quotient:?}");
|
||||
for digit in quotient.clone() {
|
||||
if digit != 0 || quotient.len() == 1 {
|
||||
break;
|
||||
}
|
||||
res.digits.remove(0);
|
||||
quotient.remove(0);
|
||||
}
|
||||
for digit in remainder.clone().digits {
|
||||
quotient.reverse();
|
||||
let res = Number {
|
||||
digits: quotient,
|
||||
sign,
|
||||
};
|
||||
let mut rem_digits = remainder.clone().digits;
|
||||
rem_digits.reverse();
|
||||
for digit in rem_digits {
|
||||
if digit != 0 || remainder.digits.len() == 1 {
|
||||
break;
|
||||
}
|
||||
remainder.digits.remove(0);
|
||||
remainder.digits.pop();
|
||||
}
|
||||
Ok((res, remainder))
|
||||
//if n2 == 0.into() {
|
||||
|
Loading…
Reference in New Issue
Block a user