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 {
|
if n2_len > n1_len {
|
||||||
return Ok((Number::from(0), n2));
|
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 dividend = n1.digits[..n2_len].to_vec();
|
||||||
let mut quotient = vec![];
|
let mut quotient = vec![];
|
||||||
let mut remainder = Number {
|
let mut remainder = Number {
|
||||||
@ -31,8 +35,13 @@ impl Number {
|
|||||||
quotient.push(factor);
|
quotient.push(factor);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
remainder = temp_remainder;
|
|
||||||
factor += 1;
|
factor += 1;
|
||||||
|
if temp_remainder == 0.into() {
|
||||||
|
remainder = temp_remainder;
|
||||||
|
quotient.push(factor);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
remainder = temp_remainder;
|
||||||
}
|
}
|
||||||
if n1_len == n2_len + iteration - 1 {
|
if n1_len == n2_len + iteration - 1 {
|
||||||
break;
|
break;
|
||||||
@ -40,21 +49,25 @@ impl Number {
|
|||||||
remainder.digits.push(n1.digits[n2_len + iteration - 1]);
|
remainder.digits.push(n1.digits[n2_len + iteration - 1]);
|
||||||
iteration += 1;
|
iteration += 1;
|
||||||
}
|
}
|
||||||
let mut res = Number {
|
println!("{quotient:?}");
|
||||||
digits: quotient,
|
for digit in quotient.clone() {
|
||||||
sign: Sign::Positif,
|
if digit != 0 || quotient.len() == 1 {
|
||||||
};
|
|
||||||
for digit in res.clone().digits {
|
|
||||||
if digit != 0 || res.digits.len() == 1 {
|
|
||||||
break;
|
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 {
|
if digit != 0 || remainder.digits.len() == 1 {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
remainder.digits.remove(0);
|
remainder.digits.pop();
|
||||||
}
|
}
|
||||||
Ok((res, remainder))
|
Ok((res, remainder))
|
||||||
//if n2 == 0.into() {
|
//if n2 == 0.into() {
|
||||||
|
Loading…
Reference in New Issue
Block a user