math.big: add_digit_array() refactoring

This commit is contained in:
Mike 2025-08-19 22:42:10 +03:00
parent b99c3826ce
commit dbb5692907

View file

@ -34,11 +34,15 @@ fn add_digit_array(operand_a []u64, operand_b []u64, mut sum []u64) {
for index in 0 .. operand_b.len { for index in 0 .. operand_b.len {
sum[index] = operand_b[index] sum[index] = operand_b[index]
} }
shrink_tail_zeros(mut sum)
return
} }
if operand_b.len == 0 { if operand_b.len == 0 {
for index in 0 .. operand_a.len { for index in 0 .. operand_a.len {
sum[index] = operand_a[index] sum[index] = operand_a[index]
} }
shrink_tail_zeros(mut sum)
return
} }
// First pass intersects with both operands // First pass intersects with both operands
@ -62,11 +66,8 @@ fn add_digit_array(operand_a []u64, operand_b []u64, mut sum []u64) {
carry = u64(partial >> digit_bits) carry = u64(partial >> digit_bits)
} }
if carry == 0 { sum[larger_limit] = carry
sum.delete_last() shrink_tail_zeros(mut sum)
} else {
sum[larger_limit] = carry
}
} }
// Subtracts operand_b from operand_a and stores the difference in storage. // Subtracts operand_b from operand_a and stores the difference in storage.