JS: fix translation of float constants. See KT-8413
This commit is contained in:
@@ -1,6 +1,3 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
fun box(): String {
|
||||
if (1F != 1.toFloat()) return "fail 1"
|
||||
if (1.0F != 1.0.toFloat()) return "fail 2"
|
||||
|
||||
+1
-7
@@ -4542,13 +4542,7 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
@TestMetadata("float.kt")
|
||||
public void testFloat() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/constants/float.kt");
|
||||
try {
|
||||
doTest(fileName);
|
||||
}
|
||||
catch (Throwable ignore) {
|
||||
return;
|
||||
}
|
||||
throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that.");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt9532.kt")
|
||||
|
||||
@@ -138,6 +138,17 @@ public final class Translation {
|
||||
else if (value instanceof Long) {
|
||||
return JsAstUtils.newLong((Long) value, context);
|
||||
}
|
||||
else if (value instanceof Float) {
|
||||
float floatValue = (Float) value;
|
||||
double doubleValue;
|
||||
if (Float.isInfinite(floatValue) || Float.isNaN(floatValue)) {
|
||||
doubleValue = floatValue;
|
||||
}
|
||||
else {
|
||||
doubleValue = Double.parseDouble(Float.toString(floatValue));
|
||||
}
|
||||
return context.program().getNumberLiteral(doubleValue);
|
||||
}
|
||||
else if (value instanceof Number) {
|
||||
return context.program().getNumberLiteral(((Number) value).doubleValue());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user