https://kotlinlang.org logo
#javascript
Title
# javascript
j

juh juh

08/21/2022, 7:30 PM
Hello, is there some multiplatform library to consistently represent floating-point numbers across all platforms? I'm working on "replay" system for my game, and I really need numbers to be consistent across platforms, but with default Float it fails on JS, where I can't even do
Float.fromBits((-1e11f).toRawBits())
without getting distorted results
e

ephemient

08/22/2022, 12:51 AM
Kotlin/JS
Float
is a bit of a lie, it behaves like a
Double
(it's backed by JS
Number
either way)
Copy code
val f = -1e11f // clamped to Float range at compile time, is -99999997952f on all platforms
val g = -1e11f.toFloat() // does't actually clamp to Float range at runtime on JS
f != g
t

Tom Yuval

08/22/2022, 12:30 PM
Would
Double
work?
e

ephemient

08/22/2022, 2:54 PM
it should, there might be some inconsistencies around NaN but I expect other numbers will be fine
5 Views