Rename ClosedComparableRange to ClosedFloatingPointRange
This commit is contained in:
@@ -13,7 +13,7 @@ class ComparablePair<T : Comparable<T>>(val first: T, val second: T) : Comparabl
|
||||
fun <T : Comparable<T>> 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<Float> {
|
||||
operator fun Float.rangeTo(other: Float) = object : ClosedFloatingPointRange<Float> {
|
||||
override val endInclusive: Float = this@rangeTo
|
||||
override val start: Float = other
|
||||
override fun lessThanOrEquals(a: Float, b: Float) = a >= b
|
||||
|
||||
+1
-1
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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: Comparable<T>> T.coerceIn(range: ClosedComparableRange<T>): T {
|
||||
public fun <T: Comparable<T>> T.coerceIn(range: ClosedFloatingPointRange<T>): 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: Comparable<T>> T.coerceIn(range: ClosedComparableRange<T>): 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: Comparable<T>> T.coerceIn(range: ClosedRange<T>): T {
|
||||
if (range is ClosedComparableRange) {
|
||||
if (range is ClosedFloatingPointRange) {
|
||||
return this.coerceIn<T>(range)
|
||||
}
|
||||
if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: $range.")
|
||||
@@ -902,7 +902,7 @@ public fun <T: Comparable<T>> T.coerceIn(range: ClosedRange<T>): 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>): Int {
|
||||
if (range is ClosedComparableRange) {
|
||||
if (range is ClosedFloatingPointRange) {
|
||||
return this.coerceIn<Int>(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>): 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>): Long {
|
||||
if (range is ClosedComparableRange) {
|
||||
if (range is ClosedFloatingPointRange) {
|
||||
return this.coerceIn<Long>(range)
|
||||
}
|
||||
if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: $range.")
|
||||
|
||||
@@ -17,5 +17,5 @@
|
||||
package kotlin.ranges
|
||||
|
||||
@SinceKotlin("1.1")
|
||||
public inline operator fun Float.rangeTo(that: Float): ClosedComparableRange<Float> =
|
||||
this.toDouble().rangeTo(that.toDouble()).unsafeCast<ClosedComparableRange<Float>>()
|
||||
public inline operator fun Float.rangeTo(that: Float): ClosedFloatingPointRange<Float> =
|
||||
this.toDouble().rangeTo(that.toDouble()).unsafeCast<ClosedFloatingPointRange<Float>>()
|
||||
|
||||
@@ -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: Comparable<T>> T.coerceIn(range: ClosedComparableRange<T>): T
|
||||
public header fun <T: Comparable<T>> T.coerceIn(range: ClosedFloatingPointRange<T>): T
|
||||
|
||||
/**
|
||||
* Ensures that this value lies in the specified [range].
|
||||
|
||||
@@ -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: Comparable<T>> T.coerceIn(range: ClosedComparableRange<T>): T {
|
||||
public fun <T: Comparable<T>> T.coerceIn(range: ClosedFloatingPointRange<T>): 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: Comparable<T>> T.coerceIn(range: ClosedComparableRange<T>): 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: Comparable<T>> T.coerceIn(range: ClosedRange<T>): T {
|
||||
if (range is ClosedComparableRange) {
|
||||
if (range is ClosedFloatingPointRange) {
|
||||
return this.coerceIn<T>(range)
|
||||
}
|
||||
if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: $range.")
|
||||
@@ -903,7 +903,7 @@ public fun <T: Comparable<T>> T.coerceIn(range: ClosedRange<T>): 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>): Int {
|
||||
if (range is ClosedComparableRange) {
|
||||
if (range is ClosedFloatingPointRange) {
|
||||
return this.coerceIn<Int>(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>): 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>): Long {
|
||||
if (range is ClosedComparableRange) {
|
||||
if (range is ClosedFloatingPointRange) {
|
||||
return this.coerceIn<Long>(range)
|
||||
}
|
||||
if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: $range.")
|
||||
|
||||
@@ -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<T: Comparable<T>> : ClosedRange<T> {
|
||||
public interface ClosedFloatingPointRange<T: Comparable<T>> : ClosedRange<T> {
|
||||
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<T: Comparable<T>> (
|
||||
private class ClosedDoubleRange (
|
||||
start: Double,
|
||||
endInclusive: Double
|
||||
) : ClosedComparableRange<Double> {
|
||||
) : ClosedFloatingPointRange<Double> {
|
||||
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<Float> {
|
||||
): ClosedFloatingPointRange<Float> {
|
||||
private val _start = start
|
||||
private val _endInclusive = endInclusive
|
||||
override val start: Float get() = _start
|
||||
@@ -114,7 +114,7 @@ public operator fun <T: Comparable<T>> T.rangeTo(that: T): ClosedRange<T> = 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<Double> = ClosedDoubleRange(this, that)
|
||||
public operator fun Double.rangeTo(that: Double): ClosedFloatingPointRange<Double> = 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<Double>
|
||||
*/
|
||||
@JvmVersion
|
||||
@SinceKotlin("1.1")
|
||||
public operator fun Float.rangeTo(that: Float): ClosedComparableRange<Float> = ClosedFloatRange(this, that)
|
||||
public operator fun Float.rangeTo(that: Float): ClosedFloatingPointRange<Float> = ClosedFloatRange(this, that)
|
||||
|
||||
|
||||
internal fun checkStepIsPositive(isPositive: Boolean, step: Number) {
|
||||
|
||||
+7
-7
@@ -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;
|
||||
|
||||
@@ -61,7 +61,7 @@ fun comparables(): List<GenericFunction> {
|
||||
}
|
||||
body(Generic) {
|
||||
"""
|
||||
if (range is ClosedComparableRange) {
|
||||
if (range is ClosedFloatingPointRange) {
|
||||
return this.coerceIn<T>(range)
|
||||
}
|
||||
if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: ${'$'}range.")
|
||||
@@ -74,7 +74,7 @@ fun comparables(): List<GenericFunction> {
|
||||
}
|
||||
body(Primitives) {
|
||||
"""
|
||||
if (range is ClosedComparableRange) {
|
||||
if (range is ClosedFloatingPointRange) {
|
||||
return this.coerceIn<T>(range)
|
||||
}
|
||||
if (range.isEmpty()) throw IllegalArgumentException("Cannot coerce value to an empty range: ${'$'}range.")
|
||||
@@ -87,7 +87,7 @@ fun comparables(): List<GenericFunction> {
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("coerceIn(range: ClosedComparableRange<T>)") {
|
||||
templates add f("coerceIn(range: ClosedFloatingPointRange<T>)") {
|
||||
sourceFile(SourceFile.Ranges)
|
||||
only(Generic)
|
||||
returns("SELF")
|
||||
|
||||
Reference in New Issue
Block a user