From a6c01f82b255e11d047ac71517257a761dba8cd6 Mon Sep 17 00:00:00 2001 From: Ilya Ryzhenkov Date: Fri, 18 Apr 2014 19:20:33 +0400 Subject: [PATCH] Make isNaN check language independent, working in JVM & JS --- libraries/stdlib/src/kotlin/Numbers.kt | 13 +++++++++++++ libraries/stdlib/src/kotlin/Ranges.kt | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 libraries/stdlib/src/kotlin/Numbers.kt diff --git a/libraries/stdlib/src/kotlin/Numbers.kt b/libraries/stdlib/src/kotlin/Numbers.kt new file mode 100644 index 00000000000..baf74f35640 --- /dev/null +++ b/libraries/stdlib/src/kotlin/Numbers.kt @@ -0,0 +1,13 @@ +package kotlin + +/** + * Returns {@code true} if the specified number is a + * Not-a-Number (NaN) value, {@code false} otherwise. + */ +fun Double.isNaN() = this != this + +/** + * Returns {@code true} if the specified number is a + * Not-a-Number (NaN) value, {@code false} otherwise. + */ +fun Float.isNaN() = this != this \ No newline at end of file diff --git a/libraries/stdlib/src/kotlin/Ranges.kt b/libraries/stdlib/src/kotlin/Ranges.kt index 6ee4e41b93b..16cee9b9884 100644 --- a/libraries/stdlib/src/kotlin/Ranges.kt +++ b/libraries/stdlib/src/kotlin/Ranges.kt @@ -135,13 +135,13 @@ public fun LongRange.step(step: Long): LongProgression { } public fun FloatRange.step(step: Float): FloatProgression { - if (java.lang.Float.isNaN(step)) throw IllegalArgumentException("Step must not be NaN") + if (step.isNaN()) throw IllegalArgumentException("Step must not be NaN") checkStepIsPositive(step > 0, step) return FloatProgression(start, end, step) } public fun DoubleRange.step(step: Double): DoubleProgression { - if (java.lang.Double.isNaN(step)) throw IllegalArgumentException("Step must not be NaN") + if (step.isNaN()) throw IllegalArgumentException("Step must not be NaN") checkStepIsPositive(step > 0, step) return DoubleProgression(start, end, step) }