"Pretty Calculator" memorandum

Rev.2

Sorry, no detailed manuals are included, this is just a memo.
 


Important notice

I wrote this program for my fun, I am not responsible for any accidents by this program. Never use at critical calculations.
 
 

License

This program is covered by the GNU General Public License.
 
 

Installation

First please delete the previous version of 'Pretty Calc' if you have. This program requires 'MathLib' floating-point library (you can get from http://www.probe.net/~rhuebner/mathlib.html). If you haven't installed yet, please install it also. 'MathLib.c' and 'MathLib.h' are also required for recompiling.
 
PCalc.prc required (calculator itself)
Constant-PCal.pdb optional (examples of scientific constants)
Program-PCal.pdb optional (examples of programs)

 

Tips

* Push UP/DOWN key to recall last 5 expressions in the buffer.
* Tap the answer field to insert the answer.
* Push [P] button to run the last run program.
 
 

Functions and operators
 
Trigonometric functions sin cos tan asin acos atan
Hyperbolic functions sinh cosh tanh asinh acosh atanh
Exponential/logarithmic functions exp log ln
Square root functions sqrt
Miscellaneous functions ceil floor abs rint
Operators +  -  *  /  ^  (  )
Signs +  -

 

Precedence and associativity
 
precedence associativity
add/sub (+, -) ->
mul/div (*, /) ->
sign (+, -) <-
power (O) <-
function <-
parenthesis x
number x

[Note]
Numbers can include its sign, the expression like "0---3" is acceptable.
ex.) 0---3  ==  0 -(operator) -(sign) -3(number)  =  -3

Notice the associativity of power operator (right to left).
ex.) 3^3^3 == 3^(3^3) ~= 7.63 x 10^12

Notice the precedence between powers and functions.
ex.) sin 10^2 + cos 10^2 == (sin 10)^2 + (cos 10)^2 = 1.
 
 

Variables and constants

Variables and constants are referred with "$" character. The last answer is stored to $ANS, even if the answer is not a number (sometimes an answer is INF or NaN). Variables are $MEM1 ... $MEM9.
 
 

Programs

Programs are now available on PrettyCalc ver. 2.00. You can use the programs for routine and complex calculations. Don't expect too much, conditional jumps and subroutines are not implemented.
 
 

Syntax

Very simple, put commands in order. "#" character indicates start of comment. Null lines are also comment.
 
 

Commands
 
Command Description
@SETEXPR "..." Set an expression into the expression field.
@EVAL Evaluate the expression on the expression field and store its answer to $ANS.
@DISP "..." Display a string on the answer field.
@INPEXPR Prompt a user to input an expression in the answer field.
@STMEM n (n = 1 ... 9) Store $ANS to $MEMn.

 

Program examples

The followings are examples of programs, included in 'Program-PCal.pdb'.

Calculate area of circle.

Title:
? Circle area

Program:
# Get circle area.
@SETEXPR ""
@DISP "R=?"
@INPEXPR
@EVAL
@SETEXPR "PI*$ANS^2"
@EVAL
 

Calculate length of vector.

Title:
? Length of vector

Program:
# Length of vector.
@DISP "X = ?"
@SETEXPR "" @INPEXPR
@EVAL @STMEM 7
@DISP "Y = ?"
@SETEXPR "" @INPEXPR
@EVAL @STMEM 8
@DISP "Z = ?"
@SETEXPR "" @INPEXPR
@EVAL @STMEM 9
@SETEXPR "sqrt ($MEM7^2+$MEM8^2+$MEM9^2)"
@EVAL
 

Calculate roots of quadratic equation.

Title:
? Roots of quadratic eq.

Program:
# Quadratic formula.
@DISP "ax^2 + bx + c = 0 : a = ?"
@SETEXPR "" @INPEXPR
@EVAL @STMEM 7
@DISP "ax^2 + bx + c = 0 : b = ?"
@SETEXPR "" @INPEXPR
@EVAL @STMEM 8
@DISP "ax^2 + bx + c = 0 : c = ?"
@SETEXPR "" @INPEXPR
@EVAL @STMEM 9
@SETEXPR "sqrt ($MEM8^2-4*$MEM7*$MEM9)"
@EVAL @STMEM 9
@SETEXPR "(-$MEM8-$MEM9) / (2*$MEM7)"
@EVAL @STMEM 9
@SETEXPR "(-$MEM8+$MEM9) / (2*$MEM7)"
@EVAL @STMEM 8
@DISP "x1,x2 -> M8,9"

[Note] The answers are inaccurate if a*c << 1. See "Numerical Recipes".
 

Convert $ANS to decimal notation (D.DDD...)

Title:
-> DEC

Program:
# Decimalize $ANS.
@STMEM 9
@SETEXPR "floor $MEM9"
@EVAL
@STMEM 7
@SETEXPR "floor(($MEM9-$MEM7)*100+1e-12)"
@EVAL
@STMEM 8
@SETEXPR "(($MEM9-$MEM7)*100-$MEM8)*100"
@EVAL
@STMEM 9
@SETEXPR "$MEM7+$MEM8/60+$MEM9/3600"
@EVAL

[Note] Don't use for a negative number.
 

Convert $ANS to 60-based notation (D.MMSSS...)

Title:
-> D.MS

Program:
# Sexagesimalize $ANS.
@STMEM 9
@SETEXPR "floor $MEM9"
@EVAL
@STMEM 7
@SETEXPR "floor(($MEM9-$MEM7)*60+1e-12)"
@EVAL
@STMEM 8
@SETEXPR "((($MEM9-$MEM7)*60)-$MEM8)*60"
@EVAL
@STMEM 9
@SETEXPR "$MEM7+$MEM8/100+$MEM9/10000"
@EVAL

[Note] Don't use for a negative number.