Stabilize unsigned types KT-45653

Deprecate specialized unsigned iterators for removal.

Fix compiler tests:
- drop unsignedLiteralsOn1_2 because apiVersion 1.2 is no longer supported
- drop experimental unsigned literals diagnostic test
This commit is contained in:
Ilya Gorbunov
2021-03-19 20:38:02 +03:00
parent 768c165a72
commit 94240f7b21
63 changed files with 1305 additions and 1461 deletions
+10 -10
View File
@@ -10,8 +10,8 @@ package kotlin
import kotlin.experimental.*
import kotlin.jvm.*
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
@JvmInline
public value class UByte @PublishedApi internal constructor(@PublishedApi internal val data: Byte) : Comparable<UByte> {
@@ -342,8 +342,8 @@ public value class UByte @PublishedApi internal constructor(@PublishedApi intern
*
* The resulting `UByte` value has the same binary representation as this `Byte` value.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
@kotlin.internal.InlineOnly
public inline fun Byte.toUByte(): UByte = UByte(this)
/**
@@ -354,8 +354,8 @@ public inline fun Byte.toUByte(): UByte = UByte(this)
*
* The resulting `UByte` value is represented by the least significant 8 bits of this `Short` value.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
@kotlin.internal.InlineOnly
public inline fun Short.toUByte(): UByte = UByte(this.toByte())
/**
@@ -366,8 +366,8 @@ public inline fun Short.toUByte(): UByte = UByte(this.toByte())
*
* The resulting `UByte` value is represented by the least significant 8 bits of this `Int` value.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
@kotlin.internal.InlineOnly
public inline fun Int.toUByte(): UByte = UByte(this.toByte())
/**
@@ -378,7 +378,7 @@ public inline fun Int.toUByte(): UByte = UByte(this.toByte())
*
* The resulting `UByte` value is represented by the least significant 8 bits of this `Long` value.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
@kotlin.internal.InlineOnly
public inline fun Long.toUByte(): UByte = UByte(this.toByte())
@@ -41,8 +41,9 @@ internal constructor(@PublishedApi internal val storage: ByteArray) : Collection
public override val size: Int get() = storage.size
/** Creates an iterator over the elements of the array. */
public override operator fun iterator(): UByteIterator = Iterator(storage)
public override operator fun iterator(): kotlin.collections.Iterator<UByte> = Iterator(storage)
@Suppress("DEPRECATION_ERROR")
private class Iterator(private val array: ByteArray) : UByteIterator() {
private var index = 0
override fun hasNext() = index < array.size
+14 -14
View File
@@ -10,8 +10,8 @@ package kotlin
import kotlin.experimental.*
import kotlin.jvm.*
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
@JvmInline
public value class UInt @PublishedApi internal constructor(@PublishedApi internal val data: Int) : Comparable<UInt> {
@@ -365,8 +365,8 @@ public value class UInt @PublishedApi internal constructor(@PublishedApi interna
* The least significant 8 bits of the resulting `UInt` value are the same as the bits of this `Byte` value,
* whereas the most significant 24 bits are filled with the sign bit of this value.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
@kotlin.internal.InlineOnly
public inline fun Byte.toUInt(): UInt = UInt(this.toInt())
/**
@@ -377,8 +377,8 @@ public inline fun Byte.toUInt(): UInt = UInt(this.toInt())
* The least significant 16 bits of the resulting `UInt` value are the same as the bits of this `Short` value,
* whereas the most significant 16 bits are filled with the sign bit of this value.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
@kotlin.internal.InlineOnly
public inline fun Short.toUInt(): UInt = UInt(this.toInt())
/**
@@ -388,8 +388,8 @@ public inline fun Short.toUInt(): UInt = UInt(this.toInt())
*
* The resulting `UInt` value has the same binary representation as this `Int` value.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
@kotlin.internal.InlineOnly
public inline fun Int.toUInt(): UInt = UInt(this)
/**
@@ -400,8 +400,8 @@ public inline fun Int.toUInt(): UInt = UInt(this)
*
* The resulting `UInt` value is represented by the least significant 32 bits of this `Long` value.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
@kotlin.internal.InlineOnly
public inline fun Long.toUInt(): UInt = UInt(this.toInt())
@@ -411,8 +411,8 @@ public inline fun Long.toUInt(): UInt = UInt(this.toInt())
* The fractional part, if any, is rounded down towards zero.
* Returns zero if this `Float` value is negative or `NaN`, [UInt.MAX_VALUE] if it's bigger than `UInt.MAX_VALUE`.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
@kotlin.internal.InlineOnly
public inline fun Float.toUInt(): UInt = doubleToUInt(this.toDouble())
/**
@@ -421,7 +421,7 @@ public inline fun Float.toUInt(): UInt = doubleToUInt(this.toDouble())
* The fractional part, if any, is rounded down towards zero.
* Returns zero if this `Double` value is negative or `NaN`, [UInt.MAX_VALUE] if it's bigger than `UInt.MAX_VALUE`.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
@kotlin.internal.InlineOnly
public inline fun Double.toUInt(): UInt = doubleToUInt(this)
@@ -41,8 +41,9 @@ internal constructor(@PublishedApi internal val storage: IntArray) : Collection<
public override val size: Int get() = storage.size
/** Creates an iterator over the elements of the array. */
public override operator fun iterator(): UIntIterator = Iterator(storage)
public override operator fun iterator(): kotlin.collections.Iterator<UInt> = Iterator(storage)
@Suppress("DEPRECATION_ERROR")
private class Iterator(private val array: IntArray) : UIntIterator() {
private var index = 0
override fun hasNext() = index < array.size
@@ -14,8 +14,8 @@ import kotlin.internal.*
/**
* A range of values of type `UInt`.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
public class UIntRange(start: UInt, endInclusive: UInt) : UIntProgression(start, endInclusive, 1), ClosedRange<UInt> {
override val start: UInt get() = first
override val endInclusive: UInt get() = last
@@ -47,8 +47,8 @@ public class UIntRange(start: UInt, endInclusive: UInt) : UIntProgression(start,
/**
* A progression of values of type `UInt`.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
public open class UIntProgression
internal constructor(
start: UInt,
@@ -75,7 +75,7 @@ internal constructor(
*/
public val step: Int = step
override fun iterator(): UIntIterator = UIntProgressionIterator(first, last, step)
final override fun iterator(): Iterator<UInt> = UIntProgressionIterator(first, last, step)
/**
* Checks if the progression is empty.
@@ -113,7 +113,7 @@ internal constructor(
* @property step the number by which the value is incremented on each step.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@Suppress("DEPRECATION_ERROR")
private class UIntProgressionIterator(first: UInt, last: UInt, step: Int) : UIntIterator() {
private val finalElement = last
private var hasNext: Boolean = if (step > 0) first <= last else first >= last
@@ -8,40 +8,40 @@
package kotlin.collections
/** An iterator over a sequence of values of type `UByte`. */
@Deprecated("This class is not going to be stabilized and is to be removed soon.", level = DeprecationLevel.ERROR)
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public abstract class UByteIterator : Iterator<UByte> {
override final fun next() = nextUByte()
final override fun next() = nextUByte()
/** Returns the next value in the sequence without boxing. */
public abstract fun nextUByte(): UByte
}
/** An iterator over a sequence of values of type `UShort`. */
@Deprecated("This class is not going to be stabilized and is to be removed soon.", level = DeprecationLevel.ERROR)
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public abstract class UShortIterator : Iterator<UShort> {
override final fun next() = nextUShort()
final override fun next() = nextUShort()
/** Returns the next value in the sequence without boxing. */
public abstract fun nextUShort(): UShort
}
/** An iterator over a sequence of values of type `UInt`. */
@Deprecated("This class is not going to be stabilized and is to be removed soon.", level = DeprecationLevel.ERROR)
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public abstract class UIntIterator : Iterator<UInt> {
override final fun next() = nextUInt()
final override fun next() = nextUInt()
/** Returns the next value in the sequence without boxing. */
public abstract fun nextUInt(): UInt
}
/** An iterator over a sequence of values of type `ULong`. */
@Deprecated("This class is not going to be stabilized and is to be removed soon.", level = DeprecationLevel.ERROR)
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public abstract class ULongIterator : Iterator<ULong> {
override final fun next() = nextULong()
final override fun next() = nextULong()
/** Returns the next value in the sequence without boxing. */
public abstract fun nextULong(): ULong
+14 -14
View File
@@ -10,8 +10,8 @@ package kotlin
import kotlin.experimental.*
import kotlin.jvm.*
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
@JvmInline
public value class ULong @PublishedApi internal constructor(@PublishedApi internal val data: Long) : Comparable<ULong> {
@@ -368,8 +368,8 @@ public value class ULong @PublishedApi internal constructor(@PublishedApi intern
* The least significant 8 bits of the resulting `ULong` value are the same as the bits of this `Byte` value,
* whereas the most significant 56 bits are filled with the sign bit of this value.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
@kotlin.internal.InlineOnly
public inline fun Byte.toULong(): ULong = ULong(this.toLong())
/**
@@ -380,8 +380,8 @@ public inline fun Byte.toULong(): ULong = ULong(this.toLong())
* The least significant 16 bits of the resulting `ULong` value are the same as the bits of this `Short` value,
* whereas the most significant 48 bits are filled with the sign bit of this value.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
@kotlin.internal.InlineOnly
public inline fun Short.toULong(): ULong = ULong(this.toLong())
/**
@@ -392,8 +392,8 @@ public inline fun Short.toULong(): ULong = ULong(this.toLong())
* The least significant 32 bits of the resulting `ULong` value are the same as the bits of this `Int` value,
* whereas the most significant 32 bits are filled with the sign bit of this value.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
@kotlin.internal.InlineOnly
public inline fun Int.toULong(): ULong = ULong(this.toLong())
/**
@@ -403,8 +403,8 @@ public inline fun Int.toULong(): ULong = ULong(this.toLong())
*
* The resulting `ULong` value has the same binary representation as this `Long` value.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
@kotlin.internal.InlineOnly
public inline fun Long.toULong(): ULong = ULong(this)
@@ -414,8 +414,8 @@ public inline fun Long.toULong(): ULong = ULong(this)
* The fractional part, if any, is rounded down towards zero.
* Returns zero if this `Float` value is negative or `NaN`, [ULong.MAX_VALUE] if it's bigger than `ULong.MAX_VALUE`.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
@kotlin.internal.InlineOnly
public inline fun Float.toULong(): ULong = doubleToULong(this.toDouble())
/**
@@ -424,7 +424,7 @@ public inline fun Float.toULong(): ULong = doubleToULong(this.toDouble())
* The fractional part, if any, is rounded down towards zero.
* Returns zero if this `Double` value is negative or `NaN`, [ULong.MAX_VALUE] if it's bigger than `ULong.MAX_VALUE`.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
@kotlin.internal.InlineOnly
public inline fun Double.toULong(): ULong = doubleToULong(this)
@@ -41,8 +41,9 @@ internal constructor(@PublishedApi internal val storage: LongArray) : Collection
public override val size: Int get() = storage.size
/** Creates an iterator over the elements of the array. */
public override operator fun iterator(): ULongIterator = Iterator(storage)
public override operator fun iterator(): kotlin.collections.Iterator<ULong> = Iterator(storage)
@Suppress("DEPRECATION_ERROR")
private class Iterator(private val array: LongArray) : ULongIterator() {
private var index = 0
override fun hasNext() = index < array.size
@@ -14,8 +14,8 @@ import kotlin.internal.*
/**
* A range of values of type `ULong`.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
public class ULongRange(start: ULong, endInclusive: ULong) : ULongProgression(start, endInclusive, 1), ClosedRange<ULong> {
override val start: ULong get() = first
override val endInclusive: ULong get() = last
@@ -47,8 +47,8 @@ public class ULongRange(start: ULong, endInclusive: ULong) : ULongProgression(st
/**
* A progression of values of type `ULong`.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
public open class ULongProgression
internal constructor(
start: ULong,
@@ -75,7 +75,7 @@ internal constructor(
*/
public val step: Long = step
override fun iterator(): ULongIterator = ULongProgressionIterator(first, last, step)
final override fun iterator(): Iterator<ULong> = ULongProgressionIterator(first, last, step)
/**
* Checks if the progression is empty.
@@ -113,7 +113,7 @@ internal constructor(
* @property step the number by which the value is incremented on each step.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@Suppress("DEPRECATION_ERROR")
private class ULongProgressionIterator(first: ULong, last: ULong, step: Long) : ULongIterator() {
private val finalElement = last
private var hasNext: Boolean = if (step > 0) first <= last else first >= last
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -8,8 +8,8 @@ package kotlin.math
/**
* Returns the smaller of two values.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
@kotlin.internal.InlineOnly
public inline fun min(a: UInt, b: UInt): UInt {
return minOf(a, b)
@@ -18,8 +18,8 @@ public inline fun min(a: UInt, b: UInt): UInt {
/**
* Returns the smaller of two values.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
@kotlin.internal.InlineOnly
public inline fun min(a: ULong, b: ULong): ULong {
return minOf(a, b)
@@ -28,8 +28,8 @@ public inline fun min(a: ULong, b: ULong): ULong {
/**
* Returns the greater of two values.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
@kotlin.internal.InlineOnly
public inline fun max(a: UInt, b: UInt): UInt {
return maxOf(a, b)
@@ -38,8 +38,8 @@ public inline fun max(a: UInt, b: UInt): UInt {
/**
* Returns the greater of two values.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
@kotlin.internal.InlineOnly
public inline fun max(a: ULong, b: ULong): ULong {
return maxOf(a, b)
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -9,27 +9,24 @@ package kotlin
/**
* Counts the number of set bits in the binary representation of this [UInt] number.
*/
@SinceKotlin("1.4")
@WasExperimental(ExperimentalStdlibApi::class)
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class, ExperimentalStdlibApi::class)
@kotlin.internal.InlineOnly
public inline fun UInt.countOneBits(): Int = toInt().countOneBits()
/**
* Counts the number of consecutive most significant bits that are zero in the binary representation of this [UInt] number.
*/
@SinceKotlin("1.4")
@WasExperimental(ExperimentalStdlibApi::class)
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class, ExperimentalStdlibApi::class)
@kotlin.internal.InlineOnly
public inline fun UInt.countLeadingZeroBits(): Int = toInt().countLeadingZeroBits()
/**
* Counts the number of consecutive least significant bits that are zero in the binary representation of this [UInt] number.
*/
@SinceKotlin("1.4")
@WasExperimental(ExperimentalStdlibApi::class)
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class, ExperimentalStdlibApi::class)
@kotlin.internal.InlineOnly
public inline fun UInt.countTrailingZeroBits(): Int = toInt().countTrailingZeroBits()
@@ -37,9 +34,8 @@ public inline fun UInt.countTrailingZeroBits(): Int = toInt().countTrailingZeroB
* Returns a number having a single bit set in the position of the most significant set bit of this [UInt] number,
* or zero, if this number is zero.
*/
@SinceKotlin("1.4")
@WasExperimental(ExperimentalStdlibApi::class)
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class, ExperimentalStdlibApi::class)
@kotlin.internal.InlineOnly
public inline fun UInt.takeHighestOneBit(): UInt = toInt().takeHighestOneBit().toUInt()
@@ -47,9 +43,8 @@ public inline fun UInt.takeHighestOneBit(): UInt = toInt().takeHighestOneBit().t
* Returns a number having a single bit set in the position of the least significant set bit of this [UInt] number,
* or zero, if this number is zero.
*/
@SinceKotlin("1.4")
@WasExperimental(ExperimentalStdlibApi::class)
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class, ExperimentalStdlibApi::class)
@kotlin.internal.InlineOnly
public inline fun UInt.takeLowestOneBit(): UInt = toInt().takeLowestOneBit().toUInt()
@@ -65,7 +60,7 @@ public inline fun UInt.takeLowestOneBit(): UInt = toInt().takeLowestOneBit().toU
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
@ExperimentalUnsignedTypes
@WasExperimental(ExperimentalUnsignedTypes::class)
@kotlin.internal.InlineOnly
public inline fun UInt.rotateLeft(bitCount: Int): UInt = toInt().rotateLeft(bitCount).toUInt()
@@ -82,7 +77,7 @@ public inline fun UInt.rotateLeft(bitCount: Int): UInt = toInt().rotateLeft(bitC
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
@ExperimentalUnsignedTypes
@WasExperimental(ExperimentalUnsignedTypes::class)
@kotlin.internal.InlineOnly
public inline fun UInt.rotateRight(bitCount: Int): UInt = toInt().rotateRight(bitCount).toUInt()
@@ -90,27 +85,24 @@ public inline fun UInt.rotateRight(bitCount: Int): UInt = toInt().rotateRight(bi
/**
* Counts the number of set bits in the binary representation of this [ULong] number.
*/
@SinceKotlin("1.4")
@WasExperimental(ExperimentalStdlibApi::class)
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class, ExperimentalStdlibApi::class)
@kotlin.internal.InlineOnly
public inline fun ULong.countOneBits(): Int = toLong().countOneBits()
/**
* Counts the number of consecutive most significant bits that are zero in the binary representation of this [ULong] number.
*/
@SinceKotlin("1.4")
@WasExperimental(ExperimentalStdlibApi::class)
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class, ExperimentalStdlibApi::class)
@kotlin.internal.InlineOnly
public inline fun ULong.countLeadingZeroBits(): Int = toLong().countLeadingZeroBits()
/**
* Counts the number of consecutive least significant bits that are zero in the binary representation of this [ULong] number.
*/
@SinceKotlin("1.4")
@WasExperimental(ExperimentalStdlibApi::class)
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class, ExperimentalStdlibApi::class)
@kotlin.internal.InlineOnly
public inline fun ULong.countTrailingZeroBits(): Int = toLong().countTrailingZeroBits()
@@ -118,9 +110,8 @@ public inline fun ULong.countTrailingZeroBits(): Int = toLong().countTrailingZer
* Returns a number having a single bit set in the position of the most significant set bit of this [ULong] number,
* or zero, if this number is zero.
*/
@SinceKotlin("1.4")
@WasExperimental(ExperimentalStdlibApi::class)
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class, ExperimentalStdlibApi::class)
@kotlin.internal.InlineOnly
public inline fun ULong.takeHighestOneBit(): ULong = toLong().takeHighestOneBit().toULong()
@@ -128,9 +119,8 @@ public inline fun ULong.takeHighestOneBit(): ULong = toLong().takeHighestOneBit(
* Returns a number having a single bit set in the position of the least significant set bit of this [ULong] number,
* or zero, if this number is zero.
*/
@SinceKotlin("1.4")
@WasExperimental(ExperimentalStdlibApi::class)
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class, ExperimentalStdlibApi::class)
@kotlin.internal.InlineOnly
public inline fun ULong.takeLowestOneBit(): ULong = toLong().takeLowestOneBit().toULong()
@@ -146,7 +136,7 @@ public inline fun ULong.takeLowestOneBit(): ULong = toLong().takeLowestOneBit().
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
@ExperimentalUnsignedTypes
@WasExperimental(ExperimentalUnsignedTypes::class)
@kotlin.internal.InlineOnly
public inline fun ULong.rotateLeft(bitCount: Int): ULong = toLong().rotateLeft(bitCount).toULong()
@@ -162,34 +152,31 @@ public inline fun ULong.rotateLeft(bitCount: Int): ULong = toLong().rotateLeft(b
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
@ExperimentalUnsignedTypes
@WasExperimental(ExperimentalUnsignedTypes::class)
@kotlin.internal.InlineOnly
public inline fun ULong.rotateRight(bitCount: Int): ULong = toLong().rotateRight(bitCount).toULong()
/**
* Counts the number of set bits in the binary representation of this [UByte] number.
*/
@SinceKotlin("1.4")
@WasExperimental(ExperimentalStdlibApi::class)
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class, ExperimentalStdlibApi::class)
@kotlin.internal.InlineOnly
public inline fun UByte.countOneBits(): Int = toUInt().countOneBits()
/**
* Counts the number of consecutive most significant bits that are zero in the binary representation of this [UByte] number.
*/
@SinceKotlin("1.4")
@WasExperimental(ExperimentalStdlibApi::class)
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class, ExperimentalStdlibApi::class)
@kotlin.internal.InlineOnly
public inline fun UByte.countLeadingZeroBits(): Int = toByte().countLeadingZeroBits()
/**
* Counts the number of consecutive least significant bits that are zero in the binary representation of this [UByte] number.
*/
@SinceKotlin("1.4")
@WasExperimental(ExperimentalStdlibApi::class)
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class, ExperimentalStdlibApi::class)
@kotlin.internal.InlineOnly
public inline fun UByte.countTrailingZeroBits(): Int = toByte().countTrailingZeroBits()
@@ -197,9 +184,8 @@ public inline fun UByte.countTrailingZeroBits(): Int = toByte().countTrailingZer
* Returns a number having a single bit set in the position of the most significant set bit of this [UByte] number,
* or zero, if this number is zero.
*/
@SinceKotlin("1.4")
@WasExperimental(ExperimentalStdlibApi::class)
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class, ExperimentalStdlibApi::class)
@kotlin.internal.InlineOnly
public inline fun UByte.takeHighestOneBit(): UByte = toInt().takeHighestOneBit().toUByte()
@@ -207,9 +193,8 @@ public inline fun UByte.takeHighestOneBit(): UByte = toInt().takeHighestOneBit()
* Returns a number having a single bit set in the position of the least significant set bit of this [UByte] number,
* or zero, if this number is zero.
*/
@SinceKotlin("1.4")
@WasExperimental(ExperimentalStdlibApi::class)
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class, ExperimentalStdlibApi::class)
@kotlin.internal.InlineOnly
public inline fun UByte.takeLowestOneBit(): UByte = toInt().takeLowestOneBit().toUByte()
@@ -226,7 +211,7 @@ public inline fun UByte.takeLowestOneBit(): UByte = toInt().takeLowestOneBit().t
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
@ExperimentalUnsignedTypes
@WasExperimental(ExperimentalUnsignedTypes::class)
@kotlin.internal.InlineOnly
public inline fun UByte.rotateLeft(bitCount: Int): UByte = toByte().rotateLeft(bitCount).toUByte()
@@ -242,34 +227,31 @@ public inline fun UByte.rotateLeft(bitCount: Int): UByte = toByte().rotateLeft(b
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
@ExperimentalUnsignedTypes
@WasExperimental(ExperimentalUnsignedTypes::class)
@kotlin.internal.InlineOnly
public inline fun UByte.rotateRight(bitCount: Int): UByte = toByte().rotateRight(bitCount).toUByte()
/**
* Counts the number of set bits in the binary representation of this [UShort] number.
*/
@SinceKotlin("1.4")
@WasExperimental(ExperimentalStdlibApi::class)
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class, ExperimentalStdlibApi::class)
@kotlin.internal.InlineOnly
public inline fun UShort.countOneBits(): Int = toUInt().countOneBits()
/**
* Counts the number of consecutive most significant bits that are zero in the binary representation of this [UShort] number.
*/
@SinceKotlin("1.4")
@WasExperimental(ExperimentalStdlibApi::class)
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class, ExperimentalStdlibApi::class)
@kotlin.internal.InlineOnly
public inline fun UShort.countLeadingZeroBits(): Int = toShort().countLeadingZeroBits()
/**
* Counts the number of consecutive least significant bits that are zero in the binary representation of this [UShort] number.
*/
@SinceKotlin("1.4")
@WasExperimental(ExperimentalStdlibApi::class)
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class, ExperimentalStdlibApi::class)
@kotlin.internal.InlineOnly
public inline fun UShort.countTrailingZeroBits(): Int = toShort().countTrailingZeroBits()
@@ -277,9 +259,8 @@ public inline fun UShort.countTrailingZeroBits(): Int = toShort().countTrailingZ
* Returns a number having a single bit set in the position of the most significant set bit of this [UShort] number,
* or zero, if this number is zero.
*/
@SinceKotlin("1.4")
@WasExperimental(ExperimentalStdlibApi::class)
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class, ExperimentalStdlibApi::class)
@kotlin.internal.InlineOnly
public inline fun UShort.takeHighestOneBit(): UShort = toInt().takeHighestOneBit().toUShort()
@@ -287,9 +268,8 @@ public inline fun UShort.takeHighestOneBit(): UShort = toInt().takeHighestOneBit
* Returns a number having a single bit set in the position of the least significant set bit of this [UShort] number,
* or zero, if this number is zero.
*/
@SinceKotlin("1.4")
@WasExperimental(ExperimentalStdlibApi::class)
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class, ExperimentalStdlibApi::class)
@kotlin.internal.InlineOnly
public inline fun UShort.takeLowestOneBit(): UShort = toInt().takeLowestOneBit().toUShort()
@@ -306,7 +286,7 @@ public inline fun UShort.takeLowestOneBit(): UShort = toInt().takeLowestOneBit()
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
@ExperimentalUnsignedTypes
@WasExperimental(ExperimentalUnsignedTypes::class)
@kotlin.internal.InlineOnly
public inline fun UShort.rotateLeft(bitCount: Int): UShort = toShort().rotateLeft(bitCount).toUShort()
@@ -322,6 +302,6 @@ public inline fun UShort.rotateLeft(bitCount: Int): UShort = toShort().rotateLef
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
@ExperimentalUnsignedTypes
@WasExperimental(ExperimentalUnsignedTypes::class)
@kotlin.internal.InlineOnly
public inline fun UShort.rotateRight(bitCount: Int): UShort = toShort().rotateRight(bitCount).toUShort()
@@ -1,9 +1,8 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@file:OptIn(ExperimentalUnsignedTypes::class)
package kotlin.internal
// (a - b) mod c
+10 -10
View File
@@ -10,8 +10,8 @@ package kotlin
import kotlin.experimental.*
import kotlin.jvm.*
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
@JvmInline
public value class UShort @PublishedApi internal constructor(@PublishedApi internal val data: Short) : Comparable<UShort> {
@@ -344,8 +344,8 @@ public value class UShort @PublishedApi internal constructor(@PublishedApi inter
* The least significant 8 bits of the resulting `UShort` value are the same as the bits of this `Byte` value,
* whereas the most significant 8 bits are filled with the sign bit of this value.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
@kotlin.internal.InlineOnly
public inline fun Byte.toUShort(): UShort = UShort(this.toShort())
/**
@@ -355,8 +355,8 @@ public inline fun Byte.toUShort(): UShort = UShort(this.toShort())
*
* The resulting `UShort` value has the same binary representation as this `Short` value.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
@kotlin.internal.InlineOnly
public inline fun Short.toUShort(): UShort = UShort(this)
/**
@@ -367,8 +367,8 @@ public inline fun Short.toUShort(): UShort = UShort(this)
*
* The resulting `UShort` value is represented by the least significant 16 bits of this `Int` value.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
@kotlin.internal.InlineOnly
public inline fun Int.toUShort(): UShort = UShort(this.toShort())
/**
@@ -379,7 +379,7 @@ public inline fun Int.toUShort(): UShort = UShort(this.toShort())
*
* The resulting `UShort` value is represented by the least significant 16 bits of this `Long` value.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
@kotlin.internal.InlineOnly
public inline fun Long.toUShort(): UShort = UShort(this.toShort())
@@ -41,8 +41,9 @@ internal constructor(@PublishedApi internal val storage: ShortArray) : Collectio
public override val size: Int get() = storage.size
/** Creates an iterator over the elements of the array. */
public override operator fun iterator(): UShortIterator = Iterator(storage)
public override operator fun iterator(): kotlin.collections.Iterator<UShort> = Iterator(storage)
@Suppress("DEPRECATION_ERROR")
private class Iterator(private val array: ShortArray) : UShortIterator() {
private var index = 0
override fun hasNext() = index < array.size
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -12,8 +12,8 @@ package kotlin.text
*
* @throws IllegalArgumentException when [radix] is not a valid radix for number to string conversion.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
//@kotlin.internal.InlineOnly
public /*inline*/ fun UByte.toString(radix: Int): String = this.toInt().toString(radix)
@@ -22,8 +22,8 @@ public /*inline*/ fun UByte.toString(radix: Int): String = this.toInt().toString
*
* @throws IllegalArgumentException when [radix] is not a valid radix for number to string conversion.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
//@kotlin.internal.InlineOnly
public /*inline*/ fun UShort.toString(radix: Int): String = this.toInt().toString(radix)
@@ -33,8 +33,8 @@ public /*inline*/ fun UShort.toString(radix: Int): String = this.toInt().toStrin
*
* @throws IllegalArgumentException when [radix] is not a valid radix for number to string conversion.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
//@kotlin.internal.InlineOnly
public /*inline*/ fun UInt.toString(radix: Int): String = this.toLong().toString(radix)
@@ -43,8 +43,8 @@ public /*inline*/ fun UInt.toString(radix: Int): String = this.toLong().toString
*
* @throws IllegalArgumentException when [radix] is not a valid radix for number to string conversion.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
public fun ULong.toString(radix: Int): String = ulongToString(this.toLong(), checkRadix(radix))
@@ -52,8 +52,8 @@ public fun ULong.toString(radix: Int): String = ulongToString(this.toLong(), che
* Parses the string as a signed [UByte] number and returns the result.
* @throws NumberFormatException if the string is not a valid representation of a number.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
public fun String.toUByte(): UByte = toUByteOrNull() ?: numberFormatError(this)
/**
@@ -61,8 +61,8 @@ public fun String.toUByte(): UByte = toUByteOrNull() ?: numberFormatError(this)
* @throws NumberFormatException if the string is not a valid representation of a number.
* @throws IllegalArgumentException when [radix] is not a valid radix for string to number conversion.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
public fun String.toUByte(radix: Int): UByte = toUByteOrNull(radix) ?: numberFormatError(this)
@@ -70,8 +70,8 @@ public fun String.toUByte(radix: Int): UByte = toUByteOrNull(radix) ?: numberFor
* Parses the string as a [UShort] number and returns the result.
* @throws NumberFormatException if the string is not a valid representation of a number.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
public fun String.toUShort(): UShort = toUShortOrNull() ?: numberFormatError(this)
/**
@@ -79,16 +79,16 @@ public fun String.toUShort(): UShort = toUShortOrNull() ?: numberFormatError(thi
* @throws NumberFormatException if the string is not a valid representation of a number.
* @throws IllegalArgumentException when [radix] is not a valid radix for string to number conversion.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
public fun String.toUShort(radix: Int): UShort = toUShortOrNull(radix) ?: numberFormatError(this)
/**
* Parses the string as an [UInt] number and returns the result.
* @throws NumberFormatException if the string is not a valid representation of a number.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
public fun String.toUInt(): UInt = toUIntOrNull() ?: numberFormatError(this)
/**
@@ -96,16 +96,16 @@ public fun String.toUInt(): UInt = toUIntOrNull() ?: numberFormatError(this)
* @throws NumberFormatException if the string is not a valid representation of a number.
* @throws IllegalArgumentException when [radix] is not a valid radix for string to number conversion.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
public fun String.toUInt(radix: Int): UInt = toUIntOrNull(radix) ?: numberFormatError(this)
/**
* Parses the string as a [ULong] number and returns the result.
* @throws NumberFormatException if the string is not a valid representation of a number.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
public fun String.toULong(): ULong = toULongOrNull() ?: numberFormatError(this)
/**
@@ -113,8 +113,8 @@ public fun String.toULong(): ULong = toULongOrNull() ?: numberFormatError(this)
* @throws NumberFormatException if the string is not a valid representation of a number.
* @throws IllegalArgumentException when [radix] is not a valid radix for string to number conversion.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
public fun String.toULong(radix: Int): ULong = toULongOrNull(radix) ?: numberFormatError(this)
@@ -125,8 +125,8 @@ public fun String.toULong(radix: Int): ULong = toULongOrNull(radix) ?: numberFor
* Parses the string as an [UByte] number and returns the result
* or `null` if the string is not a valid representation of a number.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
public fun String.toUByteOrNull(): UByte? = toUByteOrNull(radix = 10)
/**
@@ -135,8 +135,8 @@ public fun String.toUByteOrNull(): UByte? = toUByteOrNull(radix = 10)
*
* @throws IllegalArgumentException when [radix] is not a valid radix for string to number conversion.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
public fun String.toUByteOrNull(radix: Int): UByte? {
val int = this.toUIntOrNull(radix) ?: return null
if (int > UByte.MAX_VALUE) return null
@@ -147,8 +147,8 @@ public fun String.toUByteOrNull(radix: Int): UByte? {
* Parses the string as an [UShort] number and returns the result
* or `null` if the string is not a valid representation of a number.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
public fun String.toUShortOrNull(): UShort? = toUShortOrNull(radix = 10)
/**
@@ -157,8 +157,8 @@ public fun String.toUShortOrNull(): UShort? = toUShortOrNull(radix = 10)
*
* @throws IllegalArgumentException when [radix] is not a valid radix for string to number conversion.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
public fun String.toUShortOrNull(radix: Int): UShort? {
val int = this.toUIntOrNull(radix) ?: return null
if (int > UShort.MAX_VALUE) return null
@@ -169,8 +169,8 @@ public fun String.toUShortOrNull(radix: Int): UShort? {
* Parses the string as an [UInt] number and returns the result
* or `null` if the string is not a valid representation of a number.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
public fun String.toUIntOrNull(): UInt? = toUIntOrNull(radix = 10)
/**
@@ -179,8 +179,8 @@ public fun String.toUIntOrNull(): UInt? = toUIntOrNull(radix = 10)
*
* @throws IllegalArgumentException when [radix] is not a valid radix for string to number conversion.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
public fun String.toUIntOrNull(radix: Int): UInt? {
checkRadix(radix)
@@ -233,8 +233,8 @@ public fun String.toUIntOrNull(radix: Int): UInt? {
* Parses the string as an [ULong] number and returns the result
* or `null` if the string is not a valid representation of a number.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
public fun String.toULongOrNull(): ULong? = toULongOrNull(radix = 10)
/**
@@ -243,8 +243,8 @@ public fun String.toULongOrNull(): ULong? = toULongOrNull(radix = 10)
*
* @throws IllegalArgumentException when [radix] is not a valid radix for string to number conversion.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@SinceKotlin("1.5")
@WasExperimental(ExperimentalUnsignedTypes::class)
public fun String.toULongOrNull(radix: Int): ULong? {
checkRadix(radix)
@@ -1,9 +1,8 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* 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:OptIn(ExperimentalUnsignedTypes::class)
package kotlin
@PublishedApi