diff --git a/compiler/testData/codegen/box/ranges/contains/inComparableRange.kt b/compiler/testData/codegen/box/ranges/contains/inComparableRange.kt index 52103d1cdc4..71b784e107f 100644 --- a/compiler/testData/codegen/box/ranges/contains/inComparableRange.kt +++ b/compiler/testData/codegen/box/ranges/contains/inComparableRange.kt @@ -13,7 +13,7 @@ class ComparablePair>(val first: T, val second: T) : Comparabl fun > genericRangeTo(start: T, endInclusive: T) = start..endInclusive operator fun Double.rangeTo(other: Double) = genericRangeTo(this, other) // some weird inverted range -operator fun Float.rangeTo(other: Float) = object : ClosedComparableRange { +operator fun Float.rangeTo(other: Float) = object : ClosedFloatingPointRange { override val endInclusive: Float = this@rangeTo override val start: Float = other override fun lessThanOrEquals(a: Float, b: Float) = a >= b diff --git a/compiler/testData/codegen/light-analysis/ranges/contains/inComparableRange.txt b/compiler/testData/codegen/light-analysis/ranges/contains/inComparableRange.txt index 74ee5c65ac4..8f8400c858c 100644 --- a/compiler/testData/codegen/light-analysis/ranges/contains/inComparableRange.txt +++ b/compiler/testData/codegen/light-analysis/ranges/contains/inComparableRange.txt @@ -15,5 +15,5 @@ public final class InComparableRangeKt { public final static method check(p0: float, p1: float, p2: float): boolean public final static @org.jetbrains.annotations.NotNull method genericRangeTo(@org.jetbrains.annotations.NotNull p0: java.lang.Comparable, @org.jetbrains.annotations.NotNull p1: java.lang.Comparable): kotlin.ranges.ClosedRange public final static @org.jetbrains.annotations.NotNull method rangeTo(p0: double, p1: double): kotlin.ranges.ClosedRange - public final static @org.jetbrains.annotations.NotNull method rangeTo(p0: float, p1: float): kotlin.ranges.ClosedComparableRange + public final static @org.jetbrains.annotations.NotNull method rangeTo(p0: float, p1: float): kotlin.ranges.ClosedFloatingPointRange } diff --git a/compiler/testData/codegen/light-analysis/ranges/safeCallRangeTo.txt b/compiler/testData/codegen/light-analysis/ranges/safeCallRangeTo.txt index 59343a193cc..c02477ce756 100644 --- a/compiler/testData/codegen/light-analysis/ranges/safeCallRangeTo.txt +++ b/compiler/testData/codegen/light-analysis/ranges/safeCallRangeTo.txt @@ -2,8 +2,8 @@ public final class SafeCallRangeToKt { public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String public final static @org.jetbrains.annotations.Nullable method byteRange(@org.jetbrains.annotations.Nullable p0: java.lang.Byte, p1: byte): kotlin.ranges.IntRange public final static @org.jetbrains.annotations.Nullable method charRange(@org.jetbrains.annotations.Nullable p0: java.lang.Character, p1: char): kotlin.ranges.CharRange - public final static @org.jetbrains.annotations.Nullable method dougleRange(@org.jetbrains.annotations.Nullable p0: java.lang.Double, p1: double): kotlin.ranges.ClosedComparableRange - public final static @org.jetbrains.annotations.Nullable method floatRange(@org.jetbrains.annotations.Nullable p0: java.lang.Float, p1: float): kotlin.ranges.ClosedComparableRange + public final static @org.jetbrains.annotations.Nullable method dougleRange(@org.jetbrains.annotations.Nullable p0: java.lang.Double, p1: double): kotlin.ranges.ClosedFloatingPointRange + public final static @org.jetbrains.annotations.Nullable method floatRange(@org.jetbrains.annotations.Nullable p0: java.lang.Float, p1: float): kotlin.ranges.ClosedFloatingPointRange public final static @org.jetbrains.annotations.Nullable method intRange(@org.jetbrains.annotations.Nullable p0: java.lang.Integer, p1: int): kotlin.ranges.IntRange public final static @org.jetbrains.annotations.Nullable method longRange(@org.jetbrains.annotations.Nullable p0: java.lang.Long, p1: long): kotlin.ranges.LongRange public final static @org.jetbrains.annotations.Nullable method shortRange(@org.jetbrains.annotations.Nullable p0: java.lang.Short, p1: short): kotlin.ranges.IntRange diff --git a/js/js.libraries/src/core/generated/_RangesJs.kt b/js/js.libraries/src/core/generated/_RangesJs.kt index 8dae5b853ad..a10c447ac29 100644 --- a/js/js.libraries/src/core/generated/_RangesJs.kt +++ b/js/js.libraries/src/core/generated/_RangesJs.kt @@ -868,7 +868,7 @@ public fun Double.coerceIn(minimumValue: Double, maximumValue: Double): Double { * * @return this value if it's in the [range], or `range.start` if this value is less than `range.start`, or `range.endInclusive` if this value is greater than `range.endInclusive`. */ -public fun > T.coerceIn(range: ClosedComparableRange): T { +public fun > T.coerceIn(range: ClosedFloatingPointRange): T { if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: $range.") return when { // this < start equiv to this <= start && !(this >= start) @@ -885,7 +885,7 @@ public fun > T.coerceIn(range: ClosedComparableRange): T { * @return this value if it's in the [range], or `range.start` if this value is less than `range.start`, or `range.endInclusive` if this value is greater than `range.endInclusive`. */ public fun > T.coerceIn(range: ClosedRange): T { - if (range is ClosedComparableRange) { + if (range is ClosedFloatingPointRange) { return this.coerceIn(range) } if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: $range.") @@ -902,7 +902,7 @@ public fun > T.coerceIn(range: ClosedRange): T { * @return this value if it's in the [range], or `range.start` if this value is less than `range.start`, or `range.endInclusive` if this value is greater than `range.endInclusive`. */ public fun Int.coerceIn(range: ClosedRange): Int { - if (range is ClosedComparableRange) { + if (range is ClosedFloatingPointRange) { return this.coerceIn(range) } if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: $range.") @@ -919,7 +919,7 @@ public fun Int.coerceIn(range: ClosedRange): Int { * @return this value if it's in the [range], or `range.start` if this value is less than `range.start`, or `range.endInclusive` if this value is greater than `range.endInclusive`. */ public fun Long.coerceIn(range: ClosedRange): Long { - if (range is ClosedComparableRange) { + if (range is ClosedFloatingPointRange) { return this.coerceIn(range) } if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: $range.") diff --git a/js/js.libraries/src/core/ranges.kt b/js/js.libraries/src/core/ranges.kt index 75b71fb047b..11f4d08a130 100644 --- a/js/js.libraries/src/core/ranges.kt +++ b/js/js.libraries/src/core/ranges.kt @@ -17,5 +17,5 @@ package kotlin.ranges @SinceKotlin("1.1") -public inline operator fun Float.rangeTo(that: Float): ClosedComparableRange = - this.toDouble().rangeTo(that.toDouble()).unsafeCast>() +public inline operator fun Float.rangeTo(that: Float): ClosedFloatingPointRange = + this.toDouble().rangeTo(that.toDouble()).unsafeCast>() diff --git a/libraries/stdlib/common/src/generated/_Ranges.kt b/libraries/stdlib/common/src/generated/_Ranges.kt index 1c8f7a89983..37f8ef23c01 100644 --- a/libraries/stdlib/common/src/generated/_Ranges.kt +++ b/libraries/stdlib/common/src/generated/_Ranges.kt @@ -620,7 +620,7 @@ public header fun Double.coerceIn(minimumValue: Double, maximumValue: Double): D * * @return this value if it's in the [range], or `range.start` if this value is less than `range.start`, or `range.endInclusive` if this value is greater than `range.endInclusive`. */ -public header fun > T.coerceIn(range: ClosedComparableRange): T +public header fun > T.coerceIn(range: ClosedFloatingPointRange): T /** * Ensures that this value lies in the specified [range]. diff --git a/libraries/stdlib/src/generated/_Ranges.kt b/libraries/stdlib/src/generated/_Ranges.kt index eefdbde175e..ae868886be3 100644 --- a/libraries/stdlib/src/generated/_Ranges.kt +++ b/libraries/stdlib/src/generated/_Ranges.kt @@ -869,7 +869,7 @@ public fun Double.coerceIn(minimumValue: Double, maximumValue: Double): Double { * * @return this value if it's in the [range], or `range.start` if this value is less than `range.start`, or `range.endInclusive` if this value is greater than `range.endInclusive`. */ -public fun > T.coerceIn(range: ClosedComparableRange): T { +public fun > T.coerceIn(range: ClosedFloatingPointRange): T { if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: $range.") return when { // this < start equiv to this <= start && !(this >= start) @@ -886,7 +886,7 @@ public fun > T.coerceIn(range: ClosedComparableRange): T { * @return this value if it's in the [range], or `range.start` if this value is less than `range.start`, or `range.endInclusive` if this value is greater than `range.endInclusive`. */ public fun > T.coerceIn(range: ClosedRange): T { - if (range is ClosedComparableRange) { + if (range is ClosedFloatingPointRange) { return this.coerceIn(range) } if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: $range.") @@ -903,7 +903,7 @@ public fun > T.coerceIn(range: ClosedRange): T { * @return this value if it's in the [range], or `range.start` if this value is less than `range.start`, or `range.endInclusive` if this value is greater than `range.endInclusive`. */ public fun Int.coerceIn(range: ClosedRange): Int { - if (range is ClosedComparableRange) { + if (range is ClosedFloatingPointRange) { return this.coerceIn(range) } if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: $range.") @@ -920,7 +920,7 @@ public fun Int.coerceIn(range: ClosedRange): Int { * @return this value if it's in the [range], or `range.start` if this value is less than `range.start`, or `range.endInclusive` if this value is greater than `range.endInclusive`. */ public fun Long.coerceIn(range: ClosedRange): Long { - if (range is ClosedComparableRange) { + if (range is ClosedFloatingPointRange) { return this.coerceIn(range) } if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: $range.") diff --git a/libraries/stdlib/src/kotlin/ranges/Ranges.kt b/libraries/stdlib/src/kotlin/ranges/Ranges.kt index 43cef5730f3..d6ec6eb926b 100644 --- a/libraries/stdlib/src/kotlin/ranges/Ranges.kt +++ b/libraries/stdlib/src/kotlin/ranges/Ranges.kt @@ -3,14 +3,14 @@ package kotlin.ranges /** - * Represents a range of values (for example, numbers or characters). + * Represents a range of floating point numbers. * Extends [ClosedRange] interface providing custom operation [lessThanOrEquals] for comparing values of range domain type. * * This interface is implemented by floating point ranges returned by [Float.rangeTo] and [Double.rangeTo] operators to * achieve IEEE-754 comparison order instead of total order of floating point numbers. */ @SinceKotlin("1.1") -public interface ClosedComparableRange> : ClosedRange { +public interface ClosedFloatingPointRange> : ClosedRange { override fun contains(value: T): Boolean = lessThanOrEquals(start, value) && lessThanOrEquals(value, endInclusive) override fun isEmpty(): Boolean = !lessThanOrEquals(start, endInclusive) @@ -48,7 +48,7 @@ private open class ComparableRange> ( private class ClosedDoubleRange ( start: Double, endInclusive: Double -) : ClosedComparableRange { +) : ClosedFloatingPointRange { private val _start = start private val _endInclusive = endInclusive override val start: Double get() = _start @@ -79,7 +79,7 @@ private class ClosedDoubleRange ( private class ClosedFloatRange ( start: Float, endInclusive: Float -): ClosedComparableRange { +): ClosedFloatingPointRange { private val _start = start private val _endInclusive = endInclusive override val start: Float get() = _start @@ -114,7 +114,7 @@ public operator fun > T.rangeTo(that: T): ClosedRange = Comp * Numbers are compared with the ends of this range according to IEEE-754. */ @SinceKotlin("1.1") -public operator fun Double.rangeTo(that: Double): ClosedComparableRange = ClosedDoubleRange(this, that) +public operator fun Double.rangeTo(that: Double): ClosedFloatingPointRange = ClosedDoubleRange(this, that) /** * Creates a range from this [Float] value to the specified [other] value. @@ -123,7 +123,7 @@ public operator fun Double.rangeTo(that: Double): ClosedComparableRange */ @JvmVersion @SinceKotlin("1.1") -public operator fun Float.rangeTo(that: Float): ClosedComparableRange = ClosedFloatRange(this, that) +public operator fun Float.rangeTo(that: Float): ClosedFloatingPointRange = ClosedFloatRange(this, that) internal fun checkStepIsPositive(isPositive: Boolean, step: Number) { 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 1f720cc7990..6077db3b5fb 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 @@ -1888,15 +1888,15 @@ public abstract interface class kotlin/properties/ReadWriteProperty { public abstract fun setValue (Ljava/lang/Object;Lkotlin/reflect/KProperty;Ljava/lang/Object;)V } -public abstract interface class kotlin/ranges/ClosedComparableRange : kotlin/ranges/ClosedRange { +public abstract interface class kotlin/ranges/ClosedFloatingPointRange : kotlin/ranges/ClosedRange { public abstract fun contains (Ljava/lang/Comparable;)Z public abstract fun isEmpty ()Z public abstract fun lessThanOrEquals (Ljava/lang/Comparable;Ljava/lang/Comparable;)Z } -public final class kotlin/ranges/ClosedComparableRange$DefaultImpls { - public static fun contains (Lkotlin/ranges/ClosedComparableRange;Ljava/lang/Comparable;)Z - public static fun isEmpty (Lkotlin/ranges/ClosedComparableRange;)Z +public final class kotlin/ranges/ClosedFloatingPointRange$DefaultImpls { + public static fun contains (Lkotlin/ranges/ClosedFloatingPointRange;Ljava/lang/Comparable;)Z + public static fun isEmpty (Lkotlin/ranges/ClosedFloatingPointRange;)Z } public final class kotlin/ranges/RangesKt { @@ -1927,7 +1927,7 @@ public final class kotlin/ranges/RangesKt { public static final fun coerceIn (JJJ)J public static final fun coerceIn (JLkotlin/ranges/ClosedRange;)J public static final fun coerceIn (Ljava/lang/Comparable;Ljava/lang/Comparable;Ljava/lang/Comparable;)Ljava/lang/Comparable; - public static final fun coerceIn (Ljava/lang/Comparable;Lkotlin/ranges/ClosedComparableRange;)Ljava/lang/Comparable; + public static final fun coerceIn (Ljava/lang/Comparable;Lkotlin/ranges/ClosedFloatingPointRange;)Ljava/lang/Comparable; public static final fun coerceIn (Ljava/lang/Comparable;Lkotlin/ranges/ClosedRange;)Ljava/lang/Comparable; public static final fun coerceIn (SSS)S public static final fun doubleRangeContains (Lkotlin/ranges/ClosedRange;B)Z @@ -1967,8 +1967,8 @@ public final class kotlin/ranges/RangesKt { public static final fun longRangeContains (Lkotlin/ranges/ClosedRange;F)Z public static final fun longRangeContains (Lkotlin/ranges/ClosedRange;I)Z public static final fun longRangeContains (Lkotlin/ranges/ClosedRange;S)Z - public static final fun rangeTo (DD)Lkotlin/ranges/ClosedComparableRange; - public static final fun rangeTo (FF)Lkotlin/ranges/ClosedComparableRange; + public static final fun rangeTo (DD)Lkotlin/ranges/ClosedFloatingPointRange; + public static final fun rangeTo (FF)Lkotlin/ranges/ClosedFloatingPointRange; public static final fun rangeTo (Ljava/lang/Comparable;Ljava/lang/Comparable;)Lkotlin/ranges/ClosedRange; public static final fun reversed (Lkotlin/ranges/CharProgression;)Lkotlin/ranges/CharProgression; public static final fun reversed (Lkotlin/ranges/IntProgression;)Lkotlin/ranges/IntProgression; diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Comparables.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Comparables.kt index aed098f8454..1d885f650a3 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Comparables.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Comparables.kt @@ -61,7 +61,7 @@ fun comparables(): List { } body(Generic) { """ - if (range is ClosedComparableRange) { + if (range is ClosedFloatingPointRange) { return this.coerceIn(range) } if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: ${'$'}range.") @@ -74,7 +74,7 @@ fun comparables(): List { } body(Primitives) { """ - if (range is ClosedComparableRange) { + if (range is ClosedFloatingPointRange) { return this.coerceIn(range) } if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: ${'$'}range.") @@ -87,7 +87,7 @@ fun comparables(): List { } } - templates add f("coerceIn(range: ClosedComparableRange)") { + templates add f("coerceIn(range: ClosedFloatingPointRange)") { sourceFile(SourceFile.Ranges) only(Generic) returns("SELF")