stdlib: Fix number parsing
This commit is contained in:
+6
-1
@@ -50,7 +50,12 @@ private class ConversionWithRadixContext<T: Any>(val convertOrFail: (String, Int
|
||||
}
|
||||
}
|
||||
|
||||
private fun doubleTotalOrderEquals(a: Any?, b: Any?) = a == b
|
||||
private fun doubleTotalOrderEquals(a: Double?, b: Double?): Boolean {
|
||||
if (a != null && b != null && a.isNaN() && b.isNaN()) {
|
||||
return true
|
||||
}
|
||||
return a == b
|
||||
}
|
||||
|
||||
fun box() {
|
||||
compareConversion(String::toDouble, String::toDoubleOrNull, ::doubleTotalOrderEquals) {
|
||||
|
||||
+7
-1
@@ -57,6 +57,12 @@ fun box() {
|
||||
assertProduces("0x77p1", (0x77 shl 1).toDouble())
|
||||
assertProduces("0x.77P8", 0x77.toDouble())
|
||||
|
||||
assertFailsOrNull("0x77e1")
|
||||
// TODO: Java Double.valueOf specification requires mandatory binary exponent character (p) in the string parsed if the string is a hex one.
|
||||
// See: http://docs.oracle.com/javase/8/docs/api/java/lang/Double.html#valueOf-java.lang.String-
|
||||
// E.g.
|
||||
// "0x77p0".toDouble() // OK for both Kotlin/JVM and Kotlin/Native.
|
||||
// "0x77".toDouble() // throws NumberFormatException in Kotlin/JVM and OK in Kotlin/Native.
|
||||
// Do we need to handle such case? Or it is OK to consume such strings?
|
||||
//assertFailsOrNull("0x77e1")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user