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:
@@ -132,9 +132,9 @@ public inline class UByte internal constructor(private val data: Byte) : Compara
|
||||
public fun toLong(): Long = data.toLong() and 0xFF
|
||||
|
||||
public fun toUByte(): UByte = this
|
||||
public fun toUShort(): UShort = data.toUShort()
|
||||
public fun toUInt(): UInt = data.toUInt()
|
||||
public fun toULong(): ULong = data.toULong()
|
||||
public fun toUShort(): UShort = data.toUShort() and 0xFFu
|
||||
public fun toUInt(): UInt = data.toUInt() and 0xFFu
|
||||
public fun toULong(): ULong = data.toULong() and 0xFFu
|
||||
|
||||
public override fun toString(): String = toInt().toString()
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -146,13 +146,13 @@ public inline class ULong internal constructor(private val data: Long) : Compara
|
||||
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
public fun Byte.toULong(): ULong = ULong(this.toLong() and 0xFF)
|
||||
public fun Byte.toULong(): ULong = ULong(this.toLong())
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
public fun Short.toULong(): ULong = ULong(this.toLong() and 0xFFFF)
|
||||
public fun Short.toULong(): ULong = ULong(this.toLong())
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
public fun Int.toULong(): ULong = ULong(this.toLong() and 0xFFFF_FFFF)
|
||||
public fun Int.toULong(): ULong = ULong(this.toLong())
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
public fun Long.toULong(): ULong = ULong(this)
|
||||
|
||||
@@ -133,8 +133,8 @@ public inline class UShort internal constructor(private val data: Short) : Compa
|
||||
|
||||
public fun toUByte(): UByte = data.toUByte()
|
||||
public fun toUShort(): UShort = this
|
||||
public fun toUInt(): UInt = data.toUInt()
|
||||
public fun toULong(): ULong = data.toULong()
|
||||
public fun toUInt(): UInt = data.toUInt() and 0xFFFFu
|
||||
public fun toULong(): ULong = data.toULong() and 0xFFFFu
|
||||
|
||||
public override fun toString(): String = toInt().toString()
|
||||
|
||||
@@ -142,7 +142,7 @@ public inline class UShort internal constructor(private val data: Short) : Compa
|
||||
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
public fun Byte.toUShort(): UShort = UShort(this.toShort() and 0xFF)
|
||||
public fun Byte.toUShort(): UShort = UShort(this.toShort())
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
public fun Short.toUShort(): UShort = UShort(this)
|
||||
|
||||
Reference in New Issue
Block a user