fix: Correct negative zero logic for +/- and update test

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
2026-03-14 17:42:25 -06:00
committed by Tanner
parent 73cd819e94
commit 98fdddac5d
2 changed files with 18 additions and 5 deletions
+15 -2
View File
@@ -532,10 +532,23 @@ function buttonPress(val) {
break; break;
case 'N': case 'N':
if (results != null && !hasPressedNumber) { if (results != null && !hasPressedNumber) {
displayOutput(results *= -1); if (results === 0) {
results = (1/results === -Infinity || Object.is(results, -0)) ? 0 : -0;
} else {
results *= -1;
}
displayOutput(results);
prevExpression = "-(" + prevExpression + ")"; prevExpression = "-(" + prevExpression + ")";
} else { } else {
displayOutput(currNumber *= -1); if (currNumber === null) currNumber = '0';
var num = parseFloat(currNumber);
if (num === 0) {
// Toggle between 0 and -0
currNumber = (1/currNumber === -Infinity || Object.is(currNumber, -0)) ? '0' : -0;
} else {
currNumber = num * -1;
}
displayOutput(currNumber);
currExpression = "-(" + currExpression + ")"; currExpression = "-(" + currExpression + ")";
} }
break; break;
+3 -3
View File
@@ -493,11 +493,11 @@ test('Negative zero handling', () => {
press('0N'); // get -0 press('0N'); // get -0
checkDisplay(-0); checkDisplay(-0);
press('*5'); press('*5');
checkDisplay(-0); checkDisplay('5'); // after typing 5, display should be 5
press('='); press('=');
checkDisplay(-0); checkDisplay(-0); // -0 * 5 = -0
buttonPress('R'); buttonPress('R'); buttonPress('R'); buttonPress('R');
press('5*-0='); press('5*0N='); // 5 * -0 = -0
checkDisplay(-0); checkDisplay(-0);
}); });