Wrong Float.MIN_VALUE and Float.MAX_VALUE

I working on my own multiplatform binary protocol and have some common tests. When the edge cases tests failed on the JS I investigated problem and found some interesting thing. In KotlinJS Float.MIN_VALUE == Double.MIN_VALUE == Number.MIN_VALUE and Float.MAX_VALUE == Double.MAX_VALUE == Number.MAX_VALUE. It means that Float.MAX_VALUE and Float.MIN_VALUE are 64 bit values that conflict with documentation.

This is bad when your working with ArrayBuffer and DataView. For example:

val buff = ArrayBuffer(4)
val dv = DataView(buff)

dv.setFloat32(0, Float.MAX_VALUE)

println(dv.getFloat32(0))

prints Infinity, that is wrong.

Max and min values are specified here https://github.com/JetBrains/kotlin/blob/master/libraries/stdlib/js/runtime/primitiveCompanionObjects.kt.

At the same time min and max values of Int, Short and Long are different between each other.

1 Like

I added isuue to the Kotlin youtrack https://youtrack.jetbrains.com/issue/KT-37175.