feat: add root command and fix calc-02 exponent shortcuts

This commit is contained in:
2026-05-15 23:05:43 +02:00
parent cb45efff43
commit b45cfe8091
4 changed files with 16 additions and 6 deletions
+6 -4
View File
@@ -7,7 +7,7 @@ A browser-friendly RPN calculator built around a small, generic JavaScript API.
This project provides:
- a reusable JavaScript RPN engine in `src/rpn-calculator.js`
- a browser demo in `samples/dev/`
- browser demos in `samples/dev/` and `samples/calc-02/`
- a command system centralized in a single operation dictionary
- a small public API focused on stack operations and generic command dispatch
@@ -24,7 +24,7 @@ The main class is `RpnCalculator`.
- `samples/calc-01/index.js`: demo UI and keyboard logic
- `samples/calc-02/index.html`: new responsive HP48GX-style demo entry point
- `samples/calc-02/index.css`: new responsive demo styles
- `samples/calc-02/index.js`: new demo UI and keyboard logic
- `samples/calc-02/index.js`: responsive HP48GX-style demo UI and keyboard logic
- `samples/calc-XX/`: placeholder name for future demo variants
## Public API
@@ -110,6 +110,7 @@ calc.command('e');
- `div` alias: `/`
- `mod` alias: `%`
- `pow` aliases: `^`, `y^x`
- `root` aliases: `y√x`, `yroot`, `nroot`
- `sqr`
- `neg`
- `sqrt` alias: `sqrt(x)`
@@ -134,6 +135,7 @@ calc.command('e');
- `sqrt` accepts alias `sqrt(x)`
- `recip` accepts alias `1/x`
- `div` and `recip` throw `Division by zero` when needed
- `root` computes the y-th root as `x^(1/y)` and throws `Invalid input for root` for invalid inputs
- `sqrt` throws `Invalid input for sqrt` for negative values
- `asin` and `acos` throw explicit domain errors outside `[-1, 1]`
- `log` throws `Invalid input for log` for values `<= 0`
@@ -270,8 +272,8 @@ It keeps the calculator screen focused and updates the visible stack window as t
## Calc 02 demo
`samples/calc-02/` is a new responsive HP48GX-inspired demo.
It adapts its layout to the browser window and switches between the supplied portrait and landscape arrangements.
`samples/calc-02/` is a responsive HP48GX-inspired demo.
It adapts its layout to the browser window, supports portrait and landscape arrangements, and includes the `y√x` root operation.
## Exports