https://kotlinlang.org logo
#compiler
Title
# compiler
m

Michael Paus

07/16/2022, 8:10 AM
Why is the Java statement
Copy code
public static final long  SIGN_BIT_MASK  = 0x8000000000000000L;
a perfectly legal statement and its Kotlin counterpart
Copy code
const val SIGN_BIT_MASK: Long = 0x8000000000000000L
results in an error? (Value out of range.) Such inconsistencies make it very difficult to port any Math libraries from Java to Kotlin.
t

Tóth István Zoltán

07/16/2022, 8:22 AM
You might want to try ULong in the Kotlin code which is unsigned. I think it is a bit of inconsisteny on the Java side that long may be unsigned or signed while other types are signed by default.
🙏 1
m

Michael Paus

07/16/2022, 8:25 AM
Thanks, I’ll give ULong a try.
It worked although it is a bit complicated by the fact that
Double.toRawBits
and
Double.fromBits
only use Long but not
ULong
. But with the conversion
.toLong
it works.
4 Views