[Wasm] Fix stdlib String to Float parse

This commit is contained in:
Igor Yakovlev
2022-12-19 18:39:01 +01:00
committed by teamcity
parent 8b14f4b15c
commit 35340f2f04
2 changed files with 26 additions and 3 deletions
@@ -6,7 +6,7 @@
package kotlin.text
import kotlin.math.abs
import kotlin.wasm.internal.wasm_f32_demote_f64
/**
* Returns `true` if the content of this string is equal to the word "true", ignoring case, and `false` otherwise.
*/
@@ -84,13 +84,13 @@ public actual fun String.toDouble(): Double = kotlin.text.parseDouble(this)
* Parses the string as a [Float] number and returns the result.
* @throws NumberFormatException if the string is not a valid representation of a number.
*/
public actual fun String.toFloat(): Float = toDouble() as Float
public actual fun String.toFloat(): Float = wasm_f32_demote_f64(toDouble())
/**
* Parses the string as a [Float] number and returns the result
* or `null` if the string is not a valid representation of a number.
*/
public actual fun String.toFloatOrNull(): Float? = toDoubleOrNull() as Float?
public actual fun String.toFloatOrNull(): Float? = toDoubleOrNull()?.let { wasm_f32_demote_f64(it) }
/**
* Parses the string as a [Double] number and returns the result