diff --git a/js/js.libraries/src/core/generated/_ComparisonsJs.kt b/js/js.libraries/src/core/generated/_ComparisonsJs.kt new file mode 100644 index 00000000000..beaceab2e6e --- /dev/null +++ b/js/js.libraries/src/core/generated/_ComparisonsJs.kt @@ -0,0 +1,296 @@ +@file:kotlin.jvm.JvmMultifileClass +@file:kotlin.jvm.JvmName("ComparisonsKt") + +package kotlin.comparisons + +// +// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt +// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib +// + +import kotlin.comparisons.* + +/** + * Returns the greater of two values. + * If values are equal, returns the first one. + */ +@SinceKotlin("1.1") +public fun > maxOf(a: T, b: T): T { + return if (a >= b) a else b +} + +/** + * Returns the greater of two values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun maxOf(a: Byte, b: Byte): Byte { + return Math.max(a.toInt(), b.toInt()).toByte() +} + +/** + * Returns the greater of two values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun maxOf(a: Short, b: Short): Short { + return Math.max(a.toInt(), b.toInt()).toShort() +} + +/** + * Returns the greater of two values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun maxOf(a: Int, b: Int): Int { + return Math.max(a, b) +} + +/** + * Returns the greater of two values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun maxOf(a: Long, b: Long): Long { + return Math.max(a, b) +} + +/** + * Returns the greater of two values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun maxOf(a: Float, b: Float): Float { + return Math.max(a, b) +} + +/** + * Returns the greater of two values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun maxOf(a: Double, b: Double): Double { + return Math.max(a, b) +} + +/** + * Returns the greater of three values. + */ +@SinceKotlin("1.1") +public fun > maxOf(a: T, b: T, c: T): T { + return maxOf(a, maxOf(b, c)) +} + +/** + * Returns the greater of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun maxOf(a: Byte, b: Byte, c: Byte): Byte { + return Math.max(a.toInt(), Math.max(b.toInt(), c.toInt())).toByte() +} + +/** + * Returns the greater of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun maxOf(a: Short, b: Short, c: Short): Short { + return Math.max(a.toInt(), Math.max(b.toInt(), c.toInt())).toShort() +} + +/** + * Returns the greater of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun maxOf(a: Int, b: Int, c: Int): Int { + return maxOf(a, maxOf(b, c)) +} + +/** + * Returns the greater of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun maxOf(a: Long, b: Long, c: Long): Long { + return maxOf(a, maxOf(b, c)) +} + +/** + * Returns the greater of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun maxOf(a: Float, b: Float, c: Float): Float { + return maxOf(a, maxOf(b, c)) +} + +/** + * Returns the greater of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun maxOf(a: Double, b: Double, c: Double): Double { + return maxOf(a, maxOf(b, c)) +} + +/** + * Returns the greater of three values according to the order specified by the given [comparator]. + */ +@SinceKotlin("1.1") +public fun maxOf(a: T, b: T, c: T, comparator: Comparator): T { + return maxOf(a, maxOf(b, c, comparator), comparator) +} + +/** + * Returns the greater of two values according to the order specified by the given [comparator]. + * If values are equal, returns the first one. + */ +@SinceKotlin("1.1") +public fun maxOf(a: T, b: T, comparator: Comparator): T { + return if (comparator.compare(a, b) >= 0) a else b +} + +/** + * Returns the smaller of two values. + * If values are equal, returns the first one. + */ +@SinceKotlin("1.1") +public fun > minOf(a: T, b: T): T { + return if (a <= b) a else b +} + +/** + * Returns the smaller of two values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun minOf(a: Byte, b: Byte): Byte { + return Math.min(a.toInt(), b.toInt()).toByte() +} + +/** + * Returns the smaller of two values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun minOf(a: Short, b: Short): Short { + return Math.min(a.toInt(), b.toInt()).toShort() +} + +/** + * Returns the smaller of two values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun minOf(a: Int, b: Int): Int { + return Math.min(a, b) +} + +/** + * Returns the smaller of two values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun minOf(a: Long, b: Long): Long { + return Math.min(a, b) +} + +/** + * Returns the smaller of two values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun minOf(a: Float, b: Float): Float { + return Math.min(a, b) +} + +/** + * Returns the smaller of two values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun minOf(a: Double, b: Double): Double { + return Math.min(a, b) +} + +/** + * Returns the smaller of three values. + */ +@SinceKotlin("1.1") +public fun > minOf(a: T, b: T, c: T): T { + return minOf(a, minOf(b, c)) +} + +/** + * Returns the smaller of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun minOf(a: Byte, b: Byte, c: Byte): Byte { + return Math.min(a.toInt(), Math.min(b.toInt(), c.toInt())).toByte() +} + +/** + * Returns the smaller of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun minOf(a: Short, b: Short, c: Short): Short { + return Math.min(a.toInt(), Math.min(b.toInt(), c.toInt())).toShort() +} + +/** + * Returns the smaller of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun minOf(a: Int, b: Int, c: Int): Int { + return minOf(a, minOf(b, c)) +} + +/** + * Returns the smaller of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun minOf(a: Long, b: Long, c: Long): Long { + return minOf(a, minOf(b, c)) +} + +/** + * Returns the smaller of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun minOf(a: Float, b: Float, c: Float): Float { + return minOf(a, minOf(b, c)) +} + +/** + * Returns the smaller of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun minOf(a: Double, b: Double, c: Double): Double { + return minOf(a, minOf(b, c)) +} + +/** + * Returns the smaller of three values according to the order specified by the given [comparator]. + */ +@SinceKotlin("1.1") +public fun minOf(a: T, b: T, c: T, comparator: Comparator): T { + return minOf(a, minOf(b, c, comparator), comparator) +} + +/** + * Returns the smaller of two values according to the order specified by the given [comparator]. + * If values are equal, returns the first one. + */ +@SinceKotlin("1.1") +public fun minOf(a: T, b: T, comparator: Comparator): T { + return if (comparator.compare(a, b) <= 0) a else b +} + diff --git a/js/js.libraries/src/core/math.kt b/js/js.libraries/src/core/math.kt index d943657fc8b..d9eb048f480 100644 --- a/js/js.libraries/src/core/math.kt +++ b/js/js.libraries/src/core/math.kt @@ -12,9 +12,11 @@ public external class MathClass() { public fun cos(value: Double): Double = noImpl public fun sin(value: Double): Double = noImpl public fun exp(value: Double): Double = noImpl - public fun max(vararg values: Double): Double = noImpl public fun max(vararg values: Int): Int = noImpl + public fun max(vararg values: Float): Float = noImpl + public fun max(vararg values: Double): Double = noImpl public fun min(vararg values: Int): Int = noImpl + public fun min(vararg values: Float): Float = noImpl public fun min(vararg values: Double): Double = noImpl public fun sqrt(value: Double): Double = noImpl public fun tan(value: Double): Double = noImpl @@ -26,3 +28,6 @@ public external class MathClass() { } public external val Math: MathClass + +public fun MathClass.min(a: Long, b: Long): Long = if (a <= b) a else b +public fun MathClass.max(a: Long, b: Long): Long = if (a >= b) a else b \ No newline at end of file diff --git a/libraries/stdlib/common/src/generated/_Comparisons.kt b/libraries/stdlib/common/src/generated/_Comparisons.kt new file mode 100644 index 00000000000..9e0f9c1e352 --- /dev/null +++ b/libraries/stdlib/common/src/generated/_Comparisons.kt @@ -0,0 +1,232 @@ +@file:kotlin.jvm.JvmMultifileClass +@file:kotlin.jvm.JvmName("ComparisonsKt") + +package kotlin.comparisons + +// +// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt +// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib +// + +import kotlin.comparisons.* + +/** + * Returns the greater of two values. + * If values are equal, returns the first one. + */ +@SinceKotlin("1.1") +public header fun > maxOf(a: T, b: T): T + +/** + * Returns the greater of two values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public header inline fun maxOf(a: Byte, b: Byte): Byte + +/** + * Returns the greater of two values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public header inline fun maxOf(a: Short, b: Short): Short + +/** + * Returns the greater of two values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public header inline fun maxOf(a: Int, b: Int): Int + +/** + * Returns the greater of two values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public header inline fun maxOf(a: Long, b: Long): Long + +/** + * Returns the greater of two values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public header inline fun maxOf(a: Float, b: Float): Float + +/** + * Returns the greater of two values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public header inline fun maxOf(a: Double, b: Double): Double + +/** + * Returns the greater of three values. + */ +@SinceKotlin("1.1") +public header fun > maxOf(a: T, b: T, c: T): T + +/** + * Returns the greater of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public header inline fun maxOf(a: Byte, b: Byte, c: Byte): Byte + +/** + * Returns the greater of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public header inline fun maxOf(a: Short, b: Short, c: Short): Short + +/** + * Returns the greater of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public header inline fun maxOf(a: Int, b: Int, c: Int): Int + +/** + * Returns the greater of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public header inline fun maxOf(a: Long, b: Long, c: Long): Long + +/** + * Returns the greater of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public header inline fun maxOf(a: Float, b: Float, c: Float): Float + +/** + * Returns the greater of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public header inline fun maxOf(a: Double, b: Double, c: Double): Double + +/** + * Returns the greater of three values according to the order specified by the given [comparator]. + */ +@SinceKotlin("1.1") +public header fun maxOf(a: T, b: T, c: T, comparator: Comparator): T + +/** + * Returns the greater of two values according to the order specified by the given [comparator]. + * If values are equal, returns the first one. + */ +@SinceKotlin("1.1") +public header fun maxOf(a: T, b: T, comparator: Comparator): T + +/** + * Returns the smaller of two values. + * If values are equal, returns the first one. + */ +@SinceKotlin("1.1") +public header fun > minOf(a: T, b: T): T + +/** + * Returns the smaller of two values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public header inline fun minOf(a: Byte, b: Byte): Byte + +/** + * Returns the smaller of two values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public header inline fun minOf(a: Short, b: Short): Short + +/** + * Returns the smaller of two values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public header inline fun minOf(a: Int, b: Int): Int + +/** + * Returns the smaller of two values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public header inline fun minOf(a: Long, b: Long): Long + +/** + * Returns the smaller of two values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public header inline fun minOf(a: Float, b: Float): Float + +/** + * Returns the smaller of two values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public header inline fun minOf(a: Double, b: Double): Double + +/** + * Returns the smaller of three values. + */ +@SinceKotlin("1.1") +public header fun > minOf(a: T, b: T, c: T): T + +/** + * Returns the smaller of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public header inline fun minOf(a: Byte, b: Byte, c: Byte): Byte + +/** + * Returns the smaller of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public header inline fun minOf(a: Short, b: Short, c: Short): Short + +/** + * Returns the smaller of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public header inline fun minOf(a: Int, b: Int, c: Int): Int + +/** + * Returns the smaller of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public header inline fun minOf(a: Long, b: Long, c: Long): Long + +/** + * Returns the smaller of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public header inline fun minOf(a: Float, b: Float, c: Float): Float + +/** + * Returns the smaller of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public header inline fun minOf(a: Double, b: Double, c: Double): Double + +/** + * Returns the smaller of three values according to the order specified by the given [comparator]. + */ +@SinceKotlin("1.1") +public header fun minOf(a: T, b: T, c: T, comparator: Comparator): T + +/** + * Returns the smaller of two values according to the order specified by the given [comparator]. + * If values are equal, returns the first one. + */ +@SinceKotlin("1.1") +public header fun minOf(a: T, b: T, comparator: Comparator): T + diff --git a/libraries/stdlib/src/generated/_Comparisons.kt b/libraries/stdlib/src/generated/_Comparisons.kt new file mode 100644 index 00000000000..10bb9b1dc1f --- /dev/null +++ b/libraries/stdlib/src/generated/_Comparisons.kt @@ -0,0 +1,297 @@ +@file:kotlin.jvm.JvmMultifileClass +@file:kotlin.jvm.JvmName("ComparisonsKt") +@file:kotlin.jvm.JvmVersion + +package kotlin.comparisons + +// +// NOTE THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt +// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib +// + +import kotlin.comparisons.* + +/** + * Returns the greater of two values. + * If values are equal, returns the first one. + */ +@SinceKotlin("1.1") +public fun > maxOf(a: T, b: T): T { + return if (a >= b) a else b +} + +/** + * Returns the greater of two values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun maxOf(a: Byte, b: Byte): Byte { + return Math.max(a.toInt(), b.toInt()).toByte() +} + +/** + * Returns the greater of two values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun maxOf(a: Short, b: Short): Short { + return Math.max(a.toInt(), b.toInt()).toShort() +} + +/** + * Returns the greater of two values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun maxOf(a: Int, b: Int): Int { + return Math.max(a, b) +} + +/** + * Returns the greater of two values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun maxOf(a: Long, b: Long): Long { + return Math.max(a, b) +} + +/** + * Returns the greater of two values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun maxOf(a: Float, b: Float): Float { + return Math.max(a, b) +} + +/** + * Returns the greater of two values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun maxOf(a: Double, b: Double): Double { + return Math.max(a, b) +} + +/** + * Returns the greater of three values. + */ +@SinceKotlin("1.1") +public fun > maxOf(a: T, b: T, c: T): T { + return maxOf(a, maxOf(b, c)) +} + +/** + * Returns the greater of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun maxOf(a: Byte, b: Byte, c: Byte): Byte { + return Math.max(a.toInt(), Math.max(b.toInt(), c.toInt())).toByte() +} + +/** + * Returns the greater of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun maxOf(a: Short, b: Short, c: Short): Short { + return Math.max(a.toInt(), Math.max(b.toInt(), c.toInt())).toShort() +} + +/** + * Returns the greater of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun maxOf(a: Int, b: Int, c: Int): Int { + return maxOf(a, maxOf(b, c)) +} + +/** + * Returns the greater of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun maxOf(a: Long, b: Long, c: Long): Long { + return maxOf(a, maxOf(b, c)) +} + +/** + * Returns the greater of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun maxOf(a: Float, b: Float, c: Float): Float { + return maxOf(a, maxOf(b, c)) +} + +/** + * Returns the greater of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun maxOf(a: Double, b: Double, c: Double): Double { + return maxOf(a, maxOf(b, c)) +} + +/** + * Returns the greater of three values according to the order specified by the given [comparator]. + */ +@SinceKotlin("1.1") +public fun maxOf(a: T, b: T, c: T, comparator: Comparator): T { + return maxOf(a, maxOf(b, c, comparator), comparator) +} + +/** + * Returns the greater of two values according to the order specified by the given [comparator]. + * If values are equal, returns the first one. + */ +@SinceKotlin("1.1") +public fun maxOf(a: T, b: T, comparator: Comparator): T { + return if (comparator.compare(a, b) >= 0) a else b +} + +/** + * Returns the smaller of two values. + * If values are equal, returns the first one. + */ +@SinceKotlin("1.1") +public fun > minOf(a: T, b: T): T { + return if (a <= b) a else b +} + +/** + * Returns the smaller of two values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun minOf(a: Byte, b: Byte): Byte { + return Math.min(a.toInt(), b.toInt()).toByte() +} + +/** + * Returns the smaller of two values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun minOf(a: Short, b: Short): Short { + return Math.min(a.toInt(), b.toInt()).toShort() +} + +/** + * Returns the smaller of two values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun minOf(a: Int, b: Int): Int { + return Math.min(a, b) +} + +/** + * Returns the smaller of two values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun minOf(a: Long, b: Long): Long { + return Math.min(a, b) +} + +/** + * Returns the smaller of two values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun minOf(a: Float, b: Float): Float { + return Math.min(a, b) +} + +/** + * Returns the smaller of two values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun minOf(a: Double, b: Double): Double { + return Math.min(a, b) +} + +/** + * Returns the smaller of three values. + */ +@SinceKotlin("1.1") +public fun > minOf(a: T, b: T, c: T): T { + return minOf(a, minOf(b, c)) +} + +/** + * Returns the smaller of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun minOf(a: Byte, b: Byte, c: Byte): Byte { + return Math.min(a.toInt(), Math.min(b.toInt(), c.toInt())).toByte() +} + +/** + * Returns the smaller of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun minOf(a: Short, b: Short, c: Short): Short { + return Math.min(a.toInt(), Math.min(b.toInt(), c.toInt())).toShort() +} + +/** + * Returns the smaller of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun minOf(a: Int, b: Int, c: Int): Int { + return minOf(a, minOf(b, c)) +} + +/** + * Returns the smaller of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun minOf(a: Long, b: Long, c: Long): Long { + return minOf(a, minOf(b, c)) +} + +/** + * Returns the smaller of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun minOf(a: Float, b: Float, c: Float): Float { + return minOf(a, minOf(b, c)) +} + +/** + * Returns the smaller of three values. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline fun minOf(a: Double, b: Double, c: Double): Double { + return minOf(a, minOf(b, c)) +} + +/** + * Returns the smaller of three values according to the order specified by the given [comparator]. + */ +@SinceKotlin("1.1") +public fun minOf(a: T, b: T, c: T, comparator: Comparator): T { + return minOf(a, minOf(b, c, comparator), comparator) +} + +/** + * Returns the smaller of two values according to the order specified by the given [comparator]. + * If values are equal, returns the first one. + */ +@SinceKotlin("1.1") +public fun minOf(a: T, b: T, comparator: Comparator): T { + return if (comparator.compare(a, b) <= 0) a else b +} + diff --git a/libraries/stdlib/src/kotlin/comparisons/Comparisons.kt b/libraries/stdlib/src/kotlin/comparisons/Comparisons.kt index c352bd02321..4d224ed9846 100644 --- a/libraries/stdlib/src/kotlin/comparisons/Comparisons.kt +++ b/libraries/stdlib/src/kotlin/comparisons/Comparisons.kt @@ -14,6 +14,7 @@ * limitations under the License. */ @file:kotlin.jvm.JvmName("ComparisonsKt") +@file:kotlin.jvm.JvmMultifileClass package kotlin.comparisons diff --git a/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib.txt b/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib.txt index 5cff91751d1..c2cb60031bd 100644 --- a/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib.txt +++ b/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib.txt @@ -1699,6 +1699,14 @@ public final class kotlin/comparisons/ComparisonsKt { public static final fun compareBy ([Lkotlin/jvm/functions/Function1;)Ljava/util/Comparator; public static final fun compareValues (Ljava/lang/Comparable;Ljava/lang/Comparable;)I public static final fun compareValuesBy (Ljava/lang/Object;Ljava/lang/Object;[Lkotlin/jvm/functions/Function1;)I + public static final fun maxOf (Ljava/lang/Comparable;Ljava/lang/Comparable;)Ljava/lang/Comparable; + public static final fun maxOf (Ljava/lang/Comparable;Ljava/lang/Comparable;Ljava/lang/Comparable;)Ljava/lang/Comparable; + public static final fun maxOf (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/util/Comparator;)Ljava/lang/Object; + public static final fun maxOf (Ljava/lang/Object;Ljava/lang/Object;Ljava/util/Comparator;)Ljava/lang/Object; + public static final fun minOf (Ljava/lang/Comparable;Ljava/lang/Comparable;)Ljava/lang/Comparable; + public static final fun minOf (Ljava/lang/Comparable;Ljava/lang/Comparable;Ljava/lang/Comparable;)Ljava/lang/Comparable; + public static final fun minOf (Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/util/Comparator;)Ljava/lang/Object; + public static final fun minOf (Ljava/lang/Object;Ljava/lang/Object;Ljava/util/Comparator;)Ljava/lang/Object; public static final fun naturalOrder ()Ljava/util/Comparator; public static final fun nullsFirst (Ljava/util/Comparator;)Ljava/util/Comparator; public static final fun nullsLast (Ljava/util/Comparator;)Ljava/util/Comparator; diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Comparables.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Comparables.kt index e5e4a9ef603..01c07b84210 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Comparables.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Comparables.kt @@ -114,6 +114,176 @@ fun comparables(): List { } } + + templates add f("minOf(a: T, b: T)") { + sourceFile(SourceFile.Comparisons) + only(Primitives, Generic) + only(numericPrimitives) + since("1.1") + typeParam("T: Comparable") + returns("T") + customReceiver("") + inline(Primitives) { Inline.Only } + doc { + """ + Returns the smaller of two values. + If values are equal, returns the first one. + """ + } + doc(Primitives) { + """Returns the smaller of two values.""" + } + bodyForTypes(Primitives, PrimitiveType.Byte, PrimitiveType.Short) { p -> + "return Math.min(a.toInt(), b.toInt()).to$p()" + } + body(Primitives) { + "return Math.min(a, b)" + } + body(Generic) { + "return if (a <= b) a else b" + } + } + + templates add f("minOf(a: T, b: T, c: T)") { + sourceFile(SourceFile.Comparisons) + only(Primitives, Generic) + only(numericPrimitives) + since("1.1") + typeParam("T: Comparable") + returns("T") + customReceiver("") + inline(Primitives) { Inline.Only } + doc { + """ + Returns the smaller of three values. + """ + } + bodyForTypes(Primitives, PrimitiveType.Byte, PrimitiveType.Short) { p -> + "return Math.min(a.toInt(), Math.min(b.toInt(), c.toInt())).to$p()" + } + body { + "return minOf(a, minOf(b, c))" + } + } + + templates add f("minOf(a: T, b: T, comparator: Comparator)") { + sourceFile(SourceFile.Comparisons) + only(Generic) + since("1.1") + returns("T") + customReceiver("") + doc { + """ + Returns the smaller of two values according to the order specified by the given [comparator]. + If values are equal, returns the first one. + """ + } + body { + "return if (comparator.compare(a, b) <= 0) a else b" + } + } + + templates add f("minOf(a: T, b: T, c: T, comparator: Comparator)") { + sourceFile(SourceFile.Comparisons) + only(Generic) + since("1.1") + returns("T") + customReceiver("") + doc { + """ + Returns the smaller of three values according to the order specified by the given [comparator]. + """ + } + body { + "return minOf(a, minOf(b, c, comparator), comparator)" + } + } + + templates add f("maxOf(a: T, b: T)") { + sourceFile(SourceFile.Comparisons) + only(Primitives, Generic) + only(numericPrimitives) + since("1.1") + typeParam("T: Comparable") + returns("T") + customReceiver("") + inline(Primitives) { Inline.Only } + doc { + """ + Returns the greater of two values. + If values are equal, returns the first one. + """ + } + doc(Primitives) { + """Returns the greater of two values.""" + } + bodyForTypes(Primitives, PrimitiveType.Byte, PrimitiveType.Short) { p -> + "return Math.max(a.toInt(), b.toInt()).to$p()" + } + body(Primitives) { + "return Math.max(a, b)" + } + body(Generic) { + "return if (a >= b) a else b" + } + } + + templates add f("maxOf(a: T, b: T, c: T)") { + sourceFile(SourceFile.Comparisons) + only(Primitives, Generic) + only(numericPrimitives) + since("1.1") + typeParam("T: Comparable") + returns("T") + customReceiver("") + inline(Primitives) { Inline.Only } + doc { + """ + Returns the greater of three values. + """ + } + bodyForTypes(Primitives, PrimitiveType.Byte, PrimitiveType.Short) { p -> + "return Math.max(a.toInt(), Math.max(b.toInt(), c.toInt())).to$p()" + } + body { + "return maxOf(a, maxOf(b, c))" + } + } + + templates add f("maxOf(a: T, b: T, comparator: Comparator)") { + sourceFile(SourceFile.Comparisons) + only(Generic) + since("1.1") + returns("T") + customReceiver("") + doc { + """ + Returns the greater of two values according to the order specified by the given [comparator]. + If values are equal, returns the first one. + """ + } + body { + "return if (comparator.compare(a, b) >= 0) a else b" + } + } + + templates add f("maxOf(a: T, b: T, c: T, comparator: Comparator)") { + sourceFile(SourceFile.Comparisons) + only(Generic) + since("1.1") + returns("T") + customReceiver("") + doc { + """ + Returns the greater of three values according to the order specified by the given [comparator]. + """ + } + body { + "return maxOf(a, maxOf(b, c, comparator), comparator)" + } + } + + templates add f("coerceIn(minimumValue: SELF, maximumValue: SELF)") { sourceFile(SourceFile.Ranges) only(Primitives, Generic) diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/engine/SourceFile.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/engine/SourceFile.kt index fbd15e76569..5ba2b58a010 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/engine/SourceFile.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/engine/SourceFile.kt @@ -8,6 +8,7 @@ enum class SourceFile(jvmClassName: String? = null, val multifile: Boolean = tru Maps(packageName = "kotlin.collections"), Sequences(packageName = "kotlin.sequences"), Ranges(packageName = "kotlin.ranges"), + Comparisons(packageName = "kotlin.comparisons"), Strings(packageName = "kotlin.text"), Misc(), ;