feat: add pow10 and exp arithmetic operations
This commit is contained in:
@@ -237,22 +237,8 @@ function execute(name) {
|
||||
if (calc.isEditing) {
|
||||
calc.inputValue = calc.inputValue.startsWith('-') ? calc.inputValue.slice(1) : `-${calc.inputValue}`;
|
||||
} else {
|
||||
calc.push(calc.pop() * -1);
|
||||
calc.command('neg');
|
||||
}
|
||||
} else if (name === 'pow10') {
|
||||
pushEditingValueIfNeeded();
|
||||
const exponent = calc.stack[0];
|
||||
calc.remove(0);
|
||||
calc.push(10);
|
||||
calc.push(exponent);
|
||||
calc.command('pow');
|
||||
} else if (name === 'exp') {
|
||||
pushEditingValueIfNeeded();
|
||||
const exponent = calc.stack[0];
|
||||
calc.remove(0);
|
||||
calc.push(Math.E);
|
||||
calc.push(exponent);
|
||||
calc.command('pow');
|
||||
} else {
|
||||
pushEditingValueIfNeeded();
|
||||
calc.command(name);
|
||||
|
||||
+13
-1
@@ -49,6 +49,18 @@ class RpnCalculator {
|
||||
aliases: ['^', 'y^x'],
|
||||
execute: (calc, a, b) => Math.pow(a, b),
|
||||
},
|
||||
pow10: {
|
||||
category: 'Arithmetic',
|
||||
argCount: 1,
|
||||
aliases: ['10^x'],
|
||||
execute: (calc, a) => Math.pow(10, a),
|
||||
},
|
||||
exp: {
|
||||
category: 'Arithmetic',
|
||||
argCount: 1,
|
||||
aliases: ['e^x'],
|
||||
execute: (calc, a) => Math.exp(a),
|
||||
},
|
||||
root: {
|
||||
category: 'Arithmetic',
|
||||
argCount: 2,
|
||||
@@ -195,7 +207,7 @@ class RpnCalculator {
|
||||
static getOperationsByCategory() {
|
||||
return {
|
||||
Stack: ['dup', 'drop', 'swap', 'clear', 'enter'],
|
||||
Arithmetic: ['add', 'sub', 'mul', 'div', 'mod', 'pow', 'root', 'sqr', 'neg', 'sqrt', 'recip', 'log', 'ln'],
|
||||
Arithmetic: ['add', 'sub', 'mul', 'div', 'mod', 'pow', 'pow10', 'exp', 'root', 'sqr', 'neg', 'sqrt', 'recip', 'log', 'ln'],
|
||||
Trigonometry: ['sin', 'cos', 'tan', 'asin', 'acos', 'atan'],
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user