I wonder if anyone already found this bug, because...
# javascript
m
I wonder if anyone already found this bug, because I wouldn't find anything related to this in YouTrack or in this channel
Copy code
println("Test: ${"297153970613387264".toLong()}")
prints...
Test: 297153970613387260
Only happens with the IR compiler, not with the Legacy compiler, I actually thought this was a kotlinx.serialization bug until I tried debugging it further to find out that it is actually Kotlin that is having the issue! 😭 Tested in Kotlin 1.5.31, haven't tested in Kotlin 1.6.0 yet because Jetpack Compose Web doesn't support Kotlin 1.6.0... yet!
It also seems to affect every Long value, it doesn't affect only
toLong()
conversions...
Copy code
val value = 297153970613387264L
println("Real value: $value") // Real value: 297153970613387260
If the value is a
ULong
, then this doesn't happen
Copy code
val value = 297153970613387264u
println("Real value: $value") // Real value: 297153970613387264
Created a YouTrack issue for this 🙂 https://youtrack.jetbrains.com/issue/KT-49913
A workaround is converting the Long value to BigInteger (https://github.com/ionspin/kotlin-multiplatform-bignum) and then printing that as an String, that works fine
e
m
@ephemient well it looks like I haven't searched enough then 🙂, I wonder why I wasn't able to find this bug report before
(well looks like I can't close my own issue 😭)
a
There is the BigInt class in JS, have you searched if it exists in Kt/JS ?
e