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:
@@ -532,10 +532,23 @@ function buttonPress(val) {
|
||||
break;
|
||||
case 'N':
|
||||
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 + ")";
|
||||
} 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 + ")";
|
||||
}
|
||||
break;
|
||||
|
||||
+3
-3
@@ -493,11 +493,11 @@ test('Negative zero handling', () => {
|
||||
press('0N'); // get -0
|
||||
checkDisplay(-0);
|
||||
press('*5');
|
||||
checkDisplay(-0);
|
||||
checkDisplay('5'); // after typing 5, display should be 5
|
||||
press('=');
|
||||
checkDisplay(-0);
|
||||
checkDisplay(-0); // -0 * 5 = -0
|
||||
buttonPress('R'); buttonPress('R');
|
||||
press('5*-0=');
|
||||
press('5*0N='); // 5 * -0 = -0
|
||||
checkDisplay(-0);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user