Слияние кода завершено, страница обновится автоматически
Testing 3.8.13 Type BigInt
and observing an inconsistent behavior when a bigint is created from number. Here is correctly working case:
function main() {
let s: number = 0.000001 // 1e-6
console.log(s)
let b = new BigInt(s)
console.log(b)
}
0.000001
[TID 26d4fe] E/runtime: Unhandled exception: escompat.Error
[TID 26d4fe] E/runtime: Error: Can't convert number 0.000001 to BigInt because it's not an integer
[TID 26d4fe] E/runtime: at escompat.Error.<ctor> (<unknown>:1)
[TID 26d4fe] E/runtime: at escompat.BigInt.parseFromString (<unknown>:1002)
[TID 26d4fe] E/runtime: at escompat.BigInt.<ctor> (<unknown>:89)
[TID 26d4fe] E/runtime: at escompat.BigInt.<ctor> (<unknown>:82)
[TID 26d4fe] E/runtime: at ETSGLOBAL.main (/home/vkopyl/test5/test.ets:4)
[TID 26d4fe] E/runtime:
If we set s
to 1e-7, we see the following incorrect behavior, 1e-7 is accepted as 0:
function main() {
let s: number = 0.0000001 // 1e-7
console.log(s)
let b = new BigInt(s)
console.log(b)
}
1e-7
0
Вход Перед тем как оставить комментарий