From 543b4ef459498fc96b8dd9a49cd653d4d7a3d6c7 Mon Sep 17 00:00:00 2001 From: EvilMuffinHa Date: Sat, 6 Aug 2022 00:16:39 -0400 Subject: [PATCH] karatsuba fixed --- src/ops.rs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/ops.rs b/src/ops.rs index d197bc5..bba35bd 100644 --- a/src/ops.rs +++ b/src/ops.rs @@ -344,25 +344,27 @@ fn mul_two_slices(slice1: &[u32], slice2: &[u32]) -> Vec { 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)