84451d0abcae85ab0bffc5f01a715f52c2d43cdb
RPN Virtual Calculator
A browser-friendly RPN calculator built around a small, generic JavaScript API.
Goal
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
RPN Virtual Calculator
A browser-friendly RPN calculator built around a small, generic JavaScript API.
Goal
This project provides a reusable Reverse Polish Notation (RPN) calculator engine with:
- a simple stack-based public API
- configurable numeric behavior
- centralized command metadata
- browser demos that use the same public API as any consumer code
Project structure
src/rpn-calculator.js: calculator enginesamples/dev/index.html: browser demosamples/hp48/index.html: HP48-style browser demo
Main features
- Single JavaScript class:
RpnCalculator - Configurable stack size via
maxSize(default:2048) - Configurable numeric base via
base(default:10) - Configurable angle mode via
angleMode:deg(default)radgrad
- Optional command filtering through
enabledCommands - Public API limited to generic methods:
push(value)pop()clear()swap(index1, index2)remove(index)edit(index)isValidIndex(index)input(command)command(name, ...args)
inputValueis always stored as a stringisEditingis exposed as a boolean- Supported operations are centralized in one dictionary with metadata such as:
argCountcategoryaliases
- Supported categories are limited to:
StackArithmeticTrigonometry
Available constants
pie
Supported commands
Arithmetic
add(+)sub(-)mul(*)div(/)mod(%)pow(^,y^x)sqrnegsqrtrecip(1/x)logln
Trigonometry
sincostanasinacosatan
Stack
dupdropswapclearenter
Behavior rules
modis a percentage operator:a b % => (a * b) / 100
logusesMath.log10lnusesMath.logsqrt,asin,acos,log, andlnthrow explicit domain errors on invalid input- Trigonometric behavior depends on
angleMode - In degree mode:
sin,cos,tanconvert degrees to radians internallyasin,acos,atanreturn degrees
inputValueremains a string to preserve future support for formats such as hexadecimal input
Basic usage
In a browser
rpn-calculator.js: calculator enginerpn-example.html: example browser interface
Main features
- Single JavaScript class
- Configurable stack size (
maxSize, default:2048) - Configurable numeric base (
base, default:10) - Configurable angle mode (
angleMode, default:deg) - Optional command filtering through
enabledCommands - Generic public API centered on:
pushpop
clearswap(index1, index2)remove(index)edit(index)isValidIndex(index)input(command)command(name, ...args)
inputValueis kept as a string to preserve future input formatsisEditingis exposed as a boolean state- All supported commands are described in one centralized dictionary
- Supported categories are limited to:
StackArithmeticTrigonometry
Basic usage
In a browser
Description
Languages
JavaScript
82.6%
Shell
17.4%