Skip to content

Commit 116eb79

Browse files
committed
ensure float literals are hinted as floats in asm
1 parent 7d249fb commit 116eb79

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/parseTools.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,15 @@ function makeVarDef(js) {
997997
return js;
998998
}
999999

1000+
function asmEnsureFloat(value, type) { // ensures that a float type has either 5.5 (clearly a float) or +5 (float due to asm coercion)
1001+
if (!ASM_JS) return value;
1002+
if (!isIntImplemented(type) && isNumber(value) && value.toString().indexOf('.') < 0) {
1003+
return '(+(' + value + '))';
1004+
} else {
1005+
return value;
1006+
}
1007+
}
1008+
10001009
function asmInitializer(type, impl) {
10011010
if (isIntImplemented(type)) {// || (impl && impl == 'VAR_EMULATED')) {
10021011
return '0';
@@ -2097,7 +2106,7 @@ function processMathop(item) {
20972106
// then unsigning that i32... which would give something huge.
20982107
case 'zext': case 'fpext': case 'sext': return idents[0];
20992108
case 'fptrunc': return idents[0];
2100-
case 'select': return idents[0] + ' ? ' + idents[1] + ' : ' + idents[2];
2109+
case 'select': return idents[0] + ' ? ' + asmEnsureFloat(idents[1], item.type) + ' : ' + asmEnsureFloat(idents[2], item.type);
21012110
case 'ptrtoint': case 'inttoptr': {
21022111
var ret = '';
21032112
if (QUANTUM_SIZE == 1) {

0 commit comments

Comments
 (0)