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

View file

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

View file

@ -9,11 +9,12 @@ program::keyword_t program::s_keywords[] =
//GENERAL
{ cmd_undef, "", NULL, "\nGENERAL"},
{ 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, "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, "quit", &program::good_bye, "(or q or exit) quit software" },
{ cmd_keyword, "exit", &program::good_bye, "" },
{ cmd_keyword, "test", &program::test, "" }, //not seen by user
{ 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_keyword, "+", &program::plus, "addition" },
{ 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, "*", &program::mul, "multiplication" },
{ cmd_keyword, "/", &program::div, "division" },
{ 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, "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, "abs", &program::rpn_abs, "absolute value" },
{ 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, "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, "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, "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, "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, "" },
//STORE
@ -172,14 +173,14 @@ program::keyword_t program::s_keywords[] =
//LOGS ON REALS AND COMPLEXES
{ cmd_undef, "", NULL, "\nLOGS ON REALS AND COMPLEXES"},
{ 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, "exp", &program::rpn_exp, "exponential" },
{ 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, "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, "sinh", &program::rpn_sinh, "hyperbolic sine" },
{ cmd_keyword, "asinh", &program::rpn_asinh, "inverse hyperbolic sine" },