fix: Parse numeric input for scientific ops and expose operators to tests
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
@@ -417,7 +417,7 @@ function buttonPress(val) {
|
|||||||
displayOutput(results);
|
displayOutput(results);
|
||||||
prevExpression = "sin(" + prevExpression + ")";
|
prevExpression = "sin(" + prevExpression + ")";
|
||||||
} else if (currNumber != null) {
|
} else if (currNumber != null) {
|
||||||
let angle = currNumber;
|
let angle = parseFloat(currNumber);
|
||||||
if (angleMode === 'deg') {
|
if (angleMode === 'deg') {
|
||||||
angle = angle * Math.PI / 180;
|
angle = angle * Math.PI / 180;
|
||||||
}
|
}
|
||||||
@@ -437,7 +437,7 @@ function buttonPress(val) {
|
|||||||
displayOutput(results);
|
displayOutput(results);
|
||||||
prevExpression = "cos(" + prevExpression + ")";
|
prevExpression = "cos(" + prevExpression + ")";
|
||||||
} else if (currNumber != null) {
|
} else if (currNumber != null) {
|
||||||
let angle = currNumber;
|
let angle = parseFloat(currNumber);
|
||||||
if (angleMode === 'deg') {
|
if (angleMode === 'deg') {
|
||||||
angle = angle * Math.PI / 180;
|
angle = angle * Math.PI / 180;
|
||||||
}
|
}
|
||||||
@@ -457,7 +457,7 @@ function buttonPress(val) {
|
|||||||
displayOutput(results);
|
displayOutput(results);
|
||||||
prevExpression = "tan(" + prevExpression + ")";
|
prevExpression = "tan(" + prevExpression + ")";
|
||||||
} else if (currNumber != null) {
|
} else if (currNumber != null) {
|
||||||
let angle = currNumber;
|
let angle = parseFloat(currNumber);
|
||||||
if (angleMode === 'deg') {
|
if (angleMode === 'deg') {
|
||||||
angle = angle * Math.PI / 180;
|
angle = angle * Math.PI / 180;
|
||||||
}
|
}
|
||||||
@@ -473,7 +473,7 @@ function buttonPress(val) {
|
|||||||
displayOutput(results);
|
displayOutput(results);
|
||||||
prevExpression = "log(" + prevExpression + ")";
|
prevExpression = "log(" + prevExpression + ")";
|
||||||
} else if (currNumber != null) {
|
} else if (currNumber != null) {
|
||||||
currNumber = Math.log(currNumber) / Math.LN10;
|
currNumber = Math.log(parseFloat(currNumber)) / Math.LN10;
|
||||||
displayOutput(currNumber);
|
displayOutput(currNumber);
|
||||||
currExpression = "log(" + currExpression + ")";
|
currExpression = "log(" + currExpression + ")";
|
||||||
}
|
}
|
||||||
@@ -485,7 +485,7 @@ function buttonPress(val) {
|
|||||||
displayOutput(results);
|
displayOutput(results);
|
||||||
prevExpression = "10^(" + prevExpression + ")";
|
prevExpression = "10^(" + prevExpression + ")";
|
||||||
} else if (currNumber != null) {
|
} else if (currNumber != null) {
|
||||||
currNumber = Math.pow(10, currNumber);
|
currNumber = Math.pow(10, parseFloat(currNumber));
|
||||||
displayOutput(currNumber);
|
displayOutput(currNumber);
|
||||||
currExpression = "10^(" + currExpression + ")";
|
currExpression = "10^(" + currExpression + ")";
|
||||||
}
|
}
|
||||||
@@ -497,7 +497,7 @@ function buttonPress(val) {
|
|||||||
displayOutput(results);
|
displayOutput(results);
|
||||||
prevExpression = "ln(" + prevExpression + ")";
|
prevExpression = "ln(" + prevExpression + ")";
|
||||||
} else if (currNumber != null) {
|
} else if (currNumber != null) {
|
||||||
currNumber = Math.log(currNumber);
|
currNumber = Math.log(parseFloat(currNumber));
|
||||||
displayOutput(currNumber);
|
displayOutput(currNumber);
|
||||||
currExpression = "ln(" + currExpression + ")";
|
currExpression = "ln(" + currExpression + ")";
|
||||||
}
|
}
|
||||||
@@ -509,7 +509,7 @@ function buttonPress(val) {
|
|||||||
displayOutput(results);
|
displayOutput(results);
|
||||||
prevExpression = "e^(" + prevExpression + ")";
|
prevExpression = "e^(" + prevExpression + ")";
|
||||||
} else if (currNumber != null) {
|
} else if (currNumber != null) {
|
||||||
currNumber = Math.exp(currNumber);
|
currNumber = Math.exp(parseFloat(currNumber));
|
||||||
displayOutput(currNumber);
|
displayOutput(currNumber);
|
||||||
currExpression = "e^(" + currExpression + ")";
|
currExpression = "e^(" + currExpression + ")";
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -66,9 +66,9 @@ global.load = () => {};
|
|||||||
// We wrap the app code in a function that returns the buttonPress function,
|
// We wrap the app code in a function that returns the buttonPress function,
|
||||||
// so we can capture it and use it in our tests.
|
// so we can capture it and use it in our tests.
|
||||||
const calculatorCode = fs.readFileSync(path.join(__dirname, 'calculator.app.js'), 'utf8');
|
const calculatorCode = fs.readFileSync(path.join(__dirname, 'calculator.app.js'), 'utf8');
|
||||||
const wrappedCode = `(function(require) { ${calculatorCode}; return buttonPress; })`;
|
const wrappedCode = `(function(require) { ${calculatorCode}; return { buttonPress, scientificOperators }; })`;
|
||||||
const getButtonPress = eval(wrappedCode);
|
const getAppFns = eval(wrappedCode);
|
||||||
const buttonPress = getButtonPress((name) => {
|
const { buttonPress, scientificOperators } = getAppFns((name) => {
|
||||||
if (name === "FontDylex7x13") {
|
if (name === "FontDylex7x13") {
|
||||||
return { add: () => {} };
|
return { add: () => {} };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user