stacniac

Stacniac Manual

Stacniac is an RPN calculator.
Enter numbers by typing them in and then hitting return or enter.
Enter commands by typing them in; the commands are described below.
The four basic operations are supported immediately: type the number and press +, -, * or /.

Commands
Examples
Programming
Programming Examples

Commands

(TOS refers to the top of the stack; NOS refers to the next on the stack.)
:         defines a new command (refer to the programming section)
!         deletes a command (refer to the programming section)
about     shows the about box
abs       absolute value of TOS
add       adds TOS and NOS (use + for immediate add)
and       converts TOS and NOS to integers and bitwise ands them
acos      arc cosine of TOS in radians
asin      arc sine of TOS in radians
atan      arc tangent of TOS in radians
clr       clears the stack
cos       cosine of TOS (TOS in radians)
cub       cubes TOS
cbrt      cube root of TOS
d2r       converts TOS from degrees to radians
div       divides NOS by TOS (use / for immediate divide)
dn        pops and discards NOS
drop      pops and discards TOS
dup       duplicates TOS
dd        duplicates TOS below NOS
e         pushes e (2.7182818284590452354)
eq        pushes 1.0 if TOS is equal to NOS; pushes -1.0 otherwise
exp       e raised to TOS
fmtc      switches display format to currency
fmtd      switches format to decimal
fmte      switches format to engineering
fmth      switches format to hexadecimal (note that fractions are ignored)
gt        pushes 1.0 if TOS is greater than NOS; pushes -1.0 otherwise
help      displays help window
inv       converts TOS to an integer and bitwise inverts it
log       natural logarithm of TOS
lt        pushes 1.0 if TOS is less than NOS; pushes -1.0 otherwise
mul       multiplies TOS by NOS (use * for immediate multiply)
neg       negates TOS
or        converts TOS and NOS to integers and bitwise ors them
pi        pushes pi (3.14159265358979323846)
pop       pops and discards TOS
pow       raises NOS to TOS power
r2d       converts TOS from radians to degrees
rcp       reciprocal of TOS
rem       remainder from dividing NOS by TOS
rd        rotates down the top three items on the stack
rt        TOS root of NOS
ru        rotates up the top three items on the stack
rnd       rounds TOS to an integer
sfmtc     set the display format for currency
sfmte     set the display format for engineering (exponential)
sfmts     set the display format for engineering (standard)
sgn       sign of TOS
show      shows a list of the current custom commands
sin       sine of TOS (TOS in radians)
sqr       squares TOS
sqrt      square root of TOS
sub       subtracts NOS from TOS (use - for immediate subtract)
swap      swaps TOS and NOS
tan       tangent of TOS (TOS in radians)
xor       converts TOS and NOS to integers and bitwise exclusive ors them

In addition, the following may be used when defining new commands (refer to the programming section)
?         pops TOS and if > 0 then skips the next command
%         pops TOS and if > 0 then terminates current command normally
$         pops TOS and if > 0 then terminates current command as a failure
		

[top]


Examples

Add Two Numbers

  • type in the first number
  • press enter
  • type in the second number
  • press +

Pythagoras's Theorem

  • type in the length of one side and press enter
  • type in sqr and press enter
  • type in the length of the second side and press enter
  • type in sqr and press enter
  • press + (or type add and press enter)
  • type in sqrt and press enter

Balance your checkbook

  • type in fmtc and press enter (sets currency format)
  • type in your balance and press enter
  • for each check type in the amount and press -
  • for each deposit type in the amount and press +
  • when done, type in clr and press enter (to clear all data)

Compute flight time to Alpha Centauri

  • type in fmte and press enter (sets engineering format)
  • type in distance to Alpha Centauri (4.3 light years) and press enter
  • type in the speed of the starship (36500 mph, solar escape velocity) and press enter
  • type in the conversion factor (0.44704 mph -> m/s) and press * (speed in m/s)
  • type in speed of light (299792458 m/s) and press / (speed in c)
  • press / (or type div and press enter)
  • if desired, you can type in fmtd and press enter to see the result in decimal format

[top]


Programming

Stacniac has limited programmability.
Complex computations are better done with a spreadsheet or a general-purpose programming language, but for that odd function that you need, this can be very useful.
If you've programmed a stack-based language (e.g. Forth) before, programming Stacniac will be straightforward. If you haven't, it will seem very strange and awkward until you gain some experience.

A new command is defined by typing in a space-delimited definition string consisting of:
  • : (the colon character)
  • the name of the new command
  • the number of stack entries required (used to validate the stack state)
  • a list of commands

You can embed numeric literals in the command definition and they will be pushed onto the stack.
You can embed ? in the command definition; it will pop TOS and, if > 0, skip the next command in the list.
You can embed % in the command definition; it will pop TOS and, if > 0, terminate the command normally.
You can embed $ in the command definition; it will pop TOS and, if > 0, terminate the command as a failure (i.e. it will beep).


Commands can be deleted by typing in a space-delimited deletion string consisting of:
  • ! (the exclamation point character)
  • the name of the command to be deleted

Commands are persistent - i.e. once you define a command, Stacniac remembers it until you explicitly delete it. Commands that you enter are stored in Stacniac's preferences file.
On Mac OS X, preferences are stored in ~/Library/Preferences/org.ghostwood.stc.prefs
On other platforms, preferences are stored in ~/.stacniac_prefs/prefs

[top]


Programming Examples

Alias a command

To alias div to d, you could enter
: d 2 div


Pythagoras's Theorem

To program a new command to compute the hypotenuse of a right triangle, you could enter
: py 2 sqr swap sqr add sqrt


Factorial

To program a new command to compute the factorial of a number, you could enter
: fact 1 1 eq dn % dup 1 sub fact mul

[top]


Send comments, questions, suggestions, bug reports to stc@ghostwood.org

logo logo