From 82002e5e732d479e233da902230816f65c9b0ce3 Mon Sep 17 00:00:00 2001 From: Abduqodiri Qurbonzoda Date: Thu, 7 Mar 2019 19:06:49 +0300 Subject: [PATCH] Remove implementations of conversions from UByte/UShort to Float/Double --- generators/builtins/unsignedTypes.kt | 5 ++++- libraries/stdlib/unsigned/src/kotlin/UByte.kt | 21 ------------------- .../stdlib/unsigned/src/kotlin/UShort.kt | 21 ------------------- .../unsigned/src/kotlin/UnsignedUtils.kt | 17 --------------- .../kotlin-stdlib-runtime-merged.txt | 2 -- 5 files changed, 4 insertions(+), 62 deletions(-) diff --git a/generators/builtins/unsignedTypes.kt b/generators/builtins/unsignedTypes.kt index 44de31ca317..fca81ed3a9f 100644 --- a/generators/builtins/unsignedTypes.kt +++ b/generators/builtins/unsignedTypes.kt @@ -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 diff --git a/libraries/stdlib/unsigned/src/kotlin/UByte.kt b/libraries/stdlib/unsigned/src/kotlin/UByte.kt index 37c3fd6bc4e..fa954b52ce4 100644 --- a/libraries/stdlib/unsigned/src/kotlin/UByte.kt +++ b/libraries/stdlib/unsigned/src/kotlin/UByte.kt @@ -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) diff --git a/libraries/stdlib/unsigned/src/kotlin/UShort.kt b/libraries/stdlib/unsigned/src/kotlin/UShort.kt index f0a2c00094e..7fbc2906b8c 100644 --- a/libraries/stdlib/unsigned/src/kotlin/UShort.kt +++ b/libraries/stdlib/unsigned/src/kotlin/UShort.kt @@ -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) diff --git a/libraries/stdlib/unsigned/src/kotlin/UnsignedUtils.kt b/libraries/stdlib/unsigned/src/kotlin/UnsignedUtils.kt index 913bd8c8b0b..35958a5ec9b 100644 --- a/libraries/stdlib/unsigned/src/kotlin/UnsignedUtils.kt +++ b/libraries/stdlib/unsigned/src/kotlin/UnsignedUtils.kt @@ -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 diff --git a/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib-runtime-merged.txt b/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib-runtime-merged.txt index 66e71bc1f9d..1ef1974a47a 100644 --- a/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib-runtime-merged.txt +++ b/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib-runtime-merged.txt @@ -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