Wishlist for Kotlin 1.2 (conversion between int-fl...
# multiplatform
d
Wishlist for Kotlin 1.2 (conversion between int-float and long-double in all targets including JS). Here a JS implementation I just did using typed arrays: https://github.com/korlibs/korma/blob/992800b59a333fec7c8cb942fed17b9bfab85128/korma-js/src/main/kotlin/com/soywiz/korma/math/NativeMath.kt#L5-L29
Let us know if it’s not enough 😉
d
Looks good! After thinking a bit about it, I was going to suggest:
Copy code
fun Int.reinterpretAsFloat(): Float = java.lang.Float.intBitsToFloat(this)
fun Float.reinterpretAsInt(): Int = java.lang.Float.floatToIntBits(this)

fun Long.reinterpretAsDouble(): Double = java.lang.Double.longBitsToDouble(this)
fun Double.reinterpretAsLong(): Long = java.lang.Double.doubleToLongBits(this)
But for me thats enough. As long as they are available i can use them. Usually I use them in binary serialization.
b
Feel free to create an issue or to write your suggestions in #stdlib
👍 1
About serialization: take a look to kotlinx.serialization — https://github.com/Kotlin/kotlinx.serialization
👍 1
d
Great!