I just discovered that the Byte and Short classes (and their unsigned counterparts) have no
shl
or
shr
infix functions. Is this intentional or not?
e
ephemient
10/11/2021, 12:24 PM
the operations don't exist in bytecode, only int and long shifts exist. Java automatically promotes byte/short values to int before all operations, and Kotlin does that for arithmetic like plus minus etc., but not shift. probably just not high priority, you can simply call
.toInt()
first
c
CLOVIS
10/20/2021, 6:51 AM
As a bonus, the reason it doesn't exist in Java, is because it doesn't exist in CPU architectures.
CLOVIS
10/20/2021, 6:53 AM
To my knowledge,
.toInt
and company are implemented as compiler intrinsics with a bit of magic, so they are more or less here so you know what you're doing, but have no performance impact at all
e
ephemient
10/20/2021, 11:20 AM
that's not 100% true on x86 due to compatibility going back to the 16-bit 8086/8088, but in practice none of those are faster