docs: reorganize project rules and README
This commit is contained in:
+38
-14
@@ -1,20 +1,44 @@
|
|||||||
# Project rules — RPN Virtual Calculator
|
# Project rules — RPN Virtual Calculator
|
||||||
|
|
||||||
- Build a browser-friendly RPN calculator as a JavaScript class, preferably in a single file.
|
- Build a browser-friendly RPN calculator as a JavaScript class, preferably in a single file.
|
||||||
- Constructor options: `maxSize` (default 2048), `base` (default 10), `angleMode` (`deg` default; also `rad` and `grad`), `enabledCommands`.
|
|
||||||
- Available constants: `pi`, `e`.
|
|
||||||
- Public API is generic only: `push`, `pop`, `clear`, `swap(index1, index2)`, `remove(index)`, `edit(index)`, `isValidIndex(index)`, `input(command)`, and `command(name, ...args)`.
|
|
||||||
- Expose `inputValue` as a string and `isEditing` as a boolean.
|
|
||||||
- Supported operations are centralized in one dictionary with `argCount`, category, and aliases.
|
|
||||||
- Categories are limited to `Stack`, `Arithmetic`, and `Trigonometry`.
|
|
||||||
- Current commands: `add`, `sub`, `mul`, `div`, `mod`, `pow`, `sqr`, `neg`, `sqrt`, `recip`, `sin`, `cos`, `tan`, `asin`, `acos`, `atan`, `log`, `ln`, `dup`, `drop`, `swap`, `clear`, `enter`.
|
|
||||||
- Aliases: `+`, `-`, `*`, `/`, `%`, `^`, `y^x`, `1/x`.
|
|
||||||
- `mod` is the percentage operator: `a b % => (a * b) / 100`.
|
|
||||||
- `sqrt`, `asin`, `acos`, `log`, and `ln` must throw clear, explicit domain errors.
|
|
||||||
- `log` uses `Math.log10`; `ln` uses `Math.log`.
|
|
||||||
- Trig functions use degrees in the demo; `sin`, `cos`, `tan` convert to radians, inverse trig returns degrees.
|
|
||||||
- `inputValue` stays a string to keep hexadecimal input possible later.
|
|
||||||
- Example HTML must group buttons by `Stack`, `Arithmetic`, and `Trigonometry`, and call `command(...)`.
|
|
||||||
- Keep code names, categories, and API identifiers in English.
|
- Keep code names, categories, and API identifiers in English.
|
||||||
|
- Use only read-only / generic public API methods: `push`, `pop`, `clear`, `swap(index1, index2)`, `remove(index)`, `edit(index)`, `isValidIndex(index)`, `input(command)`, and `command(name, ...args)`.
|
||||||
|
- Expose `inputValue` as a string and `isEditing` as a boolean.
|
||||||
|
- Constructor options:
|
||||||
|
- `maxSize` (default `2048`)
|
||||||
|
- `base` (default `10`)
|
||||||
|
- `angleMode` (`deg` default; also `rad` and `grad`)
|
||||||
|
- `enabledCommands`
|
||||||
|
- Available constants: `pi`, `e`.
|
||||||
|
- Supported operations must be centralized in one dictionary containing at least:
|
||||||
|
- `argCount`
|
||||||
|
- `category`
|
||||||
|
- `aliases`
|
||||||
|
- Allowed categories are limited to: `Stack`, `Arithmetic`, and `Trigonometry`.
|
||||||
|
|
||||||
|
## Supported commands
|
||||||
|
|
||||||
|
- Current commands:
|
||||||
|
- `add`, `sub`, `mul`, `div`, `mod`, `pow`, `sqr`, `neg`, `sqrt`, `recip`,
|
||||||
|
`sin`, `cos`, `tan`, `asin`, `acos`, `atan`, `log`, `ln`,
|
||||||
|
`dup`, `drop`, `swap`, `clear`, `enter`
|
||||||
|
- Aliases:
|
||||||
|
- `+`, `-`, `*`, `/`, `%`, `^`, `y^x`, `1/x`
|
||||||
|
|
||||||
|
## Behavior rules
|
||||||
|
|
||||||
|
- `mod` is the percentage operator: `a b % => (a * b) / 100`
|
||||||
|
- `sqrt`, `asin`, `acos`, `log`, and `ln` must throw clear, explicit domain errors
|
||||||
|
- `log` uses `Math.log10`
|
||||||
|
- `ln` uses `Math.log`
|
||||||
|
- Trigonometric functions use degrees in the demo:
|
||||||
|
- `sin`, `cos`, `tan` convert degrees to radians
|
||||||
|
- inverse trig functions return degrees
|
||||||
|
- `inputValue` must remain a string to preserve future hexadecimal input support
|
||||||
|
- The example HTML must group buttons by `Stack`, `Arithmetic`, and `Trigonometry`
|
||||||
|
- The example HTML must call `command(...)` for actions
|
||||||
|
|
||||||
|
## Maintenance
|
||||||
|
|
||||||
- Keep this file updated after each project change using the provided editing tools.
|
- Keep this file updated after each project change using the provided editing tools.
|
||||||
|
|
||||||
|
|||||||
@@ -1,123 +1,45 @@
|
|||||||
# RPN Virtual Calculator
|
# RPN Virtual Calculator
|
||||||
|
|
||||||
A browser-friendly RPN calculator implemented as a single JavaScript class, with a simple API and an example HTML interface.
|
A browser-friendly RPN calculator built around a small, generic JavaScript API.
|
||||||
|
|
||||||
## Overview
|
## Goal
|
||||||
|
|
||||||
The project includes:
|
This project defines a reusable RPN calculator engine with:
|
||||||
|
|
||||||
|
- a simple stack-based public API
|
||||||
|
- configurable numeric and UI behavior
|
||||||
|
- centralized command metadata
|
||||||
|
- a browser demo that uses the same public API as any consumer code
|
||||||
|
|
||||||
|
## Package contents
|
||||||
- `rpn-calculator.js`: calculator engine
|
- `rpn-calculator.js`: calculator engine
|
||||||
- `rpn-example.html`: browser demo
|
- `rpn-example.html`: example browser interface
|
||||||
|
|
||||||
## Highlights
|
## Main features
|
||||||
|
- Single JavaScript class
|
||||||
- Self-contained JavaScript class
|
- Configurable stack size (`maxSize`, default: `2048`)
|
||||||
- Configurable stack size (`maxSize`, default: 2048)
|
- Configurable numeric base (`base`, default: `10`)
|
||||||
- Configurable numeric base (`base`, default: 10)
|
|
||||||
- Configurable angle mode (`angleMode`, default: `deg`)
|
- Configurable angle mode (`angleMode`, default: `deg`)
|
||||||
- Optional command enabling via `enabledCommands`
|
- Optional command filtering through `enabledCommands`
|
||||||
- Generic public API centered on `push`, `pop`, `clear`, `swap`, `remove`, `edit`, `isValidIndex`, `input`, and `command`
|
- Generic public API centered on:
|
||||||
- `inputValue` stays a string to keep hexadecimal input possible later
|
- `push`
|
||||||
- `isEditing` tracks typed input mode
|
- `pop`
|
||||||
- Operations are centralized with `argCount`, category, and aliases
|
|
||||||
- Categories are limited to `Stack`, `Arithmetic`, and `Trigonometry`
|
|
||||||
- Clear domain errors for invalid inputs
|
|
||||||
- Degree-based trig demo in the example HTML
|
|
||||||
|
|
||||||
## Quick start
|
|
||||||
|
|
||||||
### In the browser
|
|
||||||
|
|
||||||
```html
|
|
||||||
<script src="rpn-calculator.js"></script>
|
|
||||||
<script>
|
|
||||||
const calc = new RpnCalculator();
|
|
||||||
calc.input('1');
|
|
||||||
calc.input('2');
|
|
||||||
calc.command('enter');
|
|
||||||
calc.command('add');
|
|
||||||
console.log(calc.stack);
|
|
||||||
</script>
|
|
||||||
```
|
|
||||||
|
|
||||||
### With options
|
|
||||||
|
|
||||||
```js
|
|
||||||
const calc = new RpnCalculator({
|
|
||||||
maxSize: 1024,
|
|
||||||
base: 10,
|
|
||||||
angleMode: 'deg',
|
|
||||||
enabledCommands: ['add', 'sub', 'mul', 'div', 'enter', 'clear'],
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
## Public API
|
|
||||||
|
|
||||||
### Properties
|
|
||||||
|
|
||||||
- `stack`: current stack, with the top item at index `0`
|
|
||||||
- `inputValue`: input text as a string
|
|
||||||
- `isEditing`: whether input is currently being edited
|
|
||||||
|
|
||||||
### Generic methods
|
|
||||||
|
|
||||||
- `push(value)`
|
|
||||||
- `pop()`
|
|
||||||
- `clear()`
|
|
||||||
- `swap(index1, index2)`
|
|
||||||
- `remove(index)`
|
|
||||||
- `edit(index)`
|
|
||||||
- `isValidIndex(index)`
|
|
||||||
- `input(command)`
|
|
||||||
- `command(name, ...args)`
|
|
||||||
|
|
||||||
## Supported commands
|
|
||||||
|
|
||||||
### Stack
|
|
||||||
|
|
||||||
- `enter`
|
|
||||||
- `dup`
|
|
||||||
- `drop`
|
|
||||||
- `swap`
|
|
||||||
- `clear`
|
- `clear`
|
||||||
|
- `swap(index1, index2)`
|
||||||
|
- `remove(index)`
|
||||||
|
- `edit(index)`
|
||||||
|
- `isValidIndex(index)`
|
||||||
|
- `input(command)`
|
||||||
|
- `command(name, ...args)`
|
||||||
|
- `inputValue` is kept as a string to preserve future input formats
|
||||||
|
- `isEditing` is exposed as a boolean state
|
||||||
|
- All supported commands are described in one centralized dictionary
|
||||||
|
- Supported categories are limited to:
|
||||||
|
- `Stack`
|
||||||
|
- `Arithmetic`
|
||||||
|
- `Trigonometry`
|
||||||
|
|
||||||
### Arithmetic
|
## Basic usage
|
||||||
|
|
||||||
- `add` / `+`
|
### In a browser
|
||||||
- `sub` / `-`
|
|
||||||
- `mul` / `*`
|
|
||||||
- `div` / `/`
|
|
||||||
- `mod` / `%`
|
|
||||||
- `pow` / `^` / `y^x`
|
|
||||||
- `sqr`
|
|
||||||
- `neg`
|
|
||||||
- `sqrt`
|
|
||||||
- `recip` / `1/x`
|
|
||||||
- `log`
|
|
||||||
- `ln`
|
|
||||||
|
|
||||||
### Trigonometry
|
|
||||||
|
|
||||||
- `sin`
|
|
||||||
- `cos`
|
|
||||||
- `tan`
|
|
||||||
- `asin`
|
|
||||||
- `acos`
|
|
||||||
- `atan`
|
|
||||||
|
|
||||||
## Important behavior
|
|
||||||
|
|
||||||
- `%` behaves as the RPN percentage operator: `a b % => (a * b) / 100`
|
|
||||||
- `sqrt`, `asin`, `acos`, `log`, and `ln` throw clear errors for invalid inputs
|
|
||||||
- `log` uses `Math.log10`
|
|
||||||
- `ln` uses `Math.log`
|
|
||||||
- `sin`, `cos`, and `tan` convert degrees to radians in the default demo
|
|
||||||
- `asin`, `acos`, and `atan` return degrees in `deg` mode
|
|
||||||
|
|
||||||
## Example HTML
|
|
||||||
|
|
||||||
The example UI groups buttons into `Stack`, `Arithmetic`, and `Trigonometry` sections, and calls `command(...)` to execute operations.
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
To be completed according to your project.
|
|
||||||
|
|||||||
Reference in New Issue
Block a user