karatsuba fixed

This commit is contained in:
EvilMuffinHa 2022-08-06 00:16:39 -04:00
parent 4d6017b974
commit 543b4ef459

View File

@ -344,25 +344,27 @@ fn mul_two_slices(slice1: &[u32], slice2: &[u32]) -> Vec<u32> {
let (low1, high1) = slice1.split_at(m2 as usize);
let (low2, high2) = slice2.split_at(m2 as usize);
println!("z0: {:?}, {:?}", low1, low2);
println!("z1: {:?}, {:?}", &add_two_slices(low1, high1), &add_two_slices(low2, high2));
println!("z2: {:?}, {:?}", high1, high2);
let z0 = mul_two_slices(low1, low2);
let z1 = mul_two_slices(&add_two_slices(low1, high1), &add_two_slices(low2, high2));
let z2 = mul_two_slices(high1, high2);
let mut op0 = z0.clone();
let mut op0 = z2.clone();
op0.reverse();
op0.resize(op0.len() + (m2 as usize * 2), 0);
op0.reverse();
for _ in 0..(m2 * 2) {
op0.insert(0, 0);
}
let mut op1 = sub_two_slices(&sub_two_slices(&z1, &z2), &z0);
for _ in 0..m2 {
op1.insert(0, 0);
}
op1.reverse();
op1.resize(op1.len() + (m2 as usize), 0);
op1.reverse();
add_two_slices(&add_two_slices(&op0, &op1), &z0)