2.7 KiB
2.7 KiB
Project rules — RPN Virtual Calculator
- Build a browser-friendly RPN calculator as a JavaScript class, preferably in a single file.
- 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), andcommand(name, ...args). - Expose
inputValueas a string andisEditingas a boolean. - Constructor options:
maxSize(default2048)base(default10)angleMode(degdefault; alsoradandgrad)enabledCommands
- Available constants:
pi,e. - Supported operations must be centralized in one dictionary containing at least:
argCountcategoryaliases
- Allowed categories are limited to:
Stack,Arithmetic, andTrigonometry.
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
modis the percentage operator:a b % => (a * b) / 100sqrt,asin,acos,log, andlnmust throw clear, explicit domain errorslogusesMath.log10lnusesMath.log- Trigonometric functions must support
deg,rad, andgrad - In the browser demo, degrees are the default angle mode
inputValuemust remain a string to preserve future hexadecimal input support
Demo rules
- The browser demo lives under
samples/dev/ samples/dev/index.htmlis the demo entry pagesamples/dev/index.csscontains the calculator visual themesamples/dev/index.jscontains demo-side presentation helpers and UI logic- The demo UI must expose:
- a stack display
- a main display
- a visible angle mode indicator
- an angle mode selector for
deg,rad, andgrad
- The demo may present user-facing labels such as
+,−,×,÷,y^x,1/x, andx²while still using English command identifiers internally - The example HTML must group buttons by
Stack,Arithmetic, andTrigonometry - The example HTML must call
command(...)for actions - Keyboard support in the demo should remain consistent with the displayed help text
File references
samples/dev/index.htmlreferencessrc/rpn-calculator.jsas the calculator engine used by the demo- Keep the demo aligned with the public calculator API exposed by
src/rpn-calculator.js
Maintenance
- Keep this file updated after each project change using the provided editing tools.
- When changing the demo UI or calculator API, update these rules so they continue to match the current project behavior.