mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
math.big: fix integer_from_int(min_int) edge case, add tests (#25120)
This commit is contained in:
parent
a88df91938
commit
5a87e8cf20
2 changed files with 12 additions and 3 deletions
|
@ -52,6 +52,8 @@ const integer_from_int_test_data = [
|
|||
IntegerFromTest{ 127, '127' },
|
||||
IntegerFromTest{ 1024, '1024' },
|
||||
IntegerFromTest{ 2147483647, '0x7fffffff' },
|
||||
IntegerFromTest{ -2147483647, '-2147483647' },
|
||||
IntegerFromTest{ -2147483648, '-2147483648' },
|
||||
]
|
||||
|
||||
const integer_from_u64_test_data = [
|
||||
|
|
|
@ -51,10 +51,17 @@ pub fn integer_from_int(value int) Integer {
|
|||
if value == 0 {
|
||||
return zero_int
|
||||
}
|
||||
if value == min_int {
|
||||
return Integer{
|
||||
digits: [u64(0x80000000)]
|
||||
signum: -1
|
||||
}
|
||||
} else {
|
||||
return Integer{
|
||||
digits: [u64(iabs(value))]
|
||||
signum: int_signum(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// integer_from_u32 creates a new `big.Integer` from the given u32 value.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue