math.big: fix Karatsuba's add_in_place() function, add carry handler on exit (#24541)

This commit is contained in:
Mike 2025-05-21 13:54:21 +03:00 committed by GitHub
parent 717deacf52
commit c27bc602bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 0 deletions

File diff suppressed because one or more lines are too long

View File

@ -298,6 +298,9 @@ fn add_in_place(mut a []u32, b []u32) {
carry = u32(partial >> 32)
}
}
if carry > 0 {
a << u32(carry)
}
}
// a := a - b supposed a >= b

View File

@ -90,6 +90,15 @@ fn test_multiply_karatsuba_02() {
assert c == expected.digits
}
fn test_multiply_karatsuba_03() {
a := integer_from_string('9729117383001812976929423642') or { panic(err) }
b := integer_from_string('36889625830') or { panic(err) }
mut c := []u32{len: a.digits.len + b.digits.len + 1, init: 0}
karatsuba_multiply_digit_array(a.digits, b.digits, mut c)
expected := integer_from_string('358903499915085682930564860470935872860') or { panic(err) }
assert c == expected.digits
}
fn test_newton_divide_03() {
a := [u32(0), 4]
b := [u32(0), 1]