prashan
09/10/2024, 3:31 PMUInt
in JS. When I expose this value to JavaScript, it seems to be interpreted as a signed int instead. is there a workaround?Artem Kobzar
09/10/2024, 4:09 PMprashan
09/10/2024, 4:10 PMval unsignedInt: UInt = 3_000_000_000u
this value is over the max for a signed 32bit int, but a perfectly valid unsigned 32bit intprashan
09/10/2024, 4:11 PMnumber
value of 3,000,000,000. the comparison fails because unsignedInt
is actually represented by a number
but number
is signed, so the value is -1294967296
CLOVIS
09/11/2024, 4:29 PMjw
09/11/2024, 4:30 PMCLOVIS
09/11/2024, 4:30 PMCLOVIS
09/11/2024, 4:31 PMjw
09/11/2024, 4:32 PMCLOVIS
09/11/2024, 4:35 PMInt
from a function, JS can pass an out-of-bounds number. So I guess you could implement the conversion in JS and it would be fine.prashan
09/11/2024, 5:02 PMprashan
09/11/2024, 7:23 PMkotlinUInt >>> 0
fixes this issue. source: https://stackoverflow.com/a/11385688
but kind of leads to more confusion on why this happens?
the fact that this actually works seems to imply that the last (LSB) 32 bits of the JS number are correct. but the according to JS docs, the sign bit should be the first bit (MSB)?