#153: alternative fn help, changed example

This commit is contained in:
Louis Rubet 2017-06-26 17:45:18 +02:00
parent 0c72e692dc
commit 8648d69554
3 changed files with 145 additions and 143 deletions

256
MANUAL.md
View file

@ -77,194 +77,194 @@ exit chs sqrt % ceil conj fix >= xor
|keyword|description| |keyword|description|
|-|-| |-|-|
|nop | no operation |`nop` | no operation
|help | (or h or ?) this help message |`help\|h\|?` | this help message
|quit | (or q or exit) quit software |`quit\|q\|exit` | quit software
|version | show rpn version |`version` | show rpn version
|uname | show rpn complete identification string |`uname` | show rpn complete identification string
|history| see commands history |`history`| see commands history
### usual operations - real and complex ### usual operations - real and complex
|keyword|description| |keyword|description|
|-|-| |-|-|
|+| addition |`+`| addition
|-| substraction |`-`| substraction
|neg| (or chs) negation |`neg\|chs`| negation
|*| multiplication |`*`| multiplication
|/| division |`/`| division
|inv| inverse |`inv`| inverse
|^| (or pow) power |`^\|pow`| power
|sqrt| square root |`sqrt`| square root
|sq| (or sqr) square |`sq\|sqr`| square
|abs| absolute value for a number or sqrt(re*re+im*im) for a complex |`abs`| absolute value for a number or `sqrt(re*re+im*im)` for a complex
|dec| decimal representation |`dec`| decimal representation
|hex| hexadecimal representation |`hex`| hexadecimal representation
|sign| sign of a real, unary vector in the same direction for a complex |`sign`| sign of a real, unary vector in the same direction for a complex
### operations on reals ### operations on reals
|keyword|description| |keyword|description|
|-|-| |-|-|
|%| purcent |`%`| purcent
|%CH| inverse purcent |`%CH`| inverse purcent
|mod| modulo |`mod`| modulo
|fact| n! for integer n or Gamma(x+1) for fractional x |`fact`| n! for integer n or Gamma(x+1) for fractional x
|mant| mantissa of a real number |`mant`| mantissa of a real number
|xpon| exponant of a real number |`xpon`| exponant of a real number
|floor| largest number <= |`floor`| largest number <=
|ceil| smallest number >= |`ceil`| smallest number >=
|ip| integer part |`ip`| integer part
|fp| fractional part |`fp`| fractional part
|min| min of 2 real numbers |`min`| min of 2 real numbers
|max| max of 2 real numbers |`max`| max of 2 real numbers
### operations on complexes ### operations on complexes
|keyword|description| |keyword|description|
|-|-| |-|-|
|re| complex real part |`re`| complex real part
|im| complex imaginary part |`im`| complex imaginary part
|conj| complex conjugate |`conj`| complex conjugate
|arg| complex argument in radians |`arg`| complex argument in radians
|r->p| rectangular to polar coordinates |`r->p`| rectangular to polar coordinates
|p->r| polar to rectangular coordinates |`p->r`| polar to rectangular coordinates
|r->c| transform 2 reals in a complex |`r->c`| transform 2 reals in a complex
|c->r| transform a complex in 2 reals |`c->r`| transform a complex in 2 reals
### mode ### mode
|keyword|description| |keyword|description|
|-|-| |-|-|
|std| standard floating numbers representation. ex: std |`std`| standard floating numbers representation. ex: `std`
|fix| fixed point representation. ex: 6 fix |`fix`| fixed point representation. ex: `6 fix`
|sci| scientific floating point representation. ex: 20 sci |`sci`| scientific floating point representation. ex: `20 sci`
|prec| get float precision in bits when first stack is not a number, set float precision in bits when first stack entry is a number. ex: ```256 prec``` |`prec`| get float precision in bits when first stack is not a number, set float precision in bits when first stack entry is a number. ex: `256 prec`
|round| set float rounding mode. Authoerized values are: ```["nearest", "toward zero", "toward +inf", "toward -inf", "away from zero"] round```. ex: ```"nearest" round``` |`round`| set float rounding mode. Authorized values are: ["nearest" \| "toward zero" \| "toward +inf" \| "toward -inf" \| "away from zero"] round`. ex: `"nearest" round`
|default | set float representation and precision to default |`default` | set float representation and precision to default
|type | show type of stack first entry |`type` | show type of stack first entry
### test ### test
|keyword|description| |keyword|description|
|-|-| |-|-|
|>| binary operator > |`>`| binary operator >
|>=| binary operator >= |`>=`| binary operator >=
|<| binary operator < |`<`| binary operator <
|<=| binary operator <= |`<=`| binary operator <=
|!=| binary operator != (different) |`!=`| binary operator != (different)
|==| binary operator == (equal) |`==`| binary operator == (equal)
|and| boolean operator and |`and`| boolean operator and
|or| boolean operator or |`or`| boolean operator or
|xor| boolean operator xor |`xor`| boolean operator xor
|not| boolean operator not |`not`| boolean operator not
|same| boolean operator same (equal) |`same`| boolean operator same (equal)
### stack ### stack
|keyword|description| |keyword|description|
|-|-| |-|-|
|swap| swap 2 first stack entries |`swap`| swap 2 first stack entries
|drop| drop first stack entry |`drop`| drop first stack entry
|drop2| drop 2 first stack entries |`drop2`| drop 2 first stack entries
|dropn| drop n first stack entries |`dropn`| drop n first stack entries
|erase| drop all stack entries |`erase`| drop all stack entries
|rot| rotate 3 first stack entries |`rot`| rotate 3 first stack entries
|dup| duplicate first stack entry |`dup`| duplicate first stack entry
|dup2| duplicate 2 first stack entries |`dup2`| duplicate 2 first stack entries
|dupn| duplicate n first stack entries |`dupn`| duplicate n first stack entries
|pick| push a copy of the given stack level onto the stack |`pick`| push a copy of the given stack level onto the stack
|depth| give stack depth |`depth`| give stack depth
|roll| move a stack entry to the top of the stack |`roll`| move a stack entry to the top of the stack
|rolld| move the element on top of the stack to a higher stack position |`rolld`| move the element on top of the stack to a higher stack position
|over| push a copy of the element in stack level 2 onto the stack |`over`| push a copy of the element in stack level 2 onto the stack
### string ### string
|keyword|description| |keyword|description|
|-|-| |-|-|
|->str| convert an object into a string |`->str`| convert an object into a string
|str->| convert a string into an object |`str->`| convert a string into an object
|chr| convert ASCII character code in stack level 1 into a string |`chr`| convert ASCII character code in stack level 1 into a string
|num| return ASCII code of the first character of the string in stack level 1 as a real number |`num`| return ASCII code of the first character of the string in stack level 1 as a real number
|size| return the length of the string |`size`| return the length of the string
|pos| seach for the string in level 1 within the string in level 2 |`pos`| seach for the string in level 1 within the string in level 2
|sub| return a substring of the string in level 3 |`sub`| return a substring of the string in level 3
### branch ### branch
|keyword|description| |keyword|description|
|-|-| |-|-|
|if| if (test-instruction) then (true-instructions) else (false-instructions) end |`if`| if (test-instruction) then (true-instructions) else (false-instructions) end
|then| used with if |`then`| used with if
|else| used with if |`else`| used with if
|end| used with various branch instructions |`end`| used with various branch instructions
|ift| similar to if-then-end: (test-instruction) (true-instruction) ift" |`ift`| similar to if-then-end: (test-instruction) (true-instruction) ift"
|ifte| similar to if-then-else-end: (test-instruction) (true-instruction) (false-instruction) ifte" |`ifte`| similar to if-then-else-end: (test-instruction) (true-instruction) (false-instruction) ifte"
|start| (start) (end) start (instructions) next|(step) step |`start`| (start) (end) start (instructions) next|(step) step
|for| (start) (end) for (variable) (instructions) next|(step) step |`for`| (start) (end) for (variable) (instructions) next|(step) step
|next| used with start and for |`next`| used with start and for
|step| used with start and for |`step`| used with start and for
|do| do (instructions) until (condition) end |`do`| do (instructions) until (condition) end
|until | (or unti) used with do |`until\|unti` | used with do
|while| (or whil) while (test-instruction) repeat (loop-instructions) end |`while\|whil`| while (test-instruction) repeat (loop-instructions) end
|repeat| (or repea) used with while |`repeat\|repea`| used with while
### store ### store
|keyword|description| |keyword|description|
|-|-| |-|-|
|sto| store a variable. ex: ```1 'name' sto``` |`sto`| store a variable. ex: ```1 'name' sto```
|rcl| recall a variable. ex: ```'name' rcl``` |`rcl`| recall a variable. ex: ```'name' rcl```
|purge| delete a variable. ex: ```'name' purge``` |`purge`| delete a variable. ex: ```'name' purge```
|vars| list all variables |`vars`| list all variables
|clusr| erase all variables |`clusr`| erase all variables
|edit| edit a variable content |`edit`| edit a variable content
|sto+| add to a stored variable. ex: 1 'name' sto+ 'name' 2 sto+ |`sto+`| add to a stored variable. ex: 1 'name' sto+ 'name' 2 sto+
|sto-| substract to a stored variable. ex: 1 'name' sto- 'name' 2 sto- |`sto-`| substract to a stored variable. ex: 1 'name' sto- 'name' 2 sto-
|sto*| multiply a stored variable. ex: 3 'name' sto* 'name' 2 sto* |`sto*`| multiply a stored variable. ex: 3 'name' sto* 'name' 2 sto*
|sto/| divide a stored variable. ex: 3 'name' sto/ 'name' 2 sto/ |`sto/`| divide a stored variable. ex: 3 'name' sto/ 'name' 2 sto/
|sneg| negate a variable. ex: 'name' sneg |`sneg`| negate a variable. ex: 'name' sneg
|sinv| inverse a variable. ex: 1 'name' sinv |`sinv`| inverse a variable. ex: 1 'name' sinv
### program ### program
|keyword|description| |keyword|description|
|-|-| |-|-|
|eval| evaluate (run) a program, or recall a variable. ex: ```'my_prog' eval``` |`eval`| evaluate (run) a program, or recall a variable. ex: ```'my_prog' eval```
|->| load program local variables. ex: ```<< -> n m << 0 n m for i i + next >> >>``` |`->`| load program local variables. ex: ```<< -> n m << 0 n m for i i + next >> >>```
### trig on reals and complexes ### trig on reals and complexes
|keyword|description| |keyword|description|
|-|-| |-|-|
|pi| pi constant |`pi`| pi constant
|sin| sinus |`sin`| sinus
|asin| arg sinus |`asin`| arg sinus
|cos| cosinus |`cos`| cosinus
|acos| arg cosinus |`acos`| arg cosinus
|tan| tangent |`tan`| tangent
|atan| arg tangent |`atan`| arg tangent
|d->r| convert degrees to radians |`d->r`| convert degrees to radians
|r->d| convert radians to degrees |`r->d`| convert radians to degrees
### logs on reals and complexes ### logs on reals and complexes
|keyword|description| |keyword|description|
|-|-| |-|-|
|e| Euler constant |`e`| Euler constant
|ln| (or log) logarithm base e |`ln\|log`| logarithm base e
|exp| exponential |`exp`| exponential
|log10| logarithm base 10 |`log10`| logarithm base 10
|alog10| (or exp10) exponential base 10 |`alog10\|exp10`| exponential base 10
|log2| logarithm base 2 |`log2`| logarithm base 2
|alog2| (or exp2) exponential base 2 |`alog2\|exp2`| exponential base 2
|sinh| hyperbolic sine |`sinh`| hyperbolic sine
|asinh| inverse hyperbolic sine |`asinh`| inverse hyperbolic sine
|cosh| hyperbolic cosine |`cosh`| hyperbolic cosine
|acosh| inverse hyperbolic cosine |`acosh`| inverse hyperbolic cosine
|tanh| hyperbolic tangent |`tanh`| hyperbolic tangent
|atanh| inverse hyperbolic tangent |`atanh`| inverse hyperbolic tangent
### default ### default

View file

@ -10,9 +10,10 @@ rpn> 1 2 + 2 sqrt
### with arbitrary precision ### with arbitrary precision
``` ```
rpn> 256 prec 200 std rpn> 256 prec
rpn> pi 3 * 4 / cos rpn> pi
-0.707106781186547524400844362104849039284835937688474036588339868995366239(...) 3.1415926535897932384626433832795028841971693993751058209749445923078164062862
rpn>
``` ```
### providing variables, programs ### providing variables, programs

View file

@ -9,11 +9,12 @@ program::keyword_t program::s_keywords[] =
//GENERAL //GENERAL
{ cmd_undef, "", NULL, "\nGENERAL"}, { cmd_undef, "", NULL, "\nGENERAL"},
{ cmd_keyword, "nop", &program::nop, "no operation"}, { cmd_keyword, "nop", &program::nop, "no operation"},
{ cmd_keyword, "?", &program::help, "" }, { cmd_keyword, "help", &program::help, "this help message" },
{ cmd_keyword, "h", &program::help, "" }, { cmd_keyword, "h", &program::help, "" },
{ cmd_keyword, "help", &program::help, "(or h or ?) this help message" }, { cmd_keyword, "?", &program::help, "" },
{ cmd_keyword, "q", &program::good_bye, "" },
{ cmd_keyword, "quit", &program::good_bye, "quit software" },
{ cmd_keyword, "q", &program::good_bye, "" }, { cmd_keyword, "q", &program::good_bye, "" },
{ cmd_keyword, "quit", &program::good_bye, "(or q or exit) quit software" },
{ cmd_keyword, "exit", &program::good_bye, "" }, { cmd_keyword, "exit", &program::good_bye, "" },
{ cmd_keyword, "test", &program::test, "" }, //not seen by user { cmd_keyword, "test", &program::test, "" }, //not seen by user
{ cmd_keyword, "version", &program::rpn_version, "show rpn version" }, { cmd_keyword, "version", &program::rpn_version, "show rpn version" },
@ -24,15 +25,15 @@ program::keyword_t program::s_keywords[] =
{ cmd_undef, "", NULL, "\nUSUAL OPERATIONS ON REALS AND COMPLEXES"}, { cmd_undef, "", NULL, "\nUSUAL OPERATIONS ON REALS AND COMPLEXES"},
{ cmd_keyword, "+", &program::plus, "addition" }, { cmd_keyword, "+", &program::plus, "addition" },
{ cmd_keyword, "-", &program::minus, "substraction" }, { cmd_keyword, "-", &program::minus, "substraction" },
{ cmd_keyword, "chs", &program::neg , "(or neg) negation" }, { cmd_keyword, "chs", &program::neg , "negation" },
{ cmd_keyword, "neg", &program::neg , "" }, { cmd_keyword, "neg", &program::neg , "" },
{ cmd_keyword, "*", &program::mul, "multiplication" }, { cmd_keyword, "*", &program::mul, "multiplication" },
{ cmd_keyword, "/", &program::div, "division" }, { cmd_keyword, "/", &program::div, "division" },
{ cmd_keyword, "inv", &program::inv, "inverse" }, { cmd_keyword, "inv", &program::inv, "inverse" },
{ cmd_keyword, "^", &program::power, "(or pow) power" }, { cmd_keyword, "^", &program::power, "power" },
{ cmd_keyword, "pow", &program::power, "" }, { cmd_keyword, "pow", &program::power, "" },
{ cmd_keyword, "sqrt", &program::squareroot, "square root" }, { cmd_keyword, "sqrt", &program::squareroot, "square root" },
{ cmd_keyword, "sq", &program::square, "(or sqr) square" }, { cmd_keyword, "sq", &program::square, "square" },
{ cmd_keyword, "sqr", &program::square, "" }, { cmd_keyword, "sqr", &program::square, "" },
{ cmd_keyword, "abs", &program::rpn_abs, "absolute value" }, { cmd_keyword, "abs", &program::rpn_abs, "absolute value" },
{ cmd_keyword, "dec", &program::dec, "decimal representation" }, { cmd_keyword, "dec", &program::dec, "decimal representation" },
@ -130,11 +131,11 @@ program::keyword_t program::s_keywords[] =
{ cmd_keyword, "ift", &program::rpn_ift, "similar to if-then-end, <test-instruction> <true-instruction> ift" }, { cmd_keyword, "ift", &program::rpn_ift, "similar to if-then-end, <test-instruction> <true-instruction> ift" },
{ cmd_keyword, "ifte",&program::rpn_ifte, "similar to if-then-else-end, <test-instruction> <true-instruction> <false-instruction> ifte" }, { cmd_keyword, "ifte",&program::rpn_ifte, "similar to if-then-else-end, <test-instruction> <true-instruction> <false-instruction> ifte" },
{ cmd_branch, "do", (program_fn_t)&program::rpn_do, "do <instructions> until <condition> end" }, { cmd_branch, "do", (program_fn_t)&program::rpn_do, "do <instructions> until <condition> end" },
{ cmd_branch, "until", (program_fn_t)&program::rpn_until, "(or unti) used with do" }, { cmd_branch, "until", (program_fn_t)&program::rpn_until, "used with do" },
{ cmd_branch, "unti", (program_fn_t)&program::rpn_until, "" }, { cmd_branch, "unti", (program_fn_t)&program::rpn_until, "" },
{ cmd_branch, "while", (program_fn_t)&program::rpn_while, "(or whil) while <test-instruction> repeat <loop-instructions> end" }, { cmd_branch, "while", (program_fn_t)&program::rpn_while, "while <test-instruction> repeat <loop-instructions> end" },
{ cmd_branch, "whil", (program_fn_t)&program::rpn_while, "" }, { cmd_branch, "whil", (program_fn_t)&program::rpn_while, "" },
{ cmd_branch, "repeat", (program_fn_t)&program::rpn_repeat, "(or repea) used with while" }, { cmd_branch, "repeat", (program_fn_t)&program::rpn_repeat, "used with while" },
{ cmd_branch, "repea", (program_fn_t)&program::rpn_repeat, "" }, { cmd_branch, "repea", (program_fn_t)&program::rpn_repeat, "" },
//STORE //STORE
@ -172,14 +173,14 @@ program::keyword_t program::s_keywords[] =
//LOGS ON REALS AND COMPLEXES //LOGS ON REALS AND COMPLEXES
{ cmd_undef, "", NULL, "\nLOGS ON REALS AND COMPLEXES"}, { cmd_undef, "", NULL, "\nLOGS ON REALS AND COMPLEXES"},
{ cmd_keyword, "e", &program::rpn_e, "Euler constant" }, { cmd_keyword, "e", &program::rpn_e, "Euler constant" },
{ cmd_keyword, "ln", &program::rpn_ln, "(or log) logarithm base e" }, { cmd_keyword, "ln", &program::rpn_ln, "logarithm base e" },
{ cmd_keyword, "log", &program::rpn_ln, "" }, { cmd_keyword, "log", &program::rpn_ln, "" },
{ cmd_keyword, "exp", &program::rpn_exp, "exponential" }, { cmd_keyword, "exp", &program::rpn_exp, "exponential" },
{ cmd_keyword, "log10", &program::rpn_log10, "logarithm base 10" }, { cmd_keyword, "log10", &program::rpn_log10, "logarithm base 10" },
{ cmd_keyword, "alog10", &program::rpn_alog10, "(or exp10) exponential base 10" }, { cmd_keyword, "alog10", &program::rpn_alog10, "exponential base 10" },
{ cmd_keyword, "exp10", &program::rpn_alog10, "" }, { cmd_keyword, "exp10", &program::rpn_alog10, "" },
{ cmd_keyword, "log2", &program::rpn_log2, "logarithm base 2" }, { cmd_keyword, "log2", &program::rpn_log2, "logarithm base 2" },
{ cmd_keyword, "alog2", &program::rpn_alog2, "(or exp2) exponential base 2" }, { cmd_keyword, "alog2", &program::rpn_alog2, "exponential base 2" },
{ cmd_keyword, "exp2", &program::rpn_alog2, "" }, { cmd_keyword, "exp2", &program::rpn_alog2, "" },
{ cmd_keyword, "sinh", &program::rpn_sinh, "hyperbolic sine" }, { cmd_keyword, "sinh", &program::rpn_sinh, "hyperbolic sine" },
{ cmd_keyword, "asinh", &program::rpn_asinh, "inverse hyperbolic sine" }, { cmd_keyword, "asinh", &program::rpn_asinh, "inverse hyperbolic sine" },