Fixed NaN = 0 wrongly reporting true, and add a test

This commit is contained in:
Tacodiva committed 2025-09-08 11:48:55 +10:00
1 parent b8defadedb
commit fbca1bf49b
6 files changed
+96 -90

No files matched your search

+2 -2
View File
@@ -57,8 +57,8 @@ const isSafeInputForEqualsOptimization = (input, other) => {
if (input.opcode !== InputOpcode.CONSTANT) return false;
// Only optimize when the constant can always be thought of as a number
if (input.isAlwaysType(InputType.NUMBER) || input.isAlwaysType(InputType.STRING_NUM)) {
if (other.isSometimesType(InputType.STRING_NAN) || other.isSometimesType(InputType.BOOLEAN_INTERPRETABLE)) {
// Never optimize 0 if the other input can be '' or a boolean.
if (other.isSometimesType(InputType.NUMBER_NAN | InputType.STRING_NAN | InputType.BOOLEAN_INTERPRETABLE)) {
// Never optimize 0 if the other input can be NaN, '' or a boolean.
// eg. if '< 0 = "" >' was optimized it would turn into `0 === +""`,
// which would be true even though Scratch would return false.
return (+input.inputs.value) !== 0;
Binary file not shown.
@@ -1,71 +1,74 @@
// TW Snapshot
// Input SHA-256: 2c124b6184d3cbeb3d692ba7a04266d8bf141c650a9cc43b28faf59ac394ee16
// Input SHA-256: 7916f21ea252ad0887060c6eb7ade266b41077b30ed849ad33947e01e6f73514
// Sprite1 script
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage();
const b0 = runtime.getOpcodeFunction("looks_say");
return function* genXYZ () {
yield* executeInCompatibilityLayer({"MESSAGE":"plan 20",}, b0, false, false, "v", null);
yield* executeInCompatibilityLayer({"MESSAGE":"plan 21",}, b0, false, false, "B", null);
if (!(("" + (0 / 0)).toLowerCase() === "0".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "aA", null);
}
if ((("" + (0 * Infinity)).toLowerCase() === "NaN".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "6", null);
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "/", null);
}
if (((((0 * Infinity) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "#", null);
}
if ((("" + ((Math.acos(1.01) * 180) / Math.PI)).toLowerCase() === "NaN".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "9", null);
}
if ((((((Math.acos(1.01) * 180) / Math.PI) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "(", null);
}
if ((("" + ((Math.asin(1.01) * 180) / Math.PI)).toLowerCase() === "NaN".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "*", null);
}
if ((((((Math.asin(1.01) * 180) / Math.PI) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, ",", null);
}
if ((("" + (0 / 0)).toLowerCase() === "NaN".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, ".", null);
}
if (((((0 / 0) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, ":", null);
}
if ((("" + Math.sqrt(-1)).toLowerCase() === "NaN".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "?", null);
}
if ((((Math.sqrt(-1) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "@", null);
if ((("" + ((Math.acos(1.01) * 180) / Math.PI)).toLowerCase() === "NaN".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "=", null);
}
if ((("" + mod(0, 0)).toLowerCase() === "NaN".toLowerCase())) {
if ((((((Math.acos(1.01) * 180) / Math.PI) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "]", null);
}
if ((((mod(0, 0) || 0) * 1) === 0)) {
if ((("" + ((Math.asin(1.01) * 180) / Math.PI)).toLowerCase() === "NaN".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "_", null);
}
if ((("" + Math.log(-1)).toLowerCase() === "NaN".toLowerCase())) {
if ((((((Math.asin(1.01) * 180) / Math.PI) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "{", null);
}
if ((((Math.log(-1) || 0) * 1) === 0)) {
if ((("" + (0 / 0)).toLowerCase() === "NaN".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "}", null);
}
if ((("" + (Math.log(-1) / Math.LN10)).toLowerCase() === "NaN".toLowerCase())) {
if (((((0 / 0) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "aa", null);
}
if (((((Math.log(-1) / Math.LN10) || 0) * 1) === 0)) {
if ((("" + Math.sqrt(-1)).toLowerCase() === "NaN".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "ac", null);
}
if (((((Math.round(Math.sin((Math.PI * ((1 / 0) || 0)) / 180) * 1e10) / 1e10) || 0) * 1) === 0)) {
if ((((Math.sqrt(-1) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "ae", null);
}
if (((((Math.round(Math.cos((Math.PI * ((1 / 0) || 0)) / 180) * 1e10) / 1e10) || 0) * 1) === 0)) {
if ((("" + mod(0, 0)).toLowerCase() === "NaN".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "ag", null);
}
if ((((tan(((1 / 0) || 0)) || 0) * 1) === 0)) {
if ((((mod(0, 0) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "ai", null);
}
if ((((runtime.ext_scratch3_operators._random((-1 / 0), (1 / 0)) || 0) * 1) === 0)) {
if ((("" + Math.log(-1)).toLowerCase() === "NaN".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "ak", null);
}
yield* executeInCompatibilityLayer({"MESSAGE":"end",}, b0, false, false, "7", null);
if ((((Math.log(-1) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "am", null);
}
if ((("" + (Math.log(-1) / Math.LN10)).toLowerCase() === "NaN".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "ao", null);
}
if (((((Math.log(-1) / Math.LN10) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "aq", null);
}
if (((((Math.round(Math.sin((Math.PI * ((1 / 0) || 0)) / 180) * 1e10) / 1e10) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "as", null);
}
if (((((Math.round(Math.cos((Math.PI * ((1 / 0) || 0)) / 180) * 1e10) / 1e10) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "au", null);
}
if ((((tan(((1 / 0) || 0)) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "aw", null);
}
if ((((runtime.ext_scratch3_operators._random((-1 / 0), (1 / 0)) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "ax", null);
}
yield* executeInCompatibilityLayer({"MESSAGE":"end",}, b0, false, false, ":", null);
retire(); return;
}; })
@@ -6,31 +6,31 @@
const b0 = runtime.getOpcodeFunction("looks_say");
return function* genXYZ () {
yield* executeInCompatibilityLayer({"MESSAGE":"plan 15",}, b0, false, false, "p", null);
if (((tan(0) || 0) === 0)) {
if (compareEqual(tan(0), 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass 0",}, b0, false, false, "O", null);
}
if (((tan(90) || 0) === Infinity)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass 90",}, b0, false, false, "G", null);
}
if (((tan(180) || 0) === 0)) {
if (compareEqual(tan(180), 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass 180",}, b0, false, false, "I", null);
}
if (((tan(270) || 0) === -Infinity)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass 270",}, b0, false, false, "K", null);
}
if (((tan(360) || 0) === 0)) {
if (compareEqual(tan(360), 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass 360",}, b0, false, false, "M", null);
}
if (((tan(450) || 0) === Infinity)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass 450",}, b0, false, false, "Q", null);
}
if (((tan(540) || 0) === 0)) {
if (compareEqual(tan(540), 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass 540",}, b0, false, false, "S", null);
}
if (((tan(630) || 0) === -Infinity)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass 630",}, b0, false, false, "U", null);
}
if (((tan(720) || 0) === 0)) {
if (compareEqual(tan(720), 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass 720",}, b0, false, false, "W", null);
}
if (((tan(810) || 0) === Infinity)) {
@@ -39,13 +39,13 @@ yield* executeInCompatibilityLayer({"MESSAGE":"pass 810",}, b0, false, false, "Y
if (((tan(-90) || 0) === -Infinity)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass -90",}, b0, false, false, "0", null);
}
if (((tan(-180) || 0) === 0)) {
if (compareEqual(tan(-180), 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass -180",}, b0, false, false, "2", null);
}
if (((tan(-270) || 0) === Infinity)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass -270",}, b0, false, false, "4", null);
}
if (((tan(-360) || 0) === 0)) {
if (compareEqual(tan(-360), 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass -360",}, b0, false, false, "6", null);
}
if (((tan(-450) || 0) === -Infinity)) {
@@ -1,71 +1,74 @@
// TW Snapshot
// Input SHA-256: 2c124b6184d3cbeb3d692ba7a04266d8bf141c650a9cc43b28faf59ac394ee16
// Input SHA-256: 7916f21ea252ad0887060c6eb7ade266b41077b30ed849ad33947e01e6f73514
// Sprite1 script
(function factoryXYZ(thread) { const target = thread.target; const runtime = target.runtime; const stage = runtime.getTargetForStage();
const b0 = runtime.getOpcodeFunction("looks_say");
return function* genXYZ () {
yield* executeInCompatibilityLayer({"MESSAGE":"plan 20",}, b0, false, false, "v", null);
yield* executeInCompatibilityLayer({"MESSAGE":"plan 21",}, b0, false, false, "B", null);
if (!(("" + (0 / 0)).toLowerCase() === "0".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "aA", null);
}
if ((("" + (0 * Infinity)).toLowerCase() === "NaN".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "6", null);
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "/", null);
}
if (((((0 * Infinity) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "#", null);
}
if ((("" + ((Math.acos(1.01) * 180) / Math.PI)).toLowerCase() === "NaN".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "9", null);
}
if ((((((Math.acos(1.01) * 180) / Math.PI) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "(", null);
}
if ((("" + ((Math.asin(1.01) * 180) / Math.PI)).toLowerCase() === "NaN".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "*", null);
}
if ((((((Math.asin(1.01) * 180) / Math.PI) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, ",", null);
}
if ((("" + (0 / 0)).toLowerCase() === "NaN".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, ".", null);
}
if (((((0 / 0) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, ":", null);
}
if ((("" + Math.sqrt(-1)).toLowerCase() === "NaN".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "?", null);
}
if ((((Math.sqrt(-1) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "@", null);
if ((("" + ((Math.acos(1.01) * 180) / Math.PI)).toLowerCase() === "NaN".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "=", null);
}
if ((("" + mod(0, 0)).toLowerCase() === "NaN".toLowerCase())) {
if ((((((Math.acos(1.01) * 180) / Math.PI) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "]", null);
}
if ((((mod(0, 0) || 0) * 1) === 0)) {
if ((("" + ((Math.asin(1.01) * 180) / Math.PI)).toLowerCase() === "NaN".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "_", null);
}
if ((("" + Math.log(-1)).toLowerCase() === "NaN".toLowerCase())) {
if ((((((Math.asin(1.01) * 180) / Math.PI) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "{", null);
}
if ((((Math.log(-1) || 0) * 1) === 0)) {
if ((("" + (0 / 0)).toLowerCase() === "NaN".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "}", null);
}
if ((("" + (Math.log(-1) / Math.LN10)).toLowerCase() === "NaN".toLowerCase())) {
if (((((0 / 0) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "aa", null);
}
if (((((Math.log(-1) / Math.LN10) || 0) * 1) === 0)) {
if ((("" + Math.sqrt(-1)).toLowerCase() === "NaN".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "ac", null);
}
if (((((Math.round(Math.sin((Math.PI * ((1 / 0) || 0)) / 180) * 1e10) / 1e10) || 0) * 1) === 0)) {
if ((((Math.sqrt(-1) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "ae", null);
}
if (((((Math.round(Math.cos((Math.PI * ((1 / 0) || 0)) / 180) * 1e10) / 1e10) || 0) * 1) === 0)) {
if ((("" + mod(0, 0)).toLowerCase() === "NaN".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "ag", null);
}
if ((((tan(((1 / 0) || 0)) || 0) * 1) === 0)) {
if ((((mod(0, 0) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "ai", null);
}
if ((((runtime.ext_scratch3_operators._random((-1 / 0), (1 / 0)) || 0) * 1) === 0)) {
if ((("" + Math.log(-1)).toLowerCase() === "NaN".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "ak", null);
}
yield* executeInCompatibilityLayer({"MESSAGE":"end",}, b0, false, false, "7", null);
if ((((Math.log(-1) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "am", null);
}
if ((("" + (Math.log(-1) / Math.LN10)).toLowerCase() === "NaN".toLowerCase())) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "ao", null);
}
if (((((Math.log(-1) / Math.LN10) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "aq", null);
}
if (((((Math.round(Math.sin((Math.PI * ((1 / 0) || 0)) / 180) * 1e10) / 1e10) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "as", null);
}
if (((((Math.round(Math.cos((Math.PI * ((1 / 0) || 0)) / 180) * 1e10) / 1e10) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "au", null);
}
if ((((tan(((1 / 0) || 0)) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "aw", null);
}
if ((((runtime.ext_scratch3_operators._random((-1 / 0), (1 / 0)) || 0) * 1) === 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass",}, b0, false, false, "ax", null);
}
yield* executeInCompatibilityLayer({"MESSAGE":"end",}, b0, false, false, ":", null);
retire(); return;
}; })
@@ -6,31 +6,31 @@
const b0 = runtime.getOpcodeFunction("looks_say");
return function* genXYZ () {
yield* executeInCompatibilityLayer({"MESSAGE":"plan 15",}, b0, false, false, "p", null);
if (((tan(0) || 0) === 0)) {
if (compareEqual(tan(0), 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass 0",}, b0, false, false, "O", null);
}
if (((tan(90) || 0) === Infinity)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass 90",}, b0, false, false, "G", null);
}
if (((tan(180) || 0) === 0)) {
if (compareEqual(tan(180), 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass 180",}, b0, false, false, "I", null);
}
if (((tan(270) || 0) === -Infinity)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass 270",}, b0, false, false, "K", null);
}
if (((tan(360) || 0) === 0)) {
if (compareEqual(tan(360), 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass 360",}, b0, false, false, "M", null);
}
if (((tan(450) || 0) === Infinity)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass 450",}, b0, false, false, "Q", null);
}
if (((tan(540) || 0) === 0)) {
if (compareEqual(tan(540), 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass 540",}, b0, false, false, "S", null);
}
if (((tan(630) || 0) === -Infinity)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass 630",}, b0, false, false, "U", null);
}
if (((tan(720) || 0) === 0)) {
if (compareEqual(tan(720), 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass 720",}, b0, false, false, "W", null);
}
if (((tan(810) || 0) === Infinity)) {
@@ -39,13 +39,13 @@ yield* executeInCompatibilityLayer({"MESSAGE":"pass 810",}, b0, false, false, "Y
if (((tan(-90) || 0) === -Infinity)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass -90",}, b0, false, false, "0", null);
}
if (((tan(-180) || 0) === 0)) {
if (compareEqual(tan(-180), 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass -180",}, b0, false, false, "2", null);
}
if (((tan(-270) || 0) === Infinity)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass -270",}, b0, false, false, "4", null);
}
if (((tan(-360) || 0) === 0)) {
if (compareEqual(tan(-360), 0)) {
yield* executeInCompatibilityLayer({"MESSAGE":"pass -360",}, b0, false, false, "6", null);
}
if (((tan(-450) || 0) === -Infinity)) {