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'},
|
'6': {grid: [2, 1], globalGrid: [2, 2], trbl: '9-35'},
|
||||||
'7': {grid: [0, 0], globalGrid: [0, 1], trbl: 'R847'},
|
'7': {grid: [0, 0], globalGrid: [0, 1], trbl: 'R847'},
|
||||||
'8': {grid: [1, 0], globalGrid: [1, 1], trbl: 'N957'},
|
'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},
|
'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: [0, 0], globalGrid: [3, 3], trbl: '-+=3'},
|
||||||
'-': {grid: [1, 0], globalGrid: [3, 2], trbl: '*-+6'},
|
'-': {grid: [1, 0], globalGrid: [3, 2], trbl: '*-+6'},
|
||||||
'*': {grid: [0, 1], globalGrid: [3, 1], trbl: '/*-9'},
|
'*': {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: '+==.'},
|
'=': {grid: [1, 2], globalGrid: [3, 4], trbl: '+==.'},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -73,8 +73,8 @@ var scientificOperators = {
|
|||||||
var specialsGrid = [2, 2];
|
var specialsGrid = [2, 2];
|
||||||
var specials = {
|
var specials = {
|
||||||
'R': {grid: [0, 0], globalGrid: [0, 0], trbl: 'RN7R', val: 'AC'},
|
'R': {grid: [0, 0], globalGrid: [0, 0], trbl: 'RN7R', val: 'AC'},
|
||||||
'N': {grid: [1, 0], globalGrid: [1, 0], trbl: 'N%8R', val: '+/-'},
|
'N': {grid: [1, 0], globalGrid: [1, 0], trbl: 'Np8R', val: '+/-'},
|
||||||
'%': {grid: [0, 1], globalGrid: [2, 0], trbl: '%/9N'},
|
'p': {grid: [0, 1], globalGrid: [2, 0], trbl: 'p/9N', val: 'Pi'},
|
||||||
'send': {grid: [1, 1], val: 'send'},
|
'send': {grid: [1, 1], val: 'send'},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -366,15 +366,16 @@ function buttonPress(val) {
|
|||||||
hasPressedNumber = false;
|
hasPressedNumber = false;
|
||||||
displayOutput(0);
|
displayOutput(0);
|
||||||
break;
|
break;
|
||||||
case '%':
|
case 'p':
|
||||||
if (results != null) {
|
specials.R.val = 'C';
|
||||||
displayOutput(results /= 100);
|
if (!swipeEnabled) drawKey('R', specials.R);
|
||||||
prevExpression = "(" + prevExpression + ")/100";
|
currNumber = Math.PI;
|
||||||
} else if (currNumber != null) {
|
if (hasPressedEquals === 1) {
|
||||||
displayOutput(currNumber /= 100);
|
hasPressedEquals = 2;
|
||||||
currExpression = "(" + currExpression + ")/100";
|
|
||||||
}
|
}
|
||||||
hasPressedNumber = false;
|
hasPressedNumber = currNumber;
|
||||||
|
currExpression = currNumber.toString();
|
||||||
|
displayOutput(currNumber);
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
if (results != null) {
|
if (results != null) {
|
||||||
|
|||||||
+17
-1
@@ -330,7 +330,6 @@ const unaryOps = {
|
|||||||
'r': { name: 'sqrt', fn: Math.sqrt },
|
'r': { name: 'sqrt', fn: Math.sqrt },
|
||||||
's': { name: 'x^2', fn: (a) => a * a },
|
's': { name: 'x^2', fn: (a) => a * a },
|
||||||
'i': { name: '1/x', fn: (a) => 1 / a },
|
'i': { name: '1/x', fn: (a) => 1 / a },
|
||||||
'%': { name: '%', fn: (a) => a / 100 },
|
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const op in unaryOps) {
|
for (const op in unaryOps) {
|
||||||
@@ -501,5 +500,22 @@ test('Negative zero handling', () => {
|
|||||||
checkDisplay(-0);
|
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
|
// Run all the defined tests
|
||||||
runTests();
|
runTests();
|
||||||
|
|||||||
Reference in New Issue
Block a user