Make most of unsigned operations inline only

This commit is contained in:
Ilya Gorbunov
2018-09-17 20:24:30 +03:00
parent d793221a7b
commit 9e0708e85a
7 changed files with 387 additions and 373 deletions
+85 -43
View File
@@ -12,7 +12,7 @@ import kotlin.experimental.*
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public inline class UByte internal constructor(private val data: Byte) : Comparable<UByte> {
public inline class UByte @PublishedApi internal constructor(@PublishedApi internal val data: Byte) : Comparable<UByte> {
companion object {
/**
@@ -48,93 +48,131 @@ public inline class UByte internal constructor(private val data: Byte) : Compara
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public operator fun compareTo(other: UShort): Int = this.toUInt().compareTo(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun compareTo(other: UShort): Int = this.toUInt().compareTo(other.toUInt())
/**
* Compares this value with the specified value for order.
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public operator fun compareTo(other: UInt): Int = this.toUInt().compareTo(other)
@kotlin.internal.InlineOnly
public inline operator fun compareTo(other: UInt): Int = this.toUInt().compareTo(other)
/**
* Compares this value with the specified value for order.
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public operator fun compareTo(other: ULong): Int = this.toULong().compareTo(other)
@kotlin.internal.InlineOnly
public inline operator fun compareTo(other: ULong): Int = this.toULong().compareTo(other)
/** Adds the other value to this value. */
public operator fun plus(other: UByte): UInt = this.toUInt().plus(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun plus(other: UByte): UInt = this.toUInt().plus(other.toUInt())
/** Adds the other value to this value. */
public operator fun plus(other: UShort): UInt = this.toUInt().plus(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun plus(other: UShort): UInt = this.toUInt().plus(other.toUInt())
/** Adds the other value to this value. */
public operator fun plus(other: UInt): UInt = this.toUInt().plus(other)
@kotlin.internal.InlineOnly
public inline operator fun plus(other: UInt): UInt = this.toUInt().plus(other)
/** Adds the other value to this value. */
public operator fun plus(other: ULong): ULong = this.toULong().plus(other)
@kotlin.internal.InlineOnly
public inline operator fun plus(other: ULong): ULong = this.toULong().plus(other)
/** Subtracts the other value from this value. */
public operator fun minus(other: UByte): UInt = this.toUInt().minus(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun minus(other: UByte): UInt = this.toUInt().minus(other.toUInt())
/** Subtracts the other value from this value. */
public operator fun minus(other: UShort): UInt = this.toUInt().minus(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun minus(other: UShort): UInt = this.toUInt().minus(other.toUInt())
/** Subtracts the other value from this value. */
public operator fun minus(other: UInt): UInt = this.toUInt().minus(other)
@kotlin.internal.InlineOnly
public inline operator fun minus(other: UInt): UInt = this.toUInt().minus(other)
/** Subtracts the other value from this value. */
public operator fun minus(other: ULong): ULong = this.toULong().minus(other)
@kotlin.internal.InlineOnly
public inline operator fun minus(other: ULong): ULong = this.toULong().minus(other)
/** Multiplies this value by the other value. */
public operator fun times(other: UByte): UInt = this.toUInt().times(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun times(other: UByte): UInt = this.toUInt().times(other.toUInt())
/** Multiplies this value by the other value. */
public operator fun times(other: UShort): UInt = this.toUInt().times(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun times(other: UShort): UInt = this.toUInt().times(other.toUInt())
/** Multiplies this value by the other value. */
public operator fun times(other: UInt): UInt = this.toUInt().times(other)
@kotlin.internal.InlineOnly
public inline operator fun times(other: UInt): UInt = this.toUInt().times(other)
/** Multiplies this value by the other value. */
public operator fun times(other: ULong): ULong = this.toULong().times(other)
@kotlin.internal.InlineOnly
public inline operator fun times(other: ULong): ULong = this.toULong().times(other)
/** Divides this value by the other value. */
public operator fun div(other: UByte): UInt = this.toUInt().div(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun div(other: UByte): UInt = this.toUInt().div(other.toUInt())
/** Divides this value by the other value. */
public operator fun div(other: UShort): UInt = this.toUInt().div(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun div(other: UShort): UInt = this.toUInt().div(other.toUInt())
/** Divides this value by the other value. */
public operator fun div(other: UInt): UInt = this.toUInt().div(other)
@kotlin.internal.InlineOnly
public inline operator fun div(other: UInt): UInt = this.toUInt().div(other)
/** Divides this value by the other value. */
public operator fun div(other: ULong): ULong = this.toULong().div(other)
@kotlin.internal.InlineOnly
public inline operator fun div(other: ULong): ULong = this.toULong().div(other)
/** Calculates the remainder of dividing this value by the other value. */
public operator fun rem(other: UByte): UInt = this.toUInt().rem(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun rem(other: UByte): UInt = this.toUInt().rem(other.toUInt())
/** Calculates the remainder of dividing this value by the other value. */
public operator fun rem(other: UShort): UInt = this.toUInt().rem(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun rem(other: UShort): UInt = this.toUInt().rem(other.toUInt())
/** Calculates the remainder of dividing this value by the other value. */
public operator fun rem(other: UInt): UInt = this.toUInt().rem(other)
@kotlin.internal.InlineOnly
public inline operator fun rem(other: UInt): UInt = this.toUInt().rem(other)
/** Calculates the remainder of dividing this value by the other value. */
public operator fun rem(other: ULong): ULong = this.toULong().rem(other)
@kotlin.internal.InlineOnly
public inline operator fun rem(other: ULong): ULong = this.toULong().rem(other)
/** Increments this value. */
public operator fun inc(): UByte = UByte(data.inc())
@kotlin.internal.InlineOnly
public inline operator fun inc(): UByte = UByte(data.inc())
/** Decrements this value. */
public operator fun dec(): UByte = UByte(data.dec())
@kotlin.internal.InlineOnly
public inline operator fun dec(): UByte = UByte(data.dec())
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: UByte): UIntRange = UIntRange(this.toUInt(), other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun rangeTo(other: UByte): UIntRange = UIntRange(this.toUInt(), other.toUInt())
/** Performs a bitwise AND operation between the two values. */
public infix fun and(other: UByte): UByte = UByte(this.data and other.data)
@kotlin.internal.InlineOnly
public inline infix fun and(other: UByte): UByte = UByte(this.data and other.data)
/** Performs a bitwise OR operation between the two values. */
public infix fun or(other: UByte): UByte = UByte(this.data or other.data)
@kotlin.internal.InlineOnly
public inline infix fun or(other: UByte): UByte = UByte(this.data or other.data)
/** Performs a bitwise XOR operation between the two values. */
public infix fun xor(other: UByte): UByte = UByte(this.data xor other.data)
@kotlin.internal.InlineOnly
public inline infix fun xor(other: UByte): UByte = UByte(this.data xor other.data)
/** Inverts the bits in this value. */
public fun inv(): UByte = UByte(data.inv())
@kotlin.internal.InlineOnly
public inline fun inv(): UByte = UByte(data.inv())
public fun toByte(): Byte = data
public fun toShort(): Short = data.toShort() and 0xFF
public fun toInt(): Int = data.toInt() and 0xFF
public fun toLong(): Long = data.toLong() and 0xFF
@kotlin.internal.InlineOnly
public inline fun toByte(): Byte = data
@kotlin.internal.InlineOnly
public inline fun toShort(): Short = data.toShort() and 0xFF
@kotlin.internal.InlineOnly
public inline fun toInt(): Int = data.toInt() and 0xFF
@kotlin.internal.InlineOnly
public inline fun toLong(): Long = data.toLong() and 0xFF
public fun toUByte(): UByte = this
public fun toUShort(): UShort = data.toUShort() and 0xFFu
public fun toUInt(): UInt = data.toUInt() and 0xFFu
public fun toULong(): ULong = data.toULong() and 0xFFu
@kotlin.internal.InlineOnly
public inline fun toUByte(): UByte = this
@kotlin.internal.InlineOnly
public inline fun toUShort(): UShort = UShort(data.toShort() and 0xFF)
@kotlin.internal.InlineOnly
public inline fun toUInt(): UInt = UInt(data.toInt() and 0xFF)
@kotlin.internal.InlineOnly
public inline fun toULong(): ULong = ULong(data.toLong() and 0xFF)
public override fun toString(): String = toInt().toString()
@@ -142,13 +180,17 @@ public inline class UByte internal constructor(private val data: Byte) : Compara
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun Byte.toUByte(): UByte = UByte(this)
@kotlin.internal.InlineOnly
public inline fun Byte.toUByte(): UByte = UByte(this)
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun Short.toUByte(): UByte = UByte(this.toByte())
@kotlin.internal.InlineOnly
public inline fun Short.toUByte(): UByte = UByte(this.toByte())
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun Int.toUByte(): UByte = UByte(this.toByte())
@kotlin.internal.InlineOnly
public inline fun Int.toUByte(): UByte = UByte(this.toByte())
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun Long.toUByte(): UByte = UByte(this.toByte())
@kotlin.internal.InlineOnly
public inline fun Long.toUByte(): UByte = UByte(this.toByte())
+89 -45
View File
@@ -12,7 +12,7 @@ import kotlin.experimental.*
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public inline class UInt internal constructor(private val data: Int) : Comparable<UInt> {
public inline class UInt @PublishedApi internal constructor(@PublishedApi internal val data: Int) : Comparable<UInt> {
companion object {
/**
@@ -41,14 +41,16 @@ public inline class UInt internal constructor(private val data: Int) : Comparabl
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public operator fun compareTo(other: UByte): Int = this.compareTo(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun compareTo(other: UByte): Int = this.compareTo(other.toUInt())
/**
* Compares this value with the specified value for order.
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public operator fun compareTo(other: UShort): Int = this.compareTo(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun compareTo(other: UShort): Int = this.compareTo(other.toUInt())
/**
* Compares this value with the specified value for order.
@@ -62,83 +64,121 @@ public inline class UInt internal constructor(private val data: Int) : Comparabl
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public operator fun compareTo(other: ULong): Int = this.toULong().compareTo(other)
@kotlin.internal.InlineOnly
public inline operator fun compareTo(other: ULong): Int = this.toULong().compareTo(other)
/** Adds the other value to this value. */
public operator fun plus(other: UByte): UInt = this.plus(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun plus(other: UByte): UInt = this.plus(other.toUInt())
/** Adds the other value to this value. */
public operator fun plus(other: UShort): UInt = this.plus(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun plus(other: UShort): UInt = this.plus(other.toUInt())
/** Adds the other value to this value. */
public operator fun plus(other: UInt): UInt = UInt(this.data.plus(other.data))
@kotlin.internal.InlineOnly
public inline operator fun plus(other: UInt): UInt = UInt(this.data.plus(other.data))
/** Adds the other value to this value. */
public operator fun plus(other: ULong): ULong = this.toULong().plus(other)
@kotlin.internal.InlineOnly
public inline operator fun plus(other: ULong): ULong = this.toULong().plus(other)
/** Subtracts the other value from this value. */
public operator fun minus(other: UByte): UInt = this.minus(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun minus(other: UByte): UInt = this.minus(other.toUInt())
/** Subtracts the other value from this value. */
public operator fun minus(other: UShort): UInt = this.minus(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun minus(other: UShort): UInt = this.minus(other.toUInt())
/** Subtracts the other value from this value. */
public operator fun minus(other: UInt): UInt = UInt(this.data.minus(other.data))
@kotlin.internal.InlineOnly
public inline operator fun minus(other: UInt): UInt = UInt(this.data.minus(other.data))
/** Subtracts the other value from this value. */
public operator fun minus(other: ULong): ULong = this.toULong().minus(other)
@kotlin.internal.InlineOnly
public inline operator fun minus(other: ULong): ULong = this.toULong().minus(other)
/** Multiplies this value by the other value. */
public operator fun times(other: UByte): UInt = this.times(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun times(other: UByte): UInt = this.times(other.toUInt())
/** Multiplies this value by the other value. */
public operator fun times(other: UShort): UInt = this.times(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun times(other: UShort): UInt = this.times(other.toUInt())
/** Multiplies this value by the other value. */
public operator fun times(other: UInt): UInt = UInt(this.data.times(other.data))
@kotlin.internal.InlineOnly
public inline operator fun times(other: UInt): UInt = UInt(this.data.times(other.data))
/** Multiplies this value by the other value. */
public operator fun times(other: ULong): ULong = this.toULong().times(other)
@kotlin.internal.InlineOnly
public inline operator fun times(other: ULong): ULong = this.toULong().times(other)
/** Divides this value by the other value. */
public operator fun div(other: UByte): UInt = this.div(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun div(other: UByte): UInt = this.div(other.toUInt())
/** Divides this value by the other value. */
public operator fun div(other: UShort): UInt = this.div(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun div(other: UShort): UInt = this.div(other.toUInt())
/** Divides this value by the other value. */
public operator fun div(other: UInt): UInt = uintDivide(this, other)
@kotlin.internal.InlineOnly
public inline operator fun div(other: UInt): UInt = uintDivide(this, other)
/** Divides this value by the other value. */
public operator fun div(other: ULong): ULong = this.toULong().div(other)
@kotlin.internal.InlineOnly
public inline operator fun div(other: ULong): ULong = this.toULong().div(other)
/** Calculates the remainder of dividing this value by the other value. */
public operator fun rem(other: UByte): UInt = this.rem(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun rem(other: UByte): UInt = this.rem(other.toUInt())
/** Calculates the remainder of dividing this value by the other value. */
public operator fun rem(other: UShort): UInt = this.rem(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun rem(other: UShort): UInt = this.rem(other.toUInt())
/** Calculates the remainder of dividing this value by the other value. */
public operator fun rem(other: UInt): UInt = uintRemainder(this, other)
@kotlin.internal.InlineOnly
public inline operator fun rem(other: UInt): UInt = uintRemainder(this, other)
/** Calculates the remainder of dividing this value by the other value. */
public operator fun rem(other: ULong): ULong = this.toULong().rem(other)
@kotlin.internal.InlineOnly
public inline operator fun rem(other: ULong): ULong = this.toULong().rem(other)
/** Increments this value. */
public operator fun inc(): UInt = UInt(data.inc())
@kotlin.internal.InlineOnly
public inline operator fun inc(): UInt = UInt(data.inc())
/** Decrements this value. */
public operator fun dec(): UInt = UInt(data.dec())
@kotlin.internal.InlineOnly
public inline operator fun dec(): UInt = UInt(data.dec())
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: UInt): UIntRange = UIntRange(this, other)
@kotlin.internal.InlineOnly
public inline operator fun rangeTo(other: UInt): UIntRange = UIntRange(this, other)
/** Shifts this value left by the [bitCount] number of bits. */
public infix fun shl(bitCount: Int): UInt = UInt(data shl bitCount)
@kotlin.internal.InlineOnly
public inline infix fun shl(bitCount: Int): UInt = UInt(data shl bitCount)
/** Shifts this value right by the [bitCount] number of bits, filling the leftmost bits with zeros. */
public infix fun shr(bitCount: Int): UInt = UInt(data ushr bitCount)
@kotlin.internal.InlineOnly
public inline infix fun shr(bitCount: Int): UInt = UInt(data ushr bitCount)
/** Performs a bitwise AND operation between the two values. */
public infix fun and(other: UInt): UInt = UInt(this.data and other.data)
@kotlin.internal.InlineOnly
public inline infix fun and(other: UInt): UInt = UInt(this.data and other.data)
/** Performs a bitwise OR operation between the two values. */
public infix fun or(other: UInt): UInt = UInt(this.data or other.data)
@kotlin.internal.InlineOnly
public inline infix fun or(other: UInt): UInt = UInt(this.data or other.data)
/** Performs a bitwise XOR operation between the two values. */
public infix fun xor(other: UInt): UInt = UInt(this.data xor other.data)
@kotlin.internal.InlineOnly
public inline infix fun xor(other: UInt): UInt = UInt(this.data xor other.data)
/** Inverts the bits in this value. */
public fun inv(): UInt = UInt(data.inv())
@kotlin.internal.InlineOnly
public inline fun inv(): UInt = UInt(data.inv())
public fun toByte(): Byte = data.toByte()
public fun toShort(): Short = data.toShort()
public fun toInt(): Int = data
public fun toLong(): Long = data.toLong() and 0xFFFF_FFFF
@kotlin.internal.InlineOnly
public inline fun toByte(): Byte = data.toByte()
@kotlin.internal.InlineOnly
public inline fun toShort(): Short = data.toShort()
@kotlin.internal.InlineOnly
public inline fun toInt(): Int = data
@kotlin.internal.InlineOnly
public inline fun toLong(): Long = data.toLong() and 0xFFFF_FFFF
public fun toUByte(): UByte = data.toUByte()
public fun toUShort(): UShort = data.toUShort()
public fun toUInt(): UInt = this
public fun toULong(): ULong = data.toULong() and 0xFFFF_FFFFu
@kotlin.internal.InlineOnly
public inline fun toUByte(): UByte = data.toUByte()
@kotlin.internal.InlineOnly
public inline fun toUShort(): UShort = data.toUShort()
@kotlin.internal.InlineOnly
public inline fun toUInt(): UInt = this
@kotlin.internal.InlineOnly
public inline fun toULong(): ULong = ULong(data.toLong() and 0xFFFF_FFFF)
public override fun toString(): String = toLong().toString()
@@ -146,13 +186,17 @@ public inline class UInt internal constructor(private val data: Int) : Comparabl
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun Byte.toUInt(): UInt = UInt(this.toInt())
@kotlin.internal.InlineOnly
public inline fun Byte.toUInt(): UInt = UInt(this.toInt())
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun Short.toUInt(): UInt = UInt(this.toInt())
@kotlin.internal.InlineOnly
public inline fun Short.toUInt(): UInt = UInt(this.toInt())
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun Int.toUInt(): UInt = UInt(this)
@kotlin.internal.InlineOnly
public inline fun Int.toUInt(): UInt = UInt(this)
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun Long.toUInt(): UInt = UInt(this.toInt())
@kotlin.internal.InlineOnly
public inline fun Long.toUInt(): UInt = UInt(this.toInt())
+89 -45
View File
@@ -12,7 +12,7 @@ import kotlin.experimental.*
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public inline class ULong internal constructor(private val data: Long) : Comparable<ULong> {
public inline class ULong @PublishedApi internal constructor(@PublishedApi internal val data: Long) : Comparable<ULong> {
companion object {
/**
@@ -41,21 +41,24 @@ public inline class ULong internal constructor(private val data: Long) : Compara
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public operator fun compareTo(other: UByte): Int = this.compareTo(other.toULong())
@kotlin.internal.InlineOnly
public inline operator fun compareTo(other: UByte): Int = this.compareTo(other.toULong())
/**
* Compares this value with the specified value for order.
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public operator fun compareTo(other: UShort): Int = this.compareTo(other.toULong())
@kotlin.internal.InlineOnly
public inline operator fun compareTo(other: UShort): Int = this.compareTo(other.toULong())
/**
* Compares this value with the specified value for order.
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public operator fun compareTo(other: UInt): Int = this.compareTo(other.toULong())
@kotlin.internal.InlineOnly
public inline operator fun compareTo(other: UInt): Int = this.compareTo(other.toULong())
/**
* Compares this value with the specified value for order.
@@ -65,80 +68,117 @@ public inline class ULong internal constructor(private val data: Long) : Compara
public override operator fun compareTo(other: ULong): Int = ulongCompare(this.data, other.data)
/** Adds the other value to this value. */
public operator fun plus(other: UByte): ULong = this.plus(other.toULong())
@kotlin.internal.InlineOnly
public inline operator fun plus(other: UByte): ULong = this.plus(other.toULong())
/** Adds the other value to this value. */
public operator fun plus(other: UShort): ULong = this.plus(other.toULong())
@kotlin.internal.InlineOnly
public inline operator fun plus(other: UShort): ULong = this.plus(other.toULong())
/** Adds the other value to this value. */
public operator fun plus(other: UInt): ULong = this.plus(other.toULong())
@kotlin.internal.InlineOnly
public inline operator fun plus(other: UInt): ULong = this.plus(other.toULong())
/** Adds the other value to this value. */
public operator fun plus(other: ULong): ULong = ULong(this.data.plus(other.data))
@kotlin.internal.InlineOnly
public inline operator fun plus(other: ULong): ULong = ULong(this.data.plus(other.data))
/** Subtracts the other value from this value. */
public operator fun minus(other: UByte): ULong = this.minus(other.toULong())
@kotlin.internal.InlineOnly
public inline operator fun minus(other: UByte): ULong = this.minus(other.toULong())
/** Subtracts the other value from this value. */
public operator fun minus(other: UShort): ULong = this.minus(other.toULong())
@kotlin.internal.InlineOnly
public inline operator fun minus(other: UShort): ULong = this.minus(other.toULong())
/** Subtracts the other value from this value. */
public operator fun minus(other: UInt): ULong = this.minus(other.toULong())
@kotlin.internal.InlineOnly
public inline operator fun minus(other: UInt): ULong = this.minus(other.toULong())
/** Subtracts the other value from this value. */
public operator fun minus(other: ULong): ULong = ULong(this.data.minus(other.data))
@kotlin.internal.InlineOnly
public inline operator fun minus(other: ULong): ULong = ULong(this.data.minus(other.data))
/** Multiplies this value by the other value. */
public operator fun times(other: UByte): ULong = this.times(other.toULong())
@kotlin.internal.InlineOnly
public inline operator fun times(other: UByte): ULong = this.times(other.toULong())
/** Multiplies this value by the other value. */
public operator fun times(other: UShort): ULong = this.times(other.toULong())
@kotlin.internal.InlineOnly
public inline operator fun times(other: UShort): ULong = this.times(other.toULong())
/** Multiplies this value by the other value. */
public operator fun times(other: UInt): ULong = this.times(other.toULong())
@kotlin.internal.InlineOnly
public inline operator fun times(other: UInt): ULong = this.times(other.toULong())
/** Multiplies this value by the other value. */
public operator fun times(other: ULong): ULong = ULong(this.data.times(other.data))
@kotlin.internal.InlineOnly
public inline operator fun times(other: ULong): ULong = ULong(this.data.times(other.data))
/** Divides this value by the other value. */
public operator fun div(other: UByte): ULong = this.div(other.toULong())
@kotlin.internal.InlineOnly
public inline operator fun div(other: UByte): ULong = this.div(other.toULong())
/** Divides this value by the other value. */
public operator fun div(other: UShort): ULong = this.div(other.toULong())
@kotlin.internal.InlineOnly
public inline operator fun div(other: UShort): ULong = this.div(other.toULong())
/** Divides this value by the other value. */
public operator fun div(other: UInt): ULong = this.div(other.toULong())
@kotlin.internal.InlineOnly
public inline operator fun div(other: UInt): ULong = this.div(other.toULong())
/** Divides this value by the other value. */
public operator fun div(other: ULong): ULong = ulongDivide(this, other)
@kotlin.internal.InlineOnly
public inline operator fun div(other: ULong): ULong = ulongDivide(this, other)
/** Calculates the remainder of dividing this value by the other value. */
public operator fun rem(other: UByte): ULong = this.rem(other.toULong())
@kotlin.internal.InlineOnly
public inline operator fun rem(other: UByte): ULong = this.rem(other.toULong())
/** Calculates the remainder of dividing this value by the other value. */
public operator fun rem(other: UShort): ULong = this.rem(other.toULong())
@kotlin.internal.InlineOnly
public inline operator fun rem(other: UShort): ULong = this.rem(other.toULong())
/** Calculates the remainder of dividing this value by the other value. */
public operator fun rem(other: UInt): ULong = this.rem(other.toULong())
@kotlin.internal.InlineOnly
public inline operator fun rem(other: UInt): ULong = this.rem(other.toULong())
/** Calculates the remainder of dividing this value by the other value. */
public operator fun rem(other: ULong): ULong = ulongRemainder(this, other)
@kotlin.internal.InlineOnly
public inline operator fun rem(other: ULong): ULong = ulongRemainder(this, other)
/** Increments this value. */
public operator fun inc(): ULong = ULong(data.inc())
@kotlin.internal.InlineOnly
public inline operator fun inc(): ULong = ULong(data.inc())
/** Decrements this value. */
public operator fun dec(): ULong = ULong(data.dec())
@kotlin.internal.InlineOnly
public inline operator fun dec(): ULong = ULong(data.dec())
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: ULong): ULongRange = ULongRange(this, other)
@kotlin.internal.InlineOnly
public inline operator fun rangeTo(other: ULong): ULongRange = ULongRange(this, other)
/** Shifts this value left by the [bitCount] number of bits. */
public infix fun shl(bitCount: Int): ULong = ULong(data shl bitCount)
@kotlin.internal.InlineOnly
public inline infix fun shl(bitCount: Int): ULong = ULong(data shl bitCount)
/** Shifts this value right by the [bitCount] number of bits, filling the leftmost bits with zeros. */
public infix fun shr(bitCount: Int): ULong = ULong(data ushr bitCount)
@kotlin.internal.InlineOnly
public inline infix fun shr(bitCount: Int): ULong = ULong(data ushr bitCount)
/** Performs a bitwise AND operation between the two values. */
public infix fun and(other: ULong): ULong = ULong(this.data and other.data)
@kotlin.internal.InlineOnly
public inline infix fun and(other: ULong): ULong = ULong(this.data and other.data)
/** Performs a bitwise OR operation between the two values. */
public infix fun or(other: ULong): ULong = ULong(this.data or other.data)
@kotlin.internal.InlineOnly
public inline infix fun or(other: ULong): ULong = ULong(this.data or other.data)
/** Performs a bitwise XOR operation between the two values. */
public infix fun xor(other: ULong): ULong = ULong(this.data xor other.data)
@kotlin.internal.InlineOnly
public inline infix fun xor(other: ULong): ULong = ULong(this.data xor other.data)
/** Inverts the bits in this value. */
public fun inv(): ULong = ULong(data.inv())
@kotlin.internal.InlineOnly
public inline fun inv(): ULong = ULong(data.inv())
public fun toByte(): Byte = data.toByte()
public fun toShort(): Short = data.toShort()
public fun toInt(): Int = data.toInt()
public fun toLong(): Long = data
@kotlin.internal.InlineOnly
public inline fun toByte(): Byte = data.toByte()
@kotlin.internal.InlineOnly
public inline fun toShort(): Short = data.toShort()
@kotlin.internal.InlineOnly
public inline fun toInt(): Int = data.toInt()
@kotlin.internal.InlineOnly
public inline fun toLong(): Long = data
public fun toUByte(): UByte = data.toUByte()
public fun toUShort(): UShort = data.toUShort()
public fun toUInt(): UInt = data.toUInt()
public fun toULong(): ULong = this
@kotlin.internal.InlineOnly
public inline fun toUByte(): UByte = data.toUByte()
@kotlin.internal.InlineOnly
public inline fun toUShort(): UShort = data.toUShort()
@kotlin.internal.InlineOnly
public inline fun toUInt(): UInt = data.toUInt()
@kotlin.internal.InlineOnly
public inline fun toULong(): ULong = this
public override fun toString(): String = ulongToString(data)
@@ -146,13 +186,17 @@ public inline class ULong internal constructor(private val data: Long) : Compara
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun Byte.toULong(): ULong = ULong(this.toLong())
@kotlin.internal.InlineOnly
public inline fun Byte.toULong(): ULong = ULong(this.toLong())
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun Short.toULong(): ULong = ULong(this.toLong())
@kotlin.internal.InlineOnly
public inline fun Short.toULong(): ULong = ULong(this.toLong())
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun Int.toULong(): ULong = ULong(this.toLong())
@kotlin.internal.InlineOnly
public inline fun Int.toULong(): ULong = ULong(this.toLong())
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun Long.toULong(): ULong = ULong(this)
@kotlin.internal.InlineOnly
public inline fun Long.toULong(): ULong = ULong(this)
+85 -43
View File
@@ -12,7 +12,7 @@ import kotlin.experimental.*
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public inline class UShort internal constructor(private val data: Short) : Comparable<UShort> {
public inline class UShort @PublishedApi internal constructor(@PublishedApi internal val data: Short) : Comparable<UShort> {
companion object {
/**
@@ -41,7 +41,8 @@ public inline class UShort internal constructor(private val data: Short) : Compa
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public operator fun compareTo(other: UByte): Int = this.toUInt().compareTo(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun compareTo(other: UByte): Int = this.toUInt().compareTo(other.toUInt())
/**
* Compares this value with the specified value for order.
@@ -55,86 +56,123 @@ public inline class UShort internal constructor(private val data: Short) : Compa
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public operator fun compareTo(other: UInt): Int = this.toUInt().compareTo(other)
@kotlin.internal.InlineOnly
public inline operator fun compareTo(other: UInt): Int = this.toUInt().compareTo(other)
/**
* Compares this value with the specified value for order.
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
public operator fun compareTo(other: ULong): Int = this.toULong().compareTo(other)
@kotlin.internal.InlineOnly
public inline operator fun compareTo(other: ULong): Int = this.toULong().compareTo(other)
/** Adds the other value to this value. */
public operator fun plus(other: UByte): UInt = this.toUInt().plus(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun plus(other: UByte): UInt = this.toUInt().plus(other.toUInt())
/** Adds the other value to this value. */
public operator fun plus(other: UShort): UInt = this.toUInt().plus(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun plus(other: UShort): UInt = this.toUInt().plus(other.toUInt())
/** Adds the other value to this value. */
public operator fun plus(other: UInt): UInt = this.toUInt().plus(other)
@kotlin.internal.InlineOnly
public inline operator fun plus(other: UInt): UInt = this.toUInt().plus(other)
/** Adds the other value to this value. */
public operator fun plus(other: ULong): ULong = this.toULong().plus(other)
@kotlin.internal.InlineOnly
public inline operator fun plus(other: ULong): ULong = this.toULong().plus(other)
/** Subtracts the other value from this value. */
public operator fun minus(other: UByte): UInt = this.toUInt().minus(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun minus(other: UByte): UInt = this.toUInt().minus(other.toUInt())
/** Subtracts the other value from this value. */
public operator fun minus(other: UShort): UInt = this.toUInt().minus(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun minus(other: UShort): UInt = this.toUInt().minus(other.toUInt())
/** Subtracts the other value from this value. */
public operator fun minus(other: UInt): UInt = this.toUInt().minus(other)
@kotlin.internal.InlineOnly
public inline operator fun minus(other: UInt): UInt = this.toUInt().minus(other)
/** Subtracts the other value from this value. */
public operator fun minus(other: ULong): ULong = this.toULong().minus(other)
@kotlin.internal.InlineOnly
public inline operator fun minus(other: ULong): ULong = this.toULong().minus(other)
/** Multiplies this value by the other value. */
public operator fun times(other: UByte): UInt = this.toUInt().times(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun times(other: UByte): UInt = this.toUInt().times(other.toUInt())
/** Multiplies this value by the other value. */
public operator fun times(other: UShort): UInt = this.toUInt().times(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun times(other: UShort): UInt = this.toUInt().times(other.toUInt())
/** Multiplies this value by the other value. */
public operator fun times(other: UInt): UInt = this.toUInt().times(other)
@kotlin.internal.InlineOnly
public inline operator fun times(other: UInt): UInt = this.toUInt().times(other)
/** Multiplies this value by the other value. */
public operator fun times(other: ULong): ULong = this.toULong().times(other)
@kotlin.internal.InlineOnly
public inline operator fun times(other: ULong): ULong = this.toULong().times(other)
/** Divides this value by the other value. */
public operator fun div(other: UByte): UInt = this.toUInt().div(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun div(other: UByte): UInt = this.toUInt().div(other.toUInt())
/** Divides this value by the other value. */
public operator fun div(other: UShort): UInt = this.toUInt().div(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun div(other: UShort): UInt = this.toUInt().div(other.toUInt())
/** Divides this value by the other value. */
public operator fun div(other: UInt): UInt = this.toUInt().div(other)
@kotlin.internal.InlineOnly
public inline operator fun div(other: UInt): UInt = this.toUInt().div(other)
/** Divides this value by the other value. */
public operator fun div(other: ULong): ULong = this.toULong().div(other)
@kotlin.internal.InlineOnly
public inline operator fun div(other: ULong): ULong = this.toULong().div(other)
/** Calculates the remainder of dividing this value by the other value. */
public operator fun rem(other: UByte): UInt = this.toUInt().rem(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun rem(other: UByte): UInt = this.toUInt().rem(other.toUInt())
/** Calculates the remainder of dividing this value by the other value. */
public operator fun rem(other: UShort): UInt = this.toUInt().rem(other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun rem(other: UShort): UInt = this.toUInt().rem(other.toUInt())
/** Calculates the remainder of dividing this value by the other value. */
public operator fun rem(other: UInt): UInt = this.toUInt().rem(other)
@kotlin.internal.InlineOnly
public inline operator fun rem(other: UInt): UInt = this.toUInt().rem(other)
/** Calculates the remainder of dividing this value by the other value. */
public operator fun rem(other: ULong): ULong = this.toULong().rem(other)
@kotlin.internal.InlineOnly
public inline operator fun rem(other: ULong): ULong = this.toULong().rem(other)
/** Increments this value. */
public operator fun inc(): UShort = UShort(data.inc())
@kotlin.internal.InlineOnly
public inline operator fun inc(): UShort = UShort(data.inc())
/** Decrements this value. */
public operator fun dec(): UShort = UShort(data.dec())
@kotlin.internal.InlineOnly
public inline operator fun dec(): UShort = UShort(data.dec())
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: UShort): UIntRange = UIntRange(this.toUInt(), other.toUInt())
@kotlin.internal.InlineOnly
public inline operator fun rangeTo(other: UShort): UIntRange = UIntRange(this.toUInt(), other.toUInt())
/** Performs a bitwise AND operation between the two values. */
public infix fun and(other: UShort): UShort = UShort(this.data and other.data)
@kotlin.internal.InlineOnly
public inline infix fun and(other: UShort): UShort = UShort(this.data and other.data)
/** Performs a bitwise OR operation between the two values. */
public infix fun or(other: UShort): UShort = UShort(this.data or other.data)
@kotlin.internal.InlineOnly
public inline infix fun or(other: UShort): UShort = UShort(this.data or other.data)
/** Performs a bitwise XOR operation between the two values. */
public infix fun xor(other: UShort): UShort = UShort(this.data xor other.data)
@kotlin.internal.InlineOnly
public inline infix fun xor(other: UShort): UShort = UShort(this.data xor other.data)
/** Inverts the bits in this value. */
public fun inv(): UShort = UShort(data.inv())
@kotlin.internal.InlineOnly
public inline fun inv(): UShort = UShort(data.inv())
public fun toByte(): Byte = data.toByte()
public fun toShort(): Short = data
public fun toInt(): Int = data.toInt() and 0xFFFF
public fun toLong(): Long = data.toLong() and 0xFFFF
@kotlin.internal.InlineOnly
public inline fun toByte(): Byte = data.toByte()
@kotlin.internal.InlineOnly
public inline fun toShort(): Short = data
@kotlin.internal.InlineOnly
public inline fun toInt(): Int = data.toInt() and 0xFFFF
@kotlin.internal.InlineOnly
public inline fun toLong(): Long = data.toLong() and 0xFFFF
public fun toUByte(): UByte = data.toUByte()
public fun toUShort(): UShort = this
public fun toUInt(): UInt = data.toUInt() and 0xFFFFu
public fun toULong(): ULong = data.toULong() and 0xFFFFu
@kotlin.internal.InlineOnly
public inline fun toUByte(): UByte = data.toUByte()
@kotlin.internal.InlineOnly
public inline fun toUShort(): UShort = this
@kotlin.internal.InlineOnly
public inline fun toUInt(): UInt = UInt(data.toInt() and 0xFFFF)
@kotlin.internal.InlineOnly
public inline fun toULong(): ULong = ULong(data.toLong() and 0xFFFF)
public override fun toString(): String = toInt().toString()
@@ -142,13 +180,17 @@ public inline class UShort internal constructor(private val data: Short) : Compa
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun Byte.toUShort(): UShort = UShort(this.toShort())
@kotlin.internal.InlineOnly
public inline fun Byte.toUShort(): UShort = UShort(this.toShort())
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun Short.toUShort(): UShort = UShort(this)
@kotlin.internal.InlineOnly
public inline fun Short.toUShort(): UShort = UShort(this)
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun Int.toUShort(): UShort = UShort(this.toShort())
@kotlin.internal.InlineOnly
public inline fun Int.toUShort(): UShort = UShort(this.toShort())
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public fun Long.toUShort(): UShort = UShort(this.toShort())
@kotlin.internal.InlineOnly
public inline fun Long.toUShort(): UShort = UShort(this.toShort())
@@ -2,19 +2,22 @@
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
@file:kotlin.jvm.JvmName("UnsignedKt")
@file:UseExperimental(ExperimentalUnsignedTypes::class)
package kotlin
internal fun uintCompare(v1: Int, v2: Int): Int = (v1 xor Int.MIN_VALUE).compareTo(v2 xor Int.MIN_VALUE)
internal fun ulongCompare(v1: Long, v2: Long): Int = (v1 xor Long.MIN_VALUE).compareTo(v2 xor Long.MIN_VALUE)
@PublishedApi
internal fun uintDivide(v1: UInt, v2: UInt): UInt = (v1.toLong() / v2.toLong()).toUInt()
@PublishedApi
internal fun uintRemainder(v1: UInt, v2: UInt): UInt = (v1.toLong() % v2.toLong()).toUInt()
// Division and remainder are based on Guava's UnsignedLongs implementation
// Copyright 2011 The Guava Authors
@PublishedApi
internal fun ulongDivide(v1: ULong, v2: ULong): ULong {
val dividend = v1.toLong()
val divisor = v2.toLong()
@@ -34,6 +37,7 @@ internal fun ulongDivide(v1: ULong, v2: ULong): ULong {
}
@PublishedApi
internal fun ulongRemainder(v1: ULong, v2: ULong): ULong {
val dividend = v1.toLong()
val divisor = v2.toLong()