diff --git a/js/js.libraries/src/core/generated/_RangesJs.kt b/js/js.libraries/src/core/generated/_RangesJs.kt index 6a004d30097..34e99217511 100644 --- a/js/js.libraries/src/core/generated/_RangesJs.kt +++ b/js/js.libraries/src/core/generated/_RangesJs.kt @@ -889,6 +889,7 @@ public fun Double.coerceIn(minimumValue: Double, maximumValue: Double): Double { * Ensures that this value lies in the specified [range]. * * @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`. + * @sample samples.comparisons.ComparableOps.coerceInFloatingPointRange */ @SinceKotlin("1.1") public fun > T.coerceIn(range: ClosedFloatingPointRange): T { diff --git a/libraries/stdlib/common/src/generated/_Ranges.kt b/libraries/stdlib/common/src/generated/_Ranges.kt index 3a270b9b8ca..23aefefa764 100644 --- a/libraries/stdlib/common/src/generated/_Ranges.kt +++ b/libraries/stdlib/common/src/generated/_Ranges.kt @@ -640,6 +640,7 @@ public expect fun Double.coerceIn(minimumValue: Double, maximumValue: Double): D * Ensures that this value lies in the specified [range]. * * @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`. + * @sample samples.comparisons.ComparableOps.coerceInFloatingPointRange */ @SinceKotlin("1.1") public expect fun > T.coerceIn(range: ClosedFloatingPointRange): T diff --git a/libraries/stdlib/samples/test/samples/comparisons/comparableOps.kt b/libraries/stdlib/samples/test/samples/comparisons/comparableOps.kt index c55fb5b5bb0..fa9de820935 100644 --- a/libraries/stdlib/samples/test/samples/comparisons/comparableOps.kt +++ b/libraries/stdlib/samples/test/samples/comparisons/comparableOps.kt @@ -66,4 +66,12 @@ class ComparableOps { assertPrints(DayOfWeek.FRIDAY.coerceIn(DayOfWeek.SATURDAY, DayOfWeek.SUNDAY), "SATURDAY") } + + @Sample + fun coerceInFloatingPointRange() { + assertPrints(10.1.coerceIn(1.0..10.0), "10.0") + assertPrints(9.9.coerceIn(1.0..10.0), "9.9") + + assertFailsWith { 9.9.coerceIn(1.0..Double.NaN) } + } } \ No newline at end of file diff --git a/libraries/stdlib/src/generated/_Ranges.kt b/libraries/stdlib/src/generated/_Ranges.kt index d079c37d81a..37ccbc40b20 100644 --- a/libraries/stdlib/src/generated/_Ranges.kt +++ b/libraries/stdlib/src/generated/_Ranges.kt @@ -889,6 +889,7 @@ public fun Double.coerceIn(minimumValue: Double, maximumValue: Double): Double { * Ensures that this value lies in the specified [range]. * * @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`. + * @sample samples.comparisons.ComparableOps.coerceInFloatingPointRange */ @SinceKotlin("1.1") public fun > T.coerceIn(range: ClosedFloatingPointRange): T { diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Comparables.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Comparables.kt index b871c6a9929..13864f4bda9 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Comparables.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Comparables.kt @@ -123,6 +123,7 @@ object ComparableOps : TemplateGroupBase() { Ensures that this value lies in the specified [range]. @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`. + @sample samples.comparisons.ComparableOps.coerceInFloatingPointRange """ } body(Generic) {