Write docs for unsigned types conversions
This commit is contained in:
@@ -158,26 +158,93 @@ public inline class UByte @PublishedApi internal constructor(@PublishedApi inter
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun inv(): UByte = UByte(data.inv())
|
||||
|
||||
/**
|
||||
* Converts this [UByte] value to [Byte].
|
||||
*
|
||||
* If this value is less than or equals to [Byte.MAX_VALUE], the resulting `Byte` value represents
|
||||
* the same numerical value as this `UByte`. Otherwise the result is negative.
|
||||
*
|
||||
* The resulting `Byte` value has the same binary representation as this `UByte` value.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun toByte(): Byte = data
|
||||
/**
|
||||
* Converts this [UByte] value to [Short].
|
||||
*
|
||||
* The resulting `Short` value represents the same numerical value as this `UByte`.
|
||||
*
|
||||
* The least significant 8 bits of the resulting `Short` value are the same as the binary representation of this `UByte` value,
|
||||
* whereas the most significant 8 bits are filled with zeros.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun toShort(): Short = data.toShort() and 0xFF
|
||||
/**
|
||||
* Converts this [UByte] value to [Int].
|
||||
*
|
||||
* The resulting `Int` value represents the same numerical value as this `UByte`.
|
||||
*
|
||||
* The least significant 8 bits of the resulting `Int` value are the same as the binary representation of this `UByte` value,
|
||||
* whereas the most significant 24 bits are filled with zeros.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun toInt(): Int = data.toInt() and 0xFF
|
||||
/**
|
||||
* Converts this [UByte] value to [Long].
|
||||
*
|
||||
* The resulting `Long` value represents the same numerical value as this `UByte`.
|
||||
*
|
||||
* The least significant 8 bits of the resulting `Long` value are the same as the binary representation of this `UByte` value,
|
||||
* whereas the most significant 56 bits are filled with zeros.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun toLong(): Long = data.toLong() and 0xFF
|
||||
|
||||
/** Returns this value. */
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun toUByte(): UByte = this
|
||||
/**
|
||||
* Converts this [UByte] value to [UShort].
|
||||
*
|
||||
* The resulting `UShort` value represents the same numerical value as this `UByte`.
|
||||
*
|
||||
* The least significant 8 bits of the resulting `UShort` value are the same as the binary representation of this `UByte` value,
|
||||
* whereas the most significant 8 bits are filled with zeros.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun toUShort(): UShort = UShort(data.toShort() and 0xFF)
|
||||
/**
|
||||
* Converts this [UByte] value to [UInt].
|
||||
*
|
||||
* The resulting `UInt` value represents the same numerical value as this `UByte`.
|
||||
*
|
||||
* The least significant 8 bits of the resulting `UInt` value are the same as the binary representation of this `UByte` value,
|
||||
* whereas the most significant 24 bits are filled with zeros.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun toUInt(): UInt = UInt(data.toInt() and 0xFF)
|
||||
/**
|
||||
* Converts this [UByte] value to [ULong].
|
||||
*
|
||||
* The resulting `ULong` value represents the same numerical value as this `UByte`.
|
||||
*
|
||||
* The least significant 8 bits of the resulting `ULong` value are the same as the binary representation of this `UByte` value,
|
||||
* whereas the most significant 56 bits are filled with zeros.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun toULong(): ULong = ULong(data.toLong() and 0xFF)
|
||||
|
||||
/**
|
||||
* Converts this [UByte] value to [Float].
|
||||
*
|
||||
* The resulting `Float` value represents the same numerical value as this `UByte`.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun toFloat(): Float = this.toInt().toFloat()
|
||||
/**
|
||||
* Converts this [UByte] value to [Double].
|
||||
*
|
||||
* The resulting `Double` value represents the same numerical value as this `UByte`.
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun toDouble(): Double = this.toInt().toDouble()
|
||||
|
||||
@@ -185,27 +252,70 @@ public inline class UByte @PublishedApi internal constructor(@PublishedApi inter
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts this [Byte] value to [UByte].
|
||||
*
|
||||
* If this value is positive, the resulting `UByte` value represents the same numerical value as this `Byte`.
|
||||
*
|
||||
* The resulting `UByte` value has the same binary representation as this `Byte` value.
|
||||
*/
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun Byte.toUByte(): UByte = UByte(this)
|
||||
/**
|
||||
* Converts this [Short] value to [UByte].
|
||||
*
|
||||
* If this value is positive and less than or equals to [UByte.MAX_VALUE], the resulting `UByte` value represents
|
||||
* the same numerical value as this `Short`.
|
||||
*
|
||||
* The resulting `UByte` value is represented by the least significant 8 bits of this `Short` value.
|
||||
*/
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun Short.toUByte(): UByte = UByte(this.toByte())
|
||||
/**
|
||||
* Converts this [Int] value to [UByte].
|
||||
*
|
||||
* If this value is positive and less than or equals to [UByte.MAX_VALUE], the resulting `UByte` value represents
|
||||
* the same numerical value as this `Int`.
|
||||
*
|
||||
* The resulting `UByte` value is represented by the least significant 8 bits of this `Int` value.
|
||||
*/
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun Int.toUByte(): UByte = UByte(this.toByte())
|
||||
/**
|
||||
* Converts this [Long] value to [UByte].
|
||||
*
|
||||
* If this value is positive and less than or equals to [UByte.MAX_VALUE], the resulting `UByte` value represents
|
||||
* the same numerical value as this `Long`.
|
||||
*
|
||||
* The resulting `UByte` value is represented by the least significant 8 bits of this `Long` value.
|
||||
*/
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun Long.toUByte(): UByte = UByte(this.toByte())
|
||||
|
||||
/**
|
||||
* Converts this [Float] value to [UByte].
|
||||
*
|
||||
* The fractional part, if any, is rounded down.
|
||||
* Returns zero if this `Float` value is negative or `NaN`, [UByte.MAX_VALUE] if it's bigger than `UByte.MAX_VALUE`.
|
||||
*/
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun Float.toUByte(): UByte = doubleToUByte(this.toDouble())
|
||||
/**
|
||||
* Converts this [Double] value to [UByte].
|
||||
*
|
||||
* The fractional part, if any, is rounded down.
|
||||
* Returns zero if this `Double` value is negative or `NaN`, [UByte.MAX_VALUE] if it's bigger than `UByte.MAX_VALUE`.
|
||||
*/
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
@kotlin.internal.InlineOnly
|
||||
|
||||
Reference in New Issue
Block a user