v
v copied to clipboard
math.big: Inaccurate conversion to int
Describe the bug
The big library does not handle the smallest value of an i32 correctly.
Expected Behavior
-2147483648
-2147483648
2147483647
2147483647
-1
-2147483648
2147483647
0
Current Behavior
-2147483648
-2147483648
2147483647
2147483647
-1
0
2147483647
0
Reproduction Steps
import math.big
fn main() {
println('-2147483649'.int())
println('-2147483648'.int())
println('2147483647'.int())
println('2147483648'.int())
println(big.integer_from_string('-2147483649')!.int())
println(big.integer_from_string('-2147483648')!.int()) // this is broken
println(big.integer_from_string('2147483647')!.int())
println(big.integer_from_string('2147483648')!.int())
}
Possible Solution
No response
Additional Information/Context
No response
V version
0.3.3 daa9034
Environment details (OS name and version, etc.)
V full version: V 0.3.3 7de3485.daa9034
OS: macos, macOS, 12.6, 21G115
Processor: 10 cpus, 64bit, little endian, Apple M1 Max
getwd: /Users/elliot
vexe: /Users/elliot/v/v
vexe mtime: 2023-03-14 00:22:49
vroot: OK, value: /Users/elliot/v
VMODULES: OK, value: /Users/elliot/.vmodules
VTMP: OK, value: /tmp/v_501
Git version: git version 2.37.0 (Apple Git-136)
Git vroot status: weekly.2023.10-50-gdaa90345
.git/config present: true
CC version: Apple clang version 14.0.0 (clang-1400.0.29.102)
thirdparty/tcc status: thirdparty-macos-arm64 a668e5a0
@hungrybluedev Have you any spare time to have a look at this bug?
I might try to look at this in the weekend if that is okay. Have some assignments now.