[JS IR BE] Fix translation for float literals

This commit is contained in:
Roman Artemev
2018-10-23 19:07:24 +03:00
committed by romanart
parent 59b1743c37
commit 91ea377622
4 changed files with 4 additions and 3 deletions
@@ -44,11 +44,13 @@ class IrElementToJsExpressionTransformer : BaseIrElementToJsNodeTransformer<JsEx
is IrConstKind.Int -> JsIntLiteral(kind.valueOf(expression))
is IrConstKind.Long -> throw IllegalStateException("Long const should have been lowered at this point")
is IrConstKind.Char -> throw IllegalStateException("Char const should have been lowered at this point")
is IrConstKind.Float -> JsDoubleLiteral(kind.valueOf(expression).toDouble())
is IrConstKind.Float -> JsDoubleLiteral(toDoubleConst(kind.valueOf(expression)))
is IrConstKind.Double -> JsDoubleLiteral(kind.valueOf(expression))
}
}
private fun toDoubleConst(f: Float) = if (f.isInfinite() || f.isNaN()) f.toDouble() else f.toString().toDouble()
override fun visitStringConcatenation(expression: IrStringConcatenation, context: JsGenerationContext): JsExpression {
// TODO revisit
return expression.arguments.fold<IrExpression, JsExpression>(JsStringLiteral("")) { jsExpr, irExpr ->
-1
View File
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JS_IR
fun box(): String {
if (1F != 1.toFloat()) return "fail 1"
if (1.0F != 1.0.toFloat()) return "fail 2"
@@ -1,4 +1,5 @@
// IGNORE_BACKEND: JS
// IGNORE_BACKEND: JS_IR
// WITH_RUNTIME
fun checkByteArray(): Boolean {
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JS_IR
// WITH_RUNTIME
import kotlin.test.assertEquals