feat: Replace percent button with Pi button, update logic and tests
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
@@ -37,7 +37,7 @@ var numbers = {
|
||||
'6': {grid: [2, 1], globalGrid: [2, 2], trbl: '9-35'},
|
||||
'7': {grid: [0, 0], globalGrid: [0, 1], trbl: 'R847'},
|
||||
'8': {grid: [1, 0], globalGrid: [1, 1], trbl: 'N957'},
|
||||
'9': {grid: [2, 0], globalGrid: [2, 1], trbl: '%*68'},
|
||||
'9': {grid: [2, 0], globalGrid: [2, 1], trbl: 'p*68'},
|
||||
'B': {grid: [0, 3], globalGrid: [0, 4], trbl: '10BB', val: '<-', color: COLORS.SPECIAL},
|
||||
};
|
||||
|
||||
@@ -46,7 +46,7 @@ var operators = {
|
||||
'+': {grid: [0, 0], globalGrid: [3, 3], trbl: '-+=3'},
|
||||
'-': {grid: [1, 0], globalGrid: [3, 2], trbl: '*-+6'},
|
||||
'*': {grid: [0, 1], globalGrid: [3, 1], trbl: '/*-9'},
|
||||
'/': {grid: [1, 1], globalGrid: [3, 0], trbl: '//*%'},
|
||||
'/': {grid: [1, 1], globalGrid: [3, 0], trbl: '//*p'},
|
||||
'=': {grid: [1, 2], globalGrid: [3, 4], trbl: '+==.'},
|
||||
};
|
||||
|
||||
@@ -73,8 +73,8 @@ var scientificOperators = {
|
||||
var specialsGrid = [2, 2];
|
||||
var specials = {
|
||||
'R': {grid: [0, 0], globalGrid: [0, 0], trbl: 'RN7R', val: 'AC'},
|
||||
'N': {grid: [1, 0], globalGrid: [1, 0], trbl: 'N%8R', val: '+/-'},
|
||||
'%': {grid: [0, 1], globalGrid: [2, 0], trbl: '%/9N'},
|
||||
'N': {grid: [1, 0], globalGrid: [1, 0], trbl: 'Np8R', val: '+/-'},
|
||||
'p': {grid: [0, 1], globalGrid: [2, 0], trbl: 'p/9N', val: 'Pi'},
|
||||
'send': {grid: [1, 1], val: 'send'},
|
||||
};
|
||||
|
||||
@@ -366,15 +366,16 @@ function buttonPress(val) {
|
||||
hasPressedNumber = false;
|
||||
displayOutput(0);
|
||||
break;
|
||||
case '%':
|
||||
if (results != null) {
|
||||
displayOutput(results /= 100);
|
||||
prevExpression = "(" + prevExpression + ")/100";
|
||||
} else if (currNumber != null) {
|
||||
displayOutput(currNumber /= 100);
|
||||
currExpression = "(" + currExpression + ")/100";
|
||||
case 'p':
|
||||
specials.R.val = 'C';
|
||||
if (!swipeEnabled) drawKey('R', specials.R);
|
||||
currNumber = Math.PI;
|
||||
if (hasPressedEquals === 1) {
|
||||
hasPressedEquals = 2;
|
||||
}
|
||||
hasPressedNumber = false;
|
||||
hasPressedNumber = currNumber;
|
||||
currExpression = currNumber.toString();
|
||||
displayOutput(currNumber);
|
||||
break;
|
||||
case 'r':
|
||||
if (results != null) {
|
||||
|
||||
+17
-1
@@ -330,7 +330,6 @@ const unaryOps = {
|
||||
'r': { name: 'sqrt', fn: Math.sqrt },
|
||||
's': { name: 'x^2', fn: (a) => a * a },
|
||||
'i': { name: '1/x', fn: (a) => 1 / a },
|
||||
'%': { name: '%', fn: (a) => a / 100 },
|
||||
};
|
||||
|
||||
for (const op in unaryOps) {
|
||||
@@ -501,5 +500,22 @@ test('Negative zero handling', () => {
|
||||
checkDisplay(-0);
|
||||
});
|
||||
|
||||
test('Pi button', () => {
|
||||
press('p');
|
||||
checkDisplay(Math.PI);
|
||||
press('*2=');
|
||||
checkDisplay(Math.PI * 2);
|
||||
});
|
||||
|
||||
test('Pi replaces current number entry', () => {
|
||||
press('123p');
|
||||
checkDisplay(Math.PI);
|
||||
});
|
||||
|
||||
test('Operation with Pi', () => {
|
||||
press('5*p=');
|
||||
checkDisplay(5 * Math.PI);
|
||||
});
|
||||
|
||||
// Run all the defined tests
|
||||
runTests();
|
||||
|
||||
Reference in New Issue
Block a user