Change signed to unsigned widening conversions to sign-extending

e.g. `Byte.toUInt()` now returns `UInt.MAX_VALUE` for Byte value of -1 instead of 0xFFu.

#KT-26594 Fixed
This commit is contained in:
Ilya Gorbunov
2018-09-05 06:26:12 +03:00
parent 4344005fb5
commit 82d35cfa26
5 changed files with 17 additions and 14 deletions
+3 -3
View File
@@ -138,7 +138,7 @@ public inline class UInt internal constructor(private val data: Int) : Comparabl
public fun toUByte(): UByte = data.toUByte()
public fun toUShort(): UShort = data.toUShort()
public fun toUInt(): UInt = this
public fun toULong(): ULong = data.toULong()
public fun toULong(): ULong = data.toULong() and 0xFFFF_FFFFu
public override fun toString(): String = toLong().toString()
@@ -146,10 +146,10 @@ public inline class UInt internal constructor(private val data: Int) : Comparabl
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun Byte.toUInt(): UInt = UInt(this.toInt() and 0xFF)
public fun Byte.toUInt(): UInt = UInt(this.toInt())
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun Short.toUInt(): UInt = UInt(this.toInt() and 0xFFFF)
public fun Short.toUInt(): UInt = UInt(this.toInt())
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun Int.toUInt(): UInt = UInt(this)