Remove implementations of conversions from UByte/UShort to Float/Double

This commit is contained in:
Abduqodiri Qurbonzoda
2019-03-07 19:06:49 +03:00
parent d12e5ddafc
commit 82002e5e73
5 changed files with 4 additions and 62 deletions
+4 -1
View File
@@ -336,8 +336,11 @@ class UnsignedTypeGenerator(val type: UnsignedType, out: PrintWriter) : BuiltIns
else -> "$className(this.to$thisSigned())"
})
}
out.println()
if (type == UnsignedType.UBYTE || type == UnsignedType.USHORT)
return // conversion from UByte/UShort to Float/Double is not allowed
out.println()
for (otherType in PrimitiveType.floatingPoint) {
val otherName = otherType.capitalized
@@ -299,24 +299,3 @@ public inline fun Int.toUByte(): UByte = UByte(this.toByte())
@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
public inline fun Double.toUByte(): UByte = doubleToUByte(this)
@@ -300,24 +300,3 @@ public inline fun Int.toUShort(): UShort = UShort(this.toShort())
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun Long.toUShort(): UShort = UShort(this.toShort())
/**
* Converts this [Float] value to [UShort].
*
* The fractional part, if any, is rounded down.
* Returns zero if this `Float` value is negative or `NaN`, [UShort.MAX_VALUE] if it's bigger than `UShort.MAX_VALUE`.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun Float.toUShort(): UShort = doubleToUShort(this.toDouble())
/**
* Converts this [Double] value to [UShort].
*
* The fractional part, if any, is rounded down.
* Returns zero if this `Double` value is negative or `NaN`, [UShort.MAX_VALUE] if it's bigger than `UShort.MAX_VALUE`.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline fun Double.toUShort(): UShort = doubleToUShort(this)
@@ -62,23 +62,6 @@ internal fun ulongRemainder(v1: ULong, v2: ULong): ULong {
return ULong(rem - if (ULong(rem) >= ULong(divisor)) divisor else 0)
}
@PublishedApi
internal fun doubleToUByte(v: Double): UByte = when {
v.isNaN() -> 0u
v <= UByte.MIN_VALUE.toDouble() -> UByte.MIN_VALUE
v >= UByte.MAX_VALUE.toDouble() -> UByte.MAX_VALUE
else -> v.toInt().toUByte()
}
@PublishedApi
internal fun doubleToUShort(v: Double): UShort = when {
v.isNaN() -> 0u
v <= UShort.MIN_VALUE.toDouble() -> UShort.MIN_VALUE
v >= UShort.MAX_VALUE.toDouble() -> UShort.MAX_VALUE
else -> v.toInt().toUShort()
}
@PublishedApi
internal fun doubleToUInt(v: Double): UInt = when {
v.isNaN() -> 0u
@@ -462,10 +462,8 @@ public abstract interface annotation class kotlin/UnsafeVariance : java/lang/ann
}
public final class kotlin/UnsignedKt {
public static final fun doubleToUByte (D)B
public static final fun doubleToUInt (D)I
public static final fun doubleToULong (D)J
public static final fun doubleToUShort (D)S
public static final fun uintCompare (II)I
public static final fun uintDivide-J1ME1BU (II)I
public static final fun uintRemainder-J1ME1BU (II)I