mirror of
https://github.com/vlang/v.git
synced 2025-09-17 11:26:17 -04:00
math.big: fix 1/115792089237316195423570985008687907853269984665640564039457584007908834671663 leading to panic (fix #23771)
This commit is contained in:
parent
c5b26c441c
commit
6d017f3a31
@ -194,7 +194,7 @@ const sub_test_data = [
|
||||
SubTest{ 2, 100, -98},
|
||||
SubTest{ -100, -2, -98},
|
||||
SubTest{ 100, -2, 102},
|
||||
SubTest{ 2, -100, 102},
|
||||
SubTest{ 2, -100, 102},
|
||||
//
|
||||
SubTest{ 2, 3, -1 },
|
||||
SubTest{ 3, 2, 1 },
|
||||
@ -218,10 +218,10 @@ struct MulTest {
|
||||
// vfmt off
|
||||
const mul_test_data = [
|
||||
MulTest{ 2, 3, 6 },
|
||||
MulTest{ -2, 0, 0},
|
||||
MulTest{ 2, 0, 0},
|
||||
MulTest{ 0, -2, 0},
|
||||
MulTest{ 0, -2, 0},
|
||||
MulTest{ -2, 0, 0},
|
||||
MulTest{ 2, 0, 0},
|
||||
MulTest{ 0, -2, 0},
|
||||
MulTest{ 0, -2, 0},
|
||||
MulTest{ -869, 789, -685641 },
|
||||
MulTest{ 869, -789, -685641 },
|
||||
MulTest{ -869, -789, 685641 },
|
||||
@ -264,6 +264,7 @@ const div_mod_test_data = [
|
||||
'629648864382619361826',
|
||||
'2724578611525334851445652767465274410979805962941953382558409365935061481311529445551691298696266856092833571769883246719',
|
||||
},
|
||||
DivModTest{'1', '115792089237316195423570985008687907853269984665640564039457584007908834671663', '0', '1'},
|
||||
]
|
||||
// vfmt on
|
||||
|
||||
|
@ -144,7 +144,8 @@ pub fn integer_from_bytes(oinput []u8, config IntegerConfig) Integer {
|
||||
}
|
||||
input := oinput[first_non_zero_index..]
|
||||
// pad input
|
||||
mut padded_input := []u8{len: ((input.len + 3) & ~0x3) - input.len, cap: (input.len + 3) & ~0x3}
|
||||
mut padded_input := []u8{len: int_max(0, ((input.len + 3) & ~0x3) - input.len), cap: (
|
||||
input.len + 3) & ~0x3}
|
||||
padded_input << input
|
||||
mut digits := []u32{len: padded_input.len / 4}
|
||||
// combine every 4 bytes into a u32 and insert into n.digits
|
||||
@ -421,7 +422,7 @@ fn (dividend Integer) div_mod_internal(divisor Integer) (Integer, Integer) {
|
||||
}
|
||||
}
|
||||
// Division for positive integers
|
||||
mut q := []u32{cap: dividend.digits.len - divisor.digits.len + 1}
|
||||
mut q := []u32{cap: int_max(1, dividend.digits.len - divisor.digits.len + 1)}
|
||||
mut r := []u32{cap: dividend.digits.len}
|
||||
divide_digit_array(dividend.digits, divisor.digits, mut q, mut r)
|
||||
quotient := Integer{
|
||||
|
Loading…
x
Reference in New Issue
Block a user