mirror of
https://github.com/louisrubet/rpn
synced 2024-12-27 09:58:56 +01:00
#165: renamed all commands to rpn_command() format
This commit is contained in:
parent
3195142eb1
commit
61102de4fe
13 changed files with 270 additions and 271 deletions
|
@ -144,7 +144,7 @@ rpn>
|
|||
|`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`
|
||||
|`prec`| set float precision in bits. 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
|
||||
|
|
191
src/program.cpp
191
src/program.cpp
|
@ -8,48 +8,48 @@ program::keyword_t program::s_keywords[] =
|
|||
{
|
||||
//GENERAL
|
||||
{ cmd_undef, "", NULL, "\nGENERAL"},
|
||||
{ cmd_keyword, "nop", &program::nop, "no operation"},
|
||||
{ cmd_keyword, "help", &program::help, "this help message" },
|
||||
{ cmd_keyword, "h", &program::help, "" },
|
||||
{ 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, "exit", &program::good_bye, "" },
|
||||
{ cmd_keyword, "test", &program::test, "" }, //not seen by user
|
||||
{ cmd_keyword, "nop", &program::rpn_nop, "no operation"},
|
||||
{ cmd_keyword, "help", &program::rpn_help, "this help message" },
|
||||
{ cmd_keyword, "h", &program::rpn_help, "" },
|
||||
{ cmd_keyword, "?", &program::rpn_help, "" },
|
||||
{ cmd_keyword, "q", &program::rpn_good_bye, "" },
|
||||
{ cmd_keyword, "quit", &program::rpn_good_bye, "quit software" },
|
||||
{ cmd_keyword, "q", &program::rpn_good_bye, "" },
|
||||
{ cmd_keyword, "exit", &program::rpn_good_bye, "" },
|
||||
{ cmd_keyword, "test", &program::rpn_test, "" }, //not seen by user
|
||||
{ cmd_keyword, "version", &program::rpn_version, "show rpn version" },
|
||||
{ cmd_keyword, "uname", &program::rpn_uname, "show rpn complete identification string" },
|
||||
{ cmd_keyword, "history", &program::rpn_history, "see commands history" },
|
||||
|
||||
//USUAL OPERATIONS ON REALS AND COMPLEXEXE
|
||||
{ cmd_undef, "", NULL, "\nUSUAL OPERATIONS ON REALS AND COMPLEXES"},
|
||||
{ cmd_keyword, "+", &program::plus, "addition" },
|
||||
{ cmd_keyword, "-", &program::minus, "substraction" },
|
||||
{ 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, "power" },
|
||||
{ cmd_keyword, "pow", &program::power, "" },
|
||||
{ cmd_keyword, "sqrt", &program::squareroot, "square root" },
|
||||
{ cmd_keyword, "sq", &program::square, "square" },
|
||||
{ cmd_keyword, "sqr", &program::square, "" },
|
||||
{ cmd_keyword, "+", &program::rpn_plus, "addition" },
|
||||
{ cmd_keyword, "-", &program::rpn_minus, "substraction" },
|
||||
{ cmd_keyword, "chs", &program::rpn_neg , "negation" },
|
||||
{ cmd_keyword, "neg", &program::rpn_neg , "" },
|
||||
{ cmd_keyword, "*", &program::rpn_mul, "multiplication" },
|
||||
{ cmd_keyword, "/", &program::rpn_div, "division" },
|
||||
{ cmd_keyword, "inv", &program::rpn_inv, "inverse" },
|
||||
{ cmd_keyword, "^", &program::rpn_power, "power" },
|
||||
{ cmd_keyword, "pow", &program::rpn_power, "" },
|
||||
{ cmd_keyword, "sqrt", &program::rpn_squareroot, "rpn_square root" },
|
||||
{ cmd_keyword, "sq", &program::rpn_square, "rpn_square" },
|
||||
{ cmd_keyword, "sqr", &program::rpn_square, "" },
|
||||
{ cmd_keyword, "abs", &program::rpn_abs, "absolute value" },
|
||||
{ cmd_keyword, "dec", &program::dec, "decimal representation" },
|
||||
{ cmd_keyword, "hex", &program::hex, "hexadecimal representation" },
|
||||
{ cmd_keyword, "bin", &program::bin, "decimal representation" },
|
||||
{ cmd_keyword, "base", &program::base, "arbitrary base representation" },
|
||||
{ cmd_keyword, "sign", &program::sign, "1 if number at stack level 1 is > 0, 0 if == 0, -1 if <= 0" },
|
||||
{ cmd_keyword, "dec", &program::rpn_dec, "decimal representation" },
|
||||
{ cmd_keyword, "hex", &program::rpn_hex, "hexadecimal representation" },
|
||||
{ cmd_keyword, "bin", &program::rpn_bin, "decimal representation" },
|
||||
{ cmd_keyword, "base", &program::rpn_base, "arbitrary base representation" },
|
||||
{ cmd_keyword, "sign", &program::rpn_sign, "1 if number at stack level 1 is > 0, 0 if == 0, -1 if <= 0" },
|
||||
|
||||
//OPERATIONS ON REALS
|
||||
{ cmd_undef, "", NULL, "\nOPERATIONS ON REALS"},
|
||||
{ cmd_keyword, "%", &program::purcent, "purcent" },
|
||||
{ cmd_keyword, "%CH", &program::purcentCH, "inverse purcent" },
|
||||
{ cmd_keyword, "mod", &program::modulo, "modulo" },
|
||||
{ cmd_keyword, "fact", &program::fact, "n! for integer n or Gamma(x+1) for fractional x" },
|
||||
{ cmd_keyword, "mant", &program::mant, "mantissa of a real number" },
|
||||
{ cmd_keyword, "xpon", &program::xpon, "exponant of a real number" },
|
||||
{ cmd_keyword, "%", &program::rpn_purcent, "purcent" },
|
||||
{ cmd_keyword, "%CH", &program::rpn_purcentCH, "inverse purcent" },
|
||||
{ cmd_keyword, "mod", &program::rpn_modulo, "modulo" },
|
||||
{ cmd_keyword, "fact", &program::rpn_fact, "n! for integer n or Gamma(x+1) for fractional x" },
|
||||
{ cmd_keyword, "mant", &program::rpn_mant, "mantissa of a real number" },
|
||||
{ cmd_keyword, "xpon", &program::rpn_xpon, "exponant of a real number" },
|
||||
{ cmd_keyword, "floor", &program::rpn_floor, "largest number <=" },
|
||||
{ cmd_keyword, "ceil", &program::rpn_ceil, "smallest number >=" },
|
||||
{ cmd_keyword, "ip", &program::rpn_ip, "integer part" },
|
||||
|
@ -59,66 +59,65 @@ program::keyword_t program::s_keywords[] =
|
|||
|
||||
//nOPERATIONS ON COMPLEXES
|
||||
{ cmd_undef, "", NULL, "\nOPERATIONS ON COMPLEXES"},
|
||||
{ cmd_keyword, "re", &program::re, "complex real part" },
|
||||
{ cmd_keyword, "im", &program::im, "complex imaginary part" },
|
||||
{ cmd_keyword, "conj", &program::conj, "complex conjugate" },
|
||||
{ cmd_keyword, "arg", &program::arg, "complex argument in radians" },
|
||||
{ cmd_keyword, "c->r", &program::c2r, "transform a complex in 2 reals" },
|
||||
{ cmd_keyword, "r->c", &program::r2c, "transform 2 reals in a complex" },
|
||||
{ cmd_keyword, "p->r", &program::p2r, "cartesian to polar" },
|
||||
{ cmd_keyword, "r->p", &program::r2p, "polar to cartesian" },
|
||||
{ cmd_keyword, "re", &program::rpn_re, "complex real part" },
|
||||
{ cmd_keyword, "im", &program::rpn_im, "complex imaginary part" },
|
||||
{ cmd_keyword, "conj", &program::rpn_conj, "complex conjugate" },
|
||||
{ cmd_keyword, "arg", &program::rpn_arg, "complex argument in radians" },
|
||||
{ cmd_keyword, "c->r", &program::rpn_c2r, "transform a complex in 2 reals" },
|
||||
{ cmd_keyword, "r->c", &program::rpn_r2c, "transform 2 reals in a complex" },
|
||||
{ cmd_keyword, "p->r", &program::rpn_p2r, "cartesian to polar" },
|
||||
{ cmd_keyword, "r->p", &program::rpn_r2p, "polar to cartesian" },
|
||||
|
||||
//MODE
|
||||
{ cmd_undef, "", NULL, "\nMODE"},
|
||||
{ cmd_keyword, "std", &program::std, "standard floating numbers representation. ex: std" },
|
||||
{ cmd_keyword, "fix", &program::fix, "fixed point representation. ex: 6 fix" },
|
||||
{ cmd_keyword, "sci", &program::sci, "scientific floating point representation. ex: 20 sci" },
|
||||
{ cmd_keyword, "prec", &program::precision, "get float precision in bits when first stack is not a number\n\t"
|
||||
"set float precision in bits when first stack entry is a number. ex: 256 prec" },
|
||||
{ cmd_keyword, "round", &program::round, "set float rounding mode.\n\tex: [\"nearest\", \"toward zero\", \"toward +inf\", \"toward -inf\", \"away from zero\"] round" },
|
||||
{ cmd_keyword, "std", &program::rpn_std, "standard floating numbers representation. ex: std" },
|
||||
{ cmd_keyword, "fix", &program::rpn_fix, "fixed point representation. ex: 6 fix" },
|
||||
{ cmd_keyword, "sci", &program::rpn_sci, "scientific floating point representation. ex: 20 sci" },
|
||||
{ cmd_keyword, "prec", &program::rpn_precision, "set float precision in bits. ex: 256 prec" },
|
||||
{ cmd_keyword, "round", &program::rpn_round, "set float rounding mode.\n\tex: [\"nearest\", \"toward zero\", \"toward +inf\", \"toward -inf\", \"away from zero\"] round" },
|
||||
{ cmd_keyword, "default", &program::rpn_default, "set float representation and precision to default" },
|
||||
{ cmd_keyword, "type", &program::type, "show type of stack first entry" },
|
||||
{ cmd_keyword, "type", &program::rpn_type, "show type of stack first entry" },
|
||||
|
||||
//TESTS
|
||||
{ cmd_undef, "", NULL, "\nTEST"},
|
||||
{ cmd_keyword, ">", &program::sup, "binary operator >" },
|
||||
{ cmd_keyword, ">=", &program::sup_eq, "binary operator >=" },
|
||||
{ cmd_keyword, "<", &program::inf, "binary operator <" },
|
||||
{ cmd_keyword, "<=", &program::inf_eq, "binary operator <=" },
|
||||
{ cmd_keyword, "!=", &program::diff, "binary operator != (different)" },
|
||||
{ cmd_keyword, "==", &program::eq , "binary operator == (equal)" },
|
||||
{ cmd_keyword, "and", &program::test_and , "boolean operator and" },
|
||||
{ cmd_keyword, "or", &program::test_or , "boolean operator or" },
|
||||
{ cmd_keyword, "xor", &program::test_xor , "boolean operator xor" },
|
||||
{ cmd_keyword, "not", &program::test_not , "boolean operator not" },
|
||||
{ cmd_keyword, "same", &program::same , "boolean operator same (equal)" },
|
||||
{ cmd_keyword, ">", &program::rpn_sup, "binary operator >" },
|
||||
{ cmd_keyword, ">=", &program::rpn_sup_eq, "binary operator >=" },
|
||||
{ cmd_keyword, "<", &program::rpn_inf, "binary operator <" },
|
||||
{ cmd_keyword, "<=", &program::rpn_inf_eq, "binary operator <=" },
|
||||
{ cmd_keyword, "!=", &program::rpn_diff, "binary operator != (different)" },
|
||||
{ cmd_keyword, "==", &program::rpn_eq , "binary operator == (equal)" },
|
||||
{ cmd_keyword, "and", &program::rpn_test_and , "boolean operator and" },
|
||||
{ cmd_keyword, "or", &program::rpn_test_or , "boolean operator or" },
|
||||
{ cmd_keyword, "xor", &program::rpn_test_xor , "boolean operator xor" },
|
||||
{ cmd_keyword, "not", &program::rpn_test_not , "boolean operator not" },
|
||||
{ cmd_keyword, "same", &program::rpn_same , "boolean operator same (equal)" },
|
||||
|
||||
//STACK
|
||||
{ cmd_undef, "", NULL, "\nSTACK"},
|
||||
{ cmd_keyword, "swap", &program::swap, "swap 2 first stack entries" },
|
||||
{ cmd_keyword, "drop", &program::drop, "drop first stack entry" },
|
||||
{ cmd_keyword, "drop2", &program::drop2, "drop 2 first stack entries" },
|
||||
{ cmd_keyword, "dropn", &program::dropn, "drop n first stack entries" },
|
||||
{ cmd_keyword, "erase", &program::erase, "drop all stack entries" },
|
||||
{ cmd_keyword, "rot", &program::rot, "rotate 3 first stack entries" },
|
||||
{ cmd_keyword, "dup", &program::dup, "duplicate first stack entry" },
|
||||
{ cmd_keyword, "dup2", &program::dup2, "duplicate 2 first stack entries" },
|
||||
{ cmd_keyword, "dupn", &program::dupn, "duplicate n first stack entries" },
|
||||
{ cmd_keyword, "pick", &program::pick, "push a copy of the given stack level onto the stack" },
|
||||
{ cmd_keyword, "depth", &program::depth, "give stack depth" },
|
||||
{ cmd_keyword, "roll", &program::roll, "move a stack entry to the top of the stack" },
|
||||
{ cmd_keyword, "rolld", &program::rolld, "move the element on top of the stack to a higher stack position" },
|
||||
{ cmd_keyword, "over", &program::over, "push a copy of the element in stack level 2 onto the stack" },
|
||||
{ cmd_keyword, "swap", &program::rpn_swap, "swap 2 first stack entries" },
|
||||
{ cmd_keyword, "drop", &program::rpn_drop, "drop first stack entry" },
|
||||
{ cmd_keyword, "drop2", &program::rpn_drop2, "drop 2 first stack entries" },
|
||||
{ cmd_keyword, "dropn", &program::rpn_dropn, "drop n first stack entries" },
|
||||
{ cmd_keyword, "erase", &program::rpn_erase, "drop all stack entries" },
|
||||
{ cmd_keyword, "rot", &program::rpn_rot, "rotate 3 first stack entries" },
|
||||
{ cmd_keyword, "dup", &program::rpn_dup, "duplicate first stack entry" },
|
||||
{ cmd_keyword, "dup2", &program::rpn_dup2, "duplicate 2 first stack entries" },
|
||||
{ cmd_keyword, "dupn", &program::rpn_dupn, "duplicate n first stack entries" },
|
||||
{ cmd_keyword, "pick", &program::rpn_pick, "push a copy of the given stack level onto the stack" },
|
||||
{ cmd_keyword, "depth", &program::rpn_depth, "give stack depth" },
|
||||
{ cmd_keyword, "roll", &program::rpn_roll, "move a stack entry to the top of the stack" },
|
||||
{ cmd_keyword, "rolld", &program::rpn_rolld, "move the element on top of the stack to a higher stack position" },
|
||||
{ cmd_keyword, "over", &program::rpn_over, "push a copy of the element in stack level 2 onto the stack" },
|
||||
|
||||
//STRING
|
||||
{ cmd_undef, "", NULL, "\nSTRING"},
|
||||
{ cmd_keyword, "->str", &program::instr, "convert an object into a string" },
|
||||
{ cmd_keyword, "str->", &program::strout, "convert a string into an object" },
|
||||
{ cmd_keyword, "chr", &program::chr, "convert ASCII character code in stack level 1 into a string" },
|
||||
{ cmd_keyword, "num", &program::num, "return ASCII code of the first character of the string in stack level 1 as a real number" },
|
||||
{ cmd_keyword, "size", &program::strsize, "return the length of the string" },
|
||||
{ cmd_keyword, "pos", &program::strpos, "seach for the string in level 1 within the string in level 2" },
|
||||
{ cmd_keyword, "sub", &program::strsub, "return a substring of the string in level 3" },
|
||||
{ cmd_keyword, "->str", &program::rpn_instr, "convert an object into a string" },
|
||||
{ cmd_keyword, "str->", &program::rpn_strout, "convert a string into an object" },
|
||||
{ cmd_keyword, "chr", &program::rpn_chr, "convert ASCII character code in stack level 1 into a string" },
|
||||
{ cmd_keyword, "num", &program::rpn_num, "return ASCII code of the first character of the string in stack level 1 as a real number" },
|
||||
{ cmd_keyword, "size", &program::rpn_strsize, "return the length of the string" },
|
||||
{ cmd_keyword, "pos", &program::rpn_strpos, "seach for the string in level 1 within the string in level 2" },
|
||||
{ cmd_keyword, "sub", &program::rpn_strsub, "return a substring of the string in level 3" },
|
||||
|
||||
//BRANCH
|
||||
{ cmd_undef, "", NULL, "\nBRANCH"},
|
||||
|
@ -142,35 +141,35 @@ program::keyword_t program::s_keywords[] =
|
|||
|
||||
//STORE
|
||||
{ cmd_undef, "", NULL, "\nSTORE"},
|
||||
{ cmd_keyword, "sto", &program::sto, "store a variable. ex: 1 'name' sto" },
|
||||
{ cmd_keyword, "rcl", &program::rcl, "recall a variable. ex: 'name' rcl" },
|
||||
{ cmd_keyword, "purge", &program::purge, "delete a variable. ex: 'name' purge" },
|
||||
{ cmd_keyword, "vars", &program::vars, "list all variables" },
|
||||
{ cmd_keyword, "clusr", &program::clusr, "erase all variables" },
|
||||
{ cmd_keyword, "edit", &program::edit, "edit a variable content" },
|
||||
{ cmd_keyword, "sto+", &program::stoadd, "add to a stored variable. ex: 1 'name' sto+ 'name' 2 sto+" },
|
||||
{ cmd_keyword, "sto-", &program::stosub, "substract to a stored variable. ex: 1 'name' sto- 'name' 2 sto-" },
|
||||
{ cmd_keyword, "sto*", &program::stomul, "multiply a stored variable. ex: 3 'name' sto* 'name' 2 sto*" },
|
||||
{ cmd_keyword, "sto/", &program::stodiv, "divide a stored variable. ex: 3 'name' sto/ 'name' 2 sto/" },
|
||||
{ cmd_keyword, "sneg", &program::stoneg, "negate a variable. ex: 'name' sneg" },
|
||||
{ cmd_keyword, "sinv", &program::stoinv, "inverse a variable. ex: 1 'name' sinv" },
|
||||
{ cmd_keyword, "sto", &program::rpn_sto, "store a variable. ex: 1 'name' sto" },
|
||||
{ cmd_keyword, "rcl", &program::rpn_rcl, "recall a variable. ex: 'name' rcl" },
|
||||
{ cmd_keyword, "purge", &program::rpn_purge, "delete a variable. ex: 'name' purge" },
|
||||
{ cmd_keyword, "vars", &program::rpn_vars, "list all variables" },
|
||||
{ cmd_keyword, "clusr", &program::rpn_clusr, "erase all variables" },
|
||||
{ cmd_keyword, "edit", &program::rpn_edit, "edit a variable content" },
|
||||
{ cmd_keyword, "sto+", &program::rpn_stoadd, "add to a stored variable. ex: 1 'name' sto+ 'name' 2 sto+" },
|
||||
{ cmd_keyword, "sto-", &program::rpn_stosub, "substract to a stored variable. ex: 1 'name' sto- 'name' 2 sto-" },
|
||||
{ cmd_keyword, "sto*", &program::rpn_stomul, "multiply a stored variable. ex: 3 'name' sto* 'name' 2 sto*" },
|
||||
{ cmd_keyword, "sto/", &program::rpn_stodiv, "divide a stored variable. ex: 3 'name' sto/ 'name' 2 sto/" },
|
||||
{ cmd_keyword, "sneg", &program::rpn_stoneg, "negate a variable. ex: 'name' sneg" },
|
||||
{ cmd_keyword, "sinv", &program::rpn_stoinv, "inverse a variable. ex: 1 'name' sinv" },
|
||||
|
||||
//PROGRAM
|
||||
{ cmd_undef, "", NULL, "\nPROGRAM"},
|
||||
{ cmd_keyword, "eval", &program::eval, "evaluate (run) a program, or recall a variable. ex: 'my_prog' eval" },
|
||||
{ cmd_branch, "->", (program_fn_t)&program::inprog, "load program local variables. ex: << -> n m << 0 n m for i i + next >> >>" },
|
||||
{ cmd_keyword, "eval", &program::rpn_eval, "evaluate (run) a program, or recall a variable. ex: 'my_prog' eval" },
|
||||
{ cmd_branch, "->", (program_fn_t)&program::rpn_inprog, "load program local variables. ex: << -> n m << 0 n m for i i + next >> >>" },
|
||||
|
||||
//TRIG ON REALS AND COMPLEXES
|
||||
{ cmd_undef, "", NULL, "\nTRIG ON REALS AND COMPLEXES"},
|
||||
{ cmd_keyword, "pi", &program::pi, "pi constant" },
|
||||
{ cmd_keyword, "pi", &program::rpn_pi, "pi constant" },
|
||||
{ cmd_keyword, "sin", &program::rpn_sin, "sinus" },
|
||||
{ cmd_keyword, "asin", &program::rpn_asin, "arg sinus" },
|
||||
{ cmd_keyword, "cos", &program::rpn_cos , "cosinus" },
|
||||
{ cmd_keyword, "acos", &program::rpn_acos, "arg cosinus" },
|
||||
{ cmd_keyword, "tan", &program::rpn_tan, "tangent" },
|
||||
{ cmd_keyword, "atan", &program::rpn_atan, "arg tangent" },
|
||||
{ cmd_keyword, "d->r", &program::d2r, "convert degrees to radians" },
|
||||
{ cmd_keyword, "r->d", &program::r2d, "convert radians to degrees" },
|
||||
{ cmd_keyword, "d->r", &program::rpn_d2r, "convert degrees to radians" },
|
||||
{ cmd_keyword, "r->d", &program::rpn_r2d, "convert radians to degrees" },
|
||||
|
||||
//LOGS ON REALS AND COMPLEXES
|
||||
{ cmd_undef, "", NULL, "\nLOGS ON REALS AND COMPLEXES"},
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
void re()
|
||||
void rpn_re()
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_complex);
|
||||
|
@ -11,7 +11,7 @@ void re()
|
|||
_calc_stack.pop_back();
|
||||
}
|
||||
|
||||
void im()
|
||||
void rpn_im()
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_complex);
|
||||
|
@ -24,7 +24,7 @@ void im()
|
|||
_calc_stack.pop_back();
|
||||
}
|
||||
|
||||
void arg()
|
||||
void rpn_arg()
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_complex);
|
||||
|
@ -39,7 +39,7 @@ void arg()
|
|||
_calc_stack.pop_back();
|
||||
}
|
||||
|
||||
void conj()
|
||||
void rpn_conj()
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_complex);
|
||||
|
@ -48,7 +48,7 @@ void conj()
|
|||
CHECK_MPFR(mpfr_neg(cplx->im()->mpfr, cplx->im()->mpfr, floating_t::s_mpfr_rnd));
|
||||
}
|
||||
|
||||
void r2c()
|
||||
void rpn_r2c()
|
||||
{
|
||||
MIN_ARGUMENTS(2);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||
|
@ -65,7 +65,7 @@ void r2c()
|
|||
_calc_stack.pop_back(2);
|
||||
}
|
||||
|
||||
void c2r()
|
||||
void rpn_c2r()
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_complex);
|
||||
|
@ -81,27 +81,27 @@ void c2r()
|
|||
_calc_stack.pop_back();
|
||||
}
|
||||
|
||||
void r2p()
|
||||
void rpn_r2p()
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_complex);
|
||||
|
||||
dup();
|
||||
dup();
|
||||
arg();
|
||||
rpn_dup();
|
||||
rpn_dup();
|
||||
rpn_arg();
|
||||
|
||||
complex* cplx = (complex*)_stack->get_obj(1);
|
||||
CHECK_MPFR(mpfr_set(cplx->im()->mpfr, ((number*)_stack->back())->_value.mpfr, floating_t::s_mpfr_rnd));
|
||||
_stack->pop_back();
|
||||
|
||||
swap();
|
||||
rpn_swap();
|
||||
rpn_abs();
|
||||
cplx = (complex*)_stack->get_obj(1);
|
||||
CHECK_MPFR(mpfr_set(cplx->re()->mpfr, ((number*)_stack->back())->_value.mpfr, floating_t::s_mpfr_rnd));
|
||||
_stack->pop_back();
|
||||
}
|
||||
|
||||
void p2r()
|
||||
void rpn_p2r()
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_complex);
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
//
|
||||
void nop()
|
||||
void rpn_nop()
|
||||
{
|
||||
// nop
|
||||
}
|
||||
|
||||
void good_bye()
|
||||
void rpn_good_bye()
|
||||
{
|
||||
ERR_CONTEXT(ret_good_bye);
|
||||
}
|
||||
|
||||
void help()
|
||||
void rpn_help()
|
||||
{
|
||||
// software name
|
||||
printf("\n" ATTR_BOLD "%s" ATTR_OFF "\n", uname);
|
||||
|
@ -84,7 +84,7 @@ bool check_decimal_digits(double precision)
|
|||
return ret;
|
||||
}
|
||||
|
||||
void std()
|
||||
void rpn_std()
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||
|
@ -102,7 +102,7 @@ void std()
|
|||
ERR_CONTEXT(ret_out_of_range);
|
||||
}
|
||||
|
||||
void fix()
|
||||
void rpn_fix()
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||
|
@ -120,7 +120,7 @@ void fix()
|
|||
ERR_CONTEXT(ret_out_of_range);
|
||||
}
|
||||
|
||||
void sci()
|
||||
void rpn_sci()
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||
|
@ -167,7 +167,7 @@ void rpn_history()
|
|||
}
|
||||
}
|
||||
|
||||
void type()
|
||||
void rpn_type()
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
|
||||
|
@ -186,7 +186,7 @@ void rpn_default()
|
|||
program::apply_default();
|
||||
}
|
||||
|
||||
void precision()
|
||||
void rpn_precision()
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||
|
@ -210,7 +210,7 @@ void precision()
|
|||
ERR_CONTEXT(ret_out_of_range);
|
||||
}
|
||||
|
||||
void round()
|
||||
void rpn_round()
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_string);
|
||||
|
|
|
@ -17,7 +17,7 @@ void rpn_log10()
|
|||
number* ten = (number*)_stack->allocate_back(number::calc_size(), cmd_number);
|
||||
CHECK_MPFR(mpfr_set_d(ten->_value.mpfr, 10.0, floating_t::s_mpfr_rnd));
|
||||
rpn_ln();
|
||||
div();
|
||||
rpn_div();
|
||||
}
|
||||
else
|
||||
ERR_CONTEXT(ret_bad_operand_type);
|
||||
|
@ -33,7 +33,7 @@ void rpn_alog10()
|
|||
number* ten = (number*)_stack->allocate_back(number::calc_size(), cmd_number);
|
||||
CHECK_MPFR(mpfr_set_d(ten->_value.mpfr, 10.0, floating_t::s_mpfr_rnd));
|
||||
rpn_ln();
|
||||
mul();
|
||||
rpn_mul();
|
||||
rpn_exp();
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ void rpn_log2()
|
|||
number* two = (number*)_stack->allocate_back(number::calc_size(), cmd_number);
|
||||
CHECK_MPFR(mpfr_set_d(two->_value.mpfr, 2.0, floating_t::s_mpfr_rnd));
|
||||
rpn_ln();
|
||||
div();
|
||||
rpn_div();
|
||||
}
|
||||
else
|
||||
ERR_CONTEXT(ret_bad_operand_type);
|
||||
|
@ -66,7 +66,7 @@ void rpn_alog2()
|
|||
number* two = (number*)_stack->allocate_back(number::calc_size(), cmd_number);
|
||||
CHECK_MPFR(mpfr_set_d(two->_value.mpfr, 2.0, floating_t::s_mpfr_rnd));
|
||||
rpn_ln();
|
||||
mul();
|
||||
rpn_mul();
|
||||
rpn_exp();
|
||||
}
|
||||
}
|
||||
|
@ -201,13 +201,13 @@ void rpn_asinh()
|
|||
else if (_stack->get_type(0) == cmd_complex)
|
||||
{
|
||||
// asinh(z)=ln(z+sqrt(1+z*z))
|
||||
dup();
|
||||
square();
|
||||
rpn_dup();
|
||||
rpn_square();
|
||||
number* num = (number*)_stack->allocate_back(number::calc_size(), cmd_number);
|
||||
CHECK_MPFR(mpfr_set_d(num->_value.mpfr, 1.0, floating_t::s_mpfr_rnd));
|
||||
plus();
|
||||
squareroot();
|
||||
plus();
|
||||
rpn_plus();
|
||||
rpn_squareroot();
|
||||
rpn_plus();
|
||||
rpn_ln();
|
||||
}
|
||||
else
|
||||
|
@ -261,17 +261,17 @@ void rpn_acosh()
|
|||
else if (_stack->get_type(0) == cmd_complex)
|
||||
{
|
||||
// acosh(z)=ln(z+sqrt(z+1)sqrt(z-1))
|
||||
dup();
|
||||
rpn_dup();
|
||||
number* num = (number*)_stack->allocate_back(number::calc_size(), cmd_number);
|
||||
CHECK_MPFR(mpfr_set_d(num->_value.mpfr, 1.0, floating_t::s_mpfr_rnd));
|
||||
plus();
|
||||
dup();
|
||||
rpn_plus();
|
||||
rpn_dup();
|
||||
num = (number*)_stack->allocate_back(number::calc_size(), cmd_number);
|
||||
CHECK_MPFR(mpfr_set_d(num->_value.mpfr, 2.0, floating_t::s_mpfr_rnd));
|
||||
minus();
|
||||
mul();
|
||||
squareroot();
|
||||
plus();
|
||||
rpn_minus();
|
||||
rpn_mul();
|
||||
rpn_squareroot();
|
||||
rpn_plus();
|
||||
rpn_ln();
|
||||
}
|
||||
else
|
||||
|
@ -290,7 +290,7 @@ void rpn_tanh()
|
|||
else if (_stack->get_type(0) == cmd_complex)
|
||||
{
|
||||
// tanh(x+iy)=(tanh(x)+itan(y)) / (1 + itanh(x)tan(y))
|
||||
dup();
|
||||
rpn_dup();
|
||||
|
||||
floating_t* x = ((complex*)_stack->get_obj(1))->re();
|
||||
floating_t* y = ((complex*)_stack->get_obj(1))->im();
|
||||
|
@ -305,7 +305,7 @@ void rpn_tanh()
|
|||
CHECK_MPFR(mpfr_tan(y->mpfr, y->mpfr, floating_t::s_mpfr_rnd));
|
||||
CHECK_MPFR(mpfr_mul(y->mpfr, y->mpfr, x->mpfr, floating_t::s_mpfr_rnd));
|
||||
CHECK_MPFR(mpfr_set_d(x->mpfr, 1.0, floating_t::s_mpfr_rnd));
|
||||
div();
|
||||
rpn_div();
|
||||
}
|
||||
else
|
||||
ERR_CONTEXT(ret_bad_operand_type);
|
||||
|
@ -323,20 +323,20 @@ void rpn_atanh()
|
|||
else if (_stack->get_type(0) == cmd_complex)
|
||||
{
|
||||
// atanh(z)=0.5*ln((1+z)/(1-z))
|
||||
dup();
|
||||
rpn_dup();
|
||||
number* num = (number*)_stack->allocate_back(number::calc_size(), cmd_number);
|
||||
CHECK_MPFR(mpfr_set_d(num->_value.mpfr, 1.0, floating_t::s_mpfr_rnd));
|
||||
plus();
|
||||
swap();
|
||||
rpn_plus();
|
||||
rpn_swap();
|
||||
num = (number*)_stack->allocate_back(number::calc_size(), cmd_number);
|
||||
CHECK_MPFR(mpfr_set_d(num->_value.mpfr, 1.0, floating_t::s_mpfr_rnd));
|
||||
minus();
|
||||
neg();
|
||||
div();
|
||||
rpn_minus();
|
||||
rpn_neg();
|
||||
rpn_div();
|
||||
rpn_ln();
|
||||
num = (number*)_stack->allocate_back(number::calc_size(), cmd_number);
|
||||
CHECK_MPFR(mpfr_set_d(num->_value.mpfr, 0.5, floating_t::s_mpfr_rnd));
|
||||
mul();
|
||||
rpn_mul();
|
||||
}
|
||||
else
|
||||
ERR_CONTEXT(ret_bad_operand_type);
|
||||
|
|
|
@ -28,7 +28,7 @@ bool find_variable(string& variable, object*& obj, unsigned int& size)
|
|||
return found;
|
||||
}
|
||||
|
||||
void eval(void)
|
||||
void rpn_eval(void)
|
||||
{
|
||||
bool run_prog = false;
|
||||
string prog_text;
|
||||
|
@ -84,7 +84,7 @@ void eval(void)
|
|||
}
|
||||
|
||||
// carefull, this not a command but a branch
|
||||
int inprog(branch& myobj)
|
||||
int rpn_inprog(branch& myobj)
|
||||
{
|
||||
string context("->");// for showing errors
|
||||
int count_symbols = 0;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
void plus()
|
||||
void rpn_plus()
|
||||
{
|
||||
MIN_ARGUMENTS(2);
|
||||
|
||||
|
@ -46,7 +46,7 @@ void plus()
|
|||
// adding number+complex
|
||||
else if (_stack->get_type(0) == cmd_complex && _stack->get_type(1) == cmd_number)
|
||||
{
|
||||
swap();
|
||||
rpn_swap();
|
||||
number* right = (number*)_stack->pop_back();
|
||||
complex* left = (complex*)_stack->back();
|
||||
CHECK_MPFR(mpfr_add(left->re()->mpfr, left->re()->mpfr, right->_value.mpfr, floating_t::s_mpfr_rnd));
|
||||
|
@ -55,7 +55,7 @@ void plus()
|
|||
ERR_CONTEXT(ret_bad_operand_type);
|
||||
}
|
||||
|
||||
void minus()
|
||||
void rpn_minus()
|
||||
{
|
||||
MIN_ARGUMENTS(2);
|
||||
|
||||
|
@ -84,7 +84,7 @@ void minus()
|
|||
// substracting number-complex
|
||||
else if (_stack->get_type(0) == cmd_complex && _stack->get_type(1) == cmd_number)
|
||||
{
|
||||
swap();
|
||||
rpn_swap();
|
||||
number* right = (number*)_stack->pop_back();
|
||||
complex* left = (complex*)_stack->back();
|
||||
CHECK_MPFR(mpfr_sub(left->re()->mpfr, right->_value.mpfr, left->re()->mpfr, floating_t::s_mpfr_rnd));
|
||||
|
@ -93,7 +93,7 @@ void minus()
|
|||
ERR_CONTEXT(ret_bad_operand_type);
|
||||
}
|
||||
|
||||
void mul()
|
||||
void rpn_mul()
|
||||
{
|
||||
MIN_ARGUMENTS(2);
|
||||
|
||||
|
@ -139,7 +139,7 @@ void mul()
|
|||
// multiplying number*complex
|
||||
else if (_stack->get_type(0) == cmd_complex && _stack->get_type(1) == cmd_number)
|
||||
{
|
||||
swap();
|
||||
rpn_swap();
|
||||
number* right = (number*)_stack->pop_back();
|
||||
complex* left = (complex*)_stack->back();
|
||||
CHECK_MPFR(mpfr_mul(left->re()->mpfr, left->re()->mpfr, right->_value.mpfr, floating_t::s_mpfr_rnd));
|
||||
|
@ -185,7 +185,7 @@ void do_divide_complexes()
|
|||
_calc_stack.pop_back(4);
|
||||
}
|
||||
|
||||
void div()
|
||||
void rpn_div()
|
||||
{
|
||||
MIN_ARGUMENTS(2);
|
||||
|
||||
|
@ -232,7 +232,7 @@ void div()
|
|||
ERR_CONTEXT(ret_bad_operand_type);
|
||||
}
|
||||
|
||||
void neg()
|
||||
void rpn_neg()
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
|
||||
|
@ -251,7 +251,7 @@ void neg()
|
|||
ERR_CONTEXT(ret_bad_operand_type);
|
||||
}
|
||||
|
||||
void inv()
|
||||
void rpn_inv()
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
|
||||
|
@ -263,7 +263,7 @@ void inv()
|
|||
else if (_stack->get_type(0) == cmd_complex)
|
||||
{
|
||||
//1. duplicate
|
||||
dup();
|
||||
rpn_dup();
|
||||
//2. set complex level 2 to (1,0)
|
||||
complex* cplx = (complex*)_stack->get_obj(1);
|
||||
CHECK_MPFR(mpfr_set_ui(cplx->re()->mpfr, 1UL, floating_t::s_mpfr_rnd));
|
||||
|
@ -275,7 +275,7 @@ void inv()
|
|||
ERR_CONTEXT(ret_bad_operand_type);
|
||||
}
|
||||
|
||||
void purcent()
|
||||
void rpn_purcent()
|
||||
{
|
||||
MIN_ARGUMENTS(2);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||
|
@ -288,7 +288,7 @@ void purcent()
|
|||
CHECK_MPFR(mpfr_div_si(left->_value.mpfr, left->_value.mpfr, 100L, floating_t::s_mpfr_rnd));
|
||||
}
|
||||
|
||||
void purcentCH()
|
||||
void rpn_purcentCH()
|
||||
{
|
||||
MIN_ARGUMENTS(2);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||
|
@ -301,7 +301,7 @@ void purcentCH()
|
|||
CHECK_MPFR(mpfr_div(left->_value.mpfr, right->_value.mpfr, left->_value.mpfr, floating_t::s_mpfr_rnd));
|
||||
}
|
||||
|
||||
void power()
|
||||
void rpn_power()
|
||||
{
|
||||
MIN_ARGUMENTS(2);
|
||||
|
||||
|
@ -322,7 +322,7 @@ void power()
|
|||
|
||||
//switch complex to polar
|
||||
complex* cplx = (complex*)_stack->back();
|
||||
r2p();
|
||||
rpn_r2p();
|
||||
|
||||
//new abs=abs^exponent
|
||||
number* exponent = (number*)_calc_stack.back();
|
||||
|
@ -332,14 +332,14 @@ void power()
|
|||
CHECK_MPFR(mpfr_mul(cplx->im()->mpfr, cplx->im()->mpfr, exponent->_value.mpfr, floating_t::s_mpfr_rnd));
|
||||
|
||||
//back to cartesian
|
||||
p2r();
|
||||
rpn_p2r();
|
||||
_calc_stack.pop_back();
|
||||
}
|
||||
else
|
||||
ERR_CONTEXT(ret_bad_operand_type);
|
||||
}
|
||||
|
||||
void squareroot()
|
||||
void rpn_squareroot()
|
||||
{
|
||||
if (_stack->get_type(0) == cmd_number)
|
||||
{
|
||||
|
@ -351,13 +351,13 @@ void squareroot()
|
|||
// calc cplx^0.5
|
||||
_stack->allocate_back(number::calc_size(), cmd_number);
|
||||
CHECK_MPFR(mpfr_set_d(((number*)_stack->back())->_value.mpfr, 0.5, floating_t::s_mpfr_rnd));
|
||||
power();
|
||||
rpn_power();
|
||||
}
|
||||
else
|
||||
ERR_CONTEXT(ret_bad_operand_type);
|
||||
}
|
||||
|
||||
void square()
|
||||
void rpn_square()
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
|
||||
|
@ -368,14 +368,14 @@ void square()
|
|||
}
|
||||
else if (_stack->get_type(0) == cmd_complex)
|
||||
{
|
||||
dup();
|
||||
mul();
|
||||
rpn_dup();
|
||||
rpn_mul();
|
||||
}
|
||||
else
|
||||
ERR_CONTEXT(ret_bad_operand_type);
|
||||
}
|
||||
|
||||
void modulo()
|
||||
void rpn_modulo()
|
||||
{
|
||||
MIN_ARGUMENTS(2);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||
|
@ -422,7 +422,7 @@ void rpn_abs()
|
|||
ERR_CONTEXT(ret_bad_operand_type);
|
||||
}
|
||||
|
||||
void hex()
|
||||
void rpn_hex()
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||
|
@ -430,21 +430,21 @@ void hex()
|
|||
number::s_decimal_digits = 0;
|
||||
}
|
||||
|
||||
void bin()
|
||||
void rpn_bin()
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||
((number*)_stack->back())->_representation = number::bin;
|
||||
}
|
||||
|
||||
void dec()
|
||||
void rpn_dec()
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||
((number*)_stack->back())->_representation = number::dec;
|
||||
}
|
||||
|
||||
void base()
|
||||
void rpn_base()
|
||||
{
|
||||
MIN_ARGUMENTS(2);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||
|
@ -458,7 +458,7 @@ void base()
|
|||
ERR_CONTEXT(ret_out_of_range);
|
||||
}
|
||||
|
||||
void fact()
|
||||
void rpn_fact()
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||
|
@ -467,12 +467,12 @@ void fact()
|
|||
number* left = (number*)_stack->back();
|
||||
number* right = (number*)_stack->allocate_back(number::calc_size(), cmd_number);
|
||||
right->_value = 1L;
|
||||
plus();
|
||||
rpn_plus();
|
||||
|
||||
CHECK_MPFR(mpfr_gamma(left->_value.mpfr, left->_value.mpfr, floating_t::s_mpfr_rnd));
|
||||
}
|
||||
|
||||
void sign()
|
||||
void rpn_sign()
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
|
||||
|
@ -486,15 +486,15 @@ void sign()
|
|||
else if (_stack->get_type(0) == cmd_complex)
|
||||
{
|
||||
// calc x/sqrt(x*x+y*y) +iy/sqrt(x*x+y*y)
|
||||
dup();
|
||||
rpn_dup();
|
||||
rpn_abs();
|
||||
div();
|
||||
rpn_div();
|
||||
}
|
||||
else
|
||||
ERR_CONTEXT(ret_bad_operand_type);
|
||||
}
|
||||
|
||||
void mant()
|
||||
void rpn_mant()
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||
|
@ -528,7 +528,7 @@ void mant()
|
|||
ERR_CONTEXT(ret_out_of_range);
|
||||
}
|
||||
|
||||
void xpon()
|
||||
void rpn_xpon()
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
void swap(void)
|
||||
void rpn_swap(void)
|
||||
{
|
||||
MIN_ARGUMENTS(2);
|
||||
stack::copy_and_push_back(*_stack, _stack->size()-1, _calc_stack);
|
||||
|
@ -10,19 +10,19 @@ void swap(void)
|
|||
_calc_stack.pop_back(2);
|
||||
|
||||
}
|
||||
void drop(void)
|
||||
void rpn_drop(void)
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
(void)_stack->pop_back();
|
||||
}
|
||||
|
||||
void drop2(void)
|
||||
void rpn_drop2(void)
|
||||
{
|
||||
MIN_ARGUMENTS(2);
|
||||
(void)_stack->pop_back(2);
|
||||
}
|
||||
|
||||
void dropn(void)
|
||||
void rpn_dropn(void)
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||
|
@ -33,25 +33,25 @@ void dropn(void)
|
|||
(void)_stack->pop_back(args+1);
|
||||
}
|
||||
|
||||
void erase(void)
|
||||
void rpn_erase(void)
|
||||
{
|
||||
(void)_stack->pop_back(_stack->size());
|
||||
}
|
||||
|
||||
void dup(void)
|
||||
void rpn_dup(void)
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
stack::copy_and_push_back(*_stack, _stack->size()-1, *_stack);
|
||||
}
|
||||
|
||||
void dup2(void)
|
||||
void rpn_dup2(void)
|
||||
{
|
||||
MIN_ARGUMENTS(2);
|
||||
stack::copy_and_push_back(*_stack, _stack->size()-2, *_stack);
|
||||
stack::copy_and_push_back(*_stack, _stack->size()-2, *_stack);
|
||||
}
|
||||
|
||||
void dupn(void)
|
||||
void rpn_dupn(void)
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||
|
@ -64,7 +64,7 @@ void dupn(void)
|
|||
stack::copy_and_push_back(*_stack, _stack->size()-args, *_stack);
|
||||
}
|
||||
|
||||
void pick(void)
|
||||
void rpn_pick(void)
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||
|
@ -81,7 +81,7 @@ void pick(void)
|
|||
stack::copy_and_push_back(*_stack, _stack->size()-to_pick, *_stack);
|
||||
}
|
||||
|
||||
void rot(void)
|
||||
void rpn_rot(void)
|
||||
{
|
||||
MIN_ARGUMENTS(3);
|
||||
|
||||
|
@ -95,14 +95,14 @@ void rot(void)
|
|||
_calc_stack.pop_back(3);
|
||||
}
|
||||
|
||||
void depth(void)
|
||||
void rpn_depth(void)
|
||||
{
|
||||
unsigned long depth = (unsigned long)_stack->size();
|
||||
number* num = (number*)_stack->allocate_back(number::calc_size(), cmd_number);
|
||||
num->set(depth);
|
||||
}
|
||||
|
||||
void roll(void)
|
||||
void rpn_roll(void)
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||
|
@ -124,7 +124,7 @@ void roll(void)
|
|||
_calc_stack.pop_back(args);
|
||||
}
|
||||
|
||||
void rolld(void)
|
||||
void rpn_rolld(void)
|
||||
{
|
||||
MIN_ARGUMENTS(2);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||
|
@ -147,7 +147,7 @@ void rolld(void)
|
|||
_calc_stack.pop_back(args);
|
||||
}
|
||||
|
||||
void over(void)
|
||||
void rpn_over(void)
|
||||
{
|
||||
MIN_ARGUMENTS(2);
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
void sto(void)
|
||||
void rpn_sto(void)
|
||||
{
|
||||
MIN_ARGUMENTS(2);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_symbol);
|
||||
|
@ -10,7 +10,7 @@ void sto(void)
|
|||
}
|
||||
|
||||
//
|
||||
void stoadd(void)
|
||||
void rpn_stoadd(void)
|
||||
{
|
||||
MIN_ARGUMENTS(2);
|
||||
|
||||
|
@ -18,10 +18,10 @@ void stoadd(void)
|
|||
{
|
||||
// get variable value on stack level 1, make op then modify variable
|
||||
string variable(((symbol*)_stack->back())->_value);
|
||||
rcl();
|
||||
rpn_rcl();
|
||||
if (_err == ret_ok)
|
||||
{
|
||||
plus();
|
||||
rpn_plus();
|
||||
_heap->add(variable, _stack->get_obj(0), _stack->get_len(0));
|
||||
_stack->pop_back();
|
||||
}
|
||||
|
@ -34,11 +34,11 @@ void stoadd(void)
|
|||
_stack->pop_back();
|
||||
|
||||
string variable(((symbol*)_stack->back())->_value);
|
||||
rcl();
|
||||
rpn_rcl();
|
||||
if (_err == ret_ok)
|
||||
{
|
||||
stack::copy_and_push_back(_calc_stack, _calc_stack.size()-1, *_stack);
|
||||
plus();
|
||||
rpn_plus();
|
||||
_heap->add(variable, _stack->get_obj(0), _stack->get_len(0));
|
||||
_stack->pop_back();
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ void stoadd(void)
|
|||
ERR_CONTEXT(ret_bad_operand_type);
|
||||
}
|
||||
|
||||
void stosub(void)
|
||||
void rpn_stosub(void)
|
||||
{
|
||||
MIN_ARGUMENTS(2);
|
||||
|
||||
|
@ -55,10 +55,10 @@ void stosub(void)
|
|||
{
|
||||
// get variable value on stack level 1, make op then modify variable
|
||||
string variable(((symbol*)_stack->back())->_value);
|
||||
rcl();
|
||||
rpn_rcl();
|
||||
if (_err == ret_ok)
|
||||
{
|
||||
minus();
|
||||
rpn_minus();
|
||||
_heap->add(variable, _stack->get_obj(0), _stack->get_len(0));
|
||||
_stack->pop_back();
|
||||
}
|
||||
|
@ -71,11 +71,11 @@ void stosub(void)
|
|||
_stack->pop_back();
|
||||
|
||||
string variable(((symbol*)_stack->back())->_value);
|
||||
rcl();
|
||||
rpn_rcl();
|
||||
if (_err == ret_ok)
|
||||
{
|
||||
stack::copy_and_push_back(_calc_stack, _calc_stack.size()-1, *_stack);
|
||||
minus();
|
||||
rpn_minus();
|
||||
_heap->add(variable, _stack->get_obj(0), _stack->get_len(0));
|
||||
_stack->pop_back();
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ void stosub(void)
|
|||
ERR_CONTEXT(ret_bad_operand_type);
|
||||
}
|
||||
|
||||
void stomul(void)
|
||||
void rpn_stomul(void)
|
||||
{
|
||||
MIN_ARGUMENTS(2);
|
||||
|
||||
|
@ -92,10 +92,10 @@ void stomul(void)
|
|||
{
|
||||
// get variable value on stack level 1, make op then modify variable
|
||||
string variable(((symbol*)_stack->back())->_value);
|
||||
rcl();
|
||||
rpn_rcl();
|
||||
if (_err == ret_ok)
|
||||
{
|
||||
mul();
|
||||
rpn_mul();
|
||||
_heap->add(variable, _stack->get_obj(0), _stack->get_len(0));
|
||||
_stack->pop_back();
|
||||
}
|
||||
|
@ -108,11 +108,11 @@ void stomul(void)
|
|||
_stack->pop_back();
|
||||
|
||||
string variable(((symbol*)_stack->back())->_value);
|
||||
rcl();
|
||||
rpn_rcl();
|
||||
if (_err == ret_ok)
|
||||
{
|
||||
stack::copy_and_push_back(_calc_stack, _calc_stack.size()-1, *_stack);
|
||||
mul();
|
||||
rpn_mul();
|
||||
_heap->add(variable, _stack->get_obj(0), _stack->get_len(0));
|
||||
_stack->pop_back();
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ void stomul(void)
|
|||
ERR_CONTEXT(ret_bad_operand_type);
|
||||
}
|
||||
|
||||
void stodiv(void)
|
||||
void rpn_stodiv(void)
|
||||
{
|
||||
MIN_ARGUMENTS(2);
|
||||
|
||||
|
@ -129,10 +129,10 @@ void stodiv(void)
|
|||
{
|
||||
// get variable value on stack level 1, make op then modify variable
|
||||
string variable(((symbol*)_stack->back())->_value);
|
||||
rcl();
|
||||
rpn_rcl();
|
||||
if (_err == ret_ok)
|
||||
{
|
||||
div();
|
||||
rpn_div();
|
||||
_heap->add(variable, _stack->get_obj(0), _stack->get_len(0));
|
||||
_stack->pop_back();
|
||||
}
|
||||
|
@ -145,11 +145,11 @@ void stodiv(void)
|
|||
_stack->pop_back();
|
||||
|
||||
string variable(((symbol*)_stack->back())->_value);
|
||||
rcl();
|
||||
rpn_rcl();
|
||||
if (_err == ret_ok)
|
||||
{
|
||||
stack::copy_and_push_back(_calc_stack, _calc_stack.size()-1, *_stack);
|
||||
div();
|
||||
rpn_div();
|
||||
_heap->add(variable, _stack->get_obj(0), _stack->get_len(0));
|
||||
_stack->pop_back();
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ void stodiv(void)
|
|||
ERR_CONTEXT(ret_bad_operand_type);
|
||||
}
|
||||
|
||||
void stoneg(void)
|
||||
void rpn_stoneg(void)
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
|
||||
|
@ -166,10 +166,10 @@ void stoneg(void)
|
|||
{
|
||||
// get variable value on stack level 1, make op then modify variable
|
||||
string variable(((symbol*)_stack->back())->_value);
|
||||
rcl();
|
||||
rpn_rcl();
|
||||
if (_err == ret_ok)
|
||||
{
|
||||
neg();
|
||||
rpn_neg();
|
||||
_heap->add(variable, _stack->get_obj(0), _stack->get_len(0));
|
||||
_stack->pop_back();
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ void stoneg(void)
|
|||
ERR_CONTEXT(ret_bad_operand_type);
|
||||
}
|
||||
|
||||
void stoinv(void)
|
||||
void rpn_stoinv(void)
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
|
||||
|
@ -186,10 +186,10 @@ void stoinv(void)
|
|||
{
|
||||
// get variable value on stack level 1, make op then modify variable
|
||||
string variable(((symbol*)_stack->back())->_value);
|
||||
rcl();
|
||||
rpn_rcl();
|
||||
if (_err == ret_ok)
|
||||
{
|
||||
inv();
|
||||
rpn_inv();
|
||||
_heap->add(variable, _stack->get_obj(0), _stack->get_len(0));
|
||||
_stack->pop_back();
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ void stoinv(void)
|
|||
ERR_CONTEXT(ret_bad_operand_type);
|
||||
}
|
||||
|
||||
void rcl(void)
|
||||
void rpn_rcl(void)
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_symbol);
|
||||
|
@ -218,7 +218,7 @@ void rcl(void)
|
|||
ERR_CONTEXT(ret_unknown_variable);
|
||||
}
|
||||
|
||||
void edit(void)
|
||||
void rpn_edit(void)
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
|
||||
|
@ -263,7 +263,7 @@ void auto_rcl(symbol* symb)
|
|||
{
|
||||
stack::copy_and_push_back(obj, *_stack, size);
|
||||
if (obj->_type == cmd_program)
|
||||
eval();
|
||||
rpn_eval();
|
||||
}
|
||||
else
|
||||
stack::copy_and_push_back(symb, *_stack, symb->size());
|
||||
|
@ -272,7 +272,7 @@ void auto_rcl(symbol* symb)
|
|||
stack::copy_and_push_back(symb, *_stack, symb->size());
|
||||
}
|
||||
|
||||
void purge(void)
|
||||
void rpn_purge(void)
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_symbol);
|
||||
|
@ -282,7 +282,7 @@ void purge(void)
|
|||
ERR_CONTEXT(ret_unknown_variable);
|
||||
}
|
||||
|
||||
void vars(void)
|
||||
void rpn_vars(void)
|
||||
{
|
||||
object* obj;
|
||||
unsigned int size;
|
||||
|
@ -321,7 +321,7 @@ void vars(void)
|
|||
}
|
||||
}
|
||||
|
||||
void clusr(void)
|
||||
void rpn_clusr(void)
|
||||
{
|
||||
_heap->erase_all();
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
void instr()
|
||||
void rpn_instr()
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
|
||||
|
@ -28,7 +28,7 @@ void instr()
|
|||
}
|
||||
}
|
||||
|
||||
void strout()
|
||||
void rpn_strout()
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_string);
|
||||
|
@ -43,7 +43,7 @@ void strout()
|
|||
prog.run(*_stack, *_heap);
|
||||
}
|
||||
|
||||
void chr()
|
||||
void rpn_chr()
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||
|
@ -61,7 +61,7 @@ void chr()
|
|||
str->_value[1] = 0;
|
||||
}
|
||||
|
||||
void num()
|
||||
void rpn_num()
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_string);
|
||||
|
@ -71,7 +71,7 @@ void num()
|
|||
numb->_value = the_chr;
|
||||
}
|
||||
|
||||
void strsize()
|
||||
void rpn_strsize()
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_string);
|
||||
|
@ -81,7 +81,7 @@ void strsize()
|
|||
numb->_value = len;
|
||||
}
|
||||
|
||||
void strpos()
|
||||
void rpn_strpos()
|
||||
{
|
||||
MIN_ARGUMENTS(2);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_string);
|
||||
|
@ -99,7 +99,7 @@ void strpos()
|
|||
numb->_value = pos;
|
||||
}
|
||||
|
||||
void strsub()
|
||||
void rpn_strsub()
|
||||
{
|
||||
MIN_ARGUMENTS(3);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||
|
|
|
@ -46,7 +46,7 @@ void test_show_result(string title, int tests, int tests_failed, int steps, int
|
|||
printf(")\n");
|
||||
}
|
||||
|
||||
void test()
|
||||
void rpn_test()
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_string);
|
||||
|
|
|
@ -7,7 +7,7 @@ int cmp_strings_on_stack_top()
|
|||
return strncmp(left->_value, right->_value, min(left->_len, right->_len));
|
||||
}
|
||||
|
||||
void sup(void)
|
||||
void rpn_sup(void)
|
||||
{
|
||||
MIN_ARGUMENTS(2);
|
||||
|
||||
|
@ -33,7 +33,7 @@ void sup(void)
|
|||
ERR_CONTEXT(ret_bad_operand_type);
|
||||
}
|
||||
|
||||
void sup_eq(void)
|
||||
void rpn_sup_eq(void)
|
||||
{
|
||||
MIN_ARGUMENTS(2);
|
||||
|
||||
|
@ -59,7 +59,7 @@ void sup_eq(void)
|
|||
ERR_CONTEXT(ret_bad_operand_type);
|
||||
}
|
||||
|
||||
void inf(void)
|
||||
void rpn_inf(void)
|
||||
{
|
||||
MIN_ARGUMENTS(2);
|
||||
|
||||
|
@ -85,7 +85,7 @@ void inf(void)
|
|||
ERR_CONTEXT(ret_bad_operand_type);
|
||||
}
|
||||
|
||||
void inf_eq(void)
|
||||
void rpn_inf_eq(void)
|
||||
{
|
||||
MIN_ARGUMENTS(2);
|
||||
|
||||
|
@ -111,7 +111,7 @@ void inf_eq(void)
|
|||
ERR_CONTEXT(ret_bad_operand_type);
|
||||
}
|
||||
|
||||
void diff(void)
|
||||
void rpn_diff(void)
|
||||
{
|
||||
MIN_ARGUMENTS(2);
|
||||
|
||||
|
@ -153,7 +153,7 @@ void diff(void)
|
|||
ERR_CONTEXT(ret_bad_operand_type);
|
||||
}
|
||||
|
||||
void eq(void)
|
||||
void rpn_eq(void)
|
||||
{
|
||||
MIN_ARGUMENTS(2);
|
||||
|
||||
|
@ -195,7 +195,7 @@ void eq(void)
|
|||
ERR_CONTEXT(ret_bad_operand_type);
|
||||
}
|
||||
|
||||
void test_and(void)
|
||||
void rpn_test_and(void)
|
||||
{
|
||||
MIN_ARGUMENTS(2);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||
|
@ -211,7 +211,7 @@ void test_and(void)
|
|||
mpfr_set_si(left->_value.mpfr, 0, floating_t::s_mpfr_rnd);
|
||||
}
|
||||
|
||||
void test_or(void)
|
||||
void rpn_test_or(void)
|
||||
{
|
||||
MIN_ARGUMENTS(2);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||
|
@ -227,7 +227,7 @@ void test_or(void)
|
|||
mpfr_set_si(left->_value.mpfr, 0, floating_t::s_mpfr_rnd);
|
||||
}
|
||||
|
||||
void test_xor(void)
|
||||
void rpn_test_xor(void)
|
||||
{
|
||||
MIN_ARGUMENTS(2);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||
|
@ -252,7 +252,7 @@ void test_xor(void)
|
|||
}
|
||||
}
|
||||
|
||||
void test_not(void)
|
||||
void rpn_test_not(void)
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||
|
@ -264,7 +264,7 @@ void test_not(void)
|
|||
mpfr_set_si(left->_value.mpfr, 0, floating_t::s_mpfr_rnd);
|
||||
}
|
||||
|
||||
void same(void)
|
||||
void rpn_same(void)
|
||||
{
|
||||
eq();
|
||||
rpn_eq();
|
||||
}
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
//
|
||||
void pi(void)
|
||||
void rpn_pi(void)
|
||||
{
|
||||
number* pi = (number*)_stack->allocate_back(number::calc_size(), cmd_number);
|
||||
CHECK_MPFR(mpfr_const_pi(pi->_value.mpfr, floating_t::s_mpfr_rnd));
|
||||
}
|
||||
|
||||
void d2r(void)
|
||||
void rpn_d2r(void)
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||
|
||||
// add pi on stack
|
||||
pi();
|
||||
rpn_pi();
|
||||
|
||||
floating_t* pi = &((number*)_stack->pop_back())->_value;
|
||||
floating_t* left = &((number*)_stack->get_obj(0))->_value;
|
||||
|
@ -20,13 +20,13 @@ void d2r(void)
|
|||
CHECK_MPFR(mpfr_div_si(left->mpfr, left->mpfr, 180, floating_t::s_mpfr_rnd));
|
||||
}
|
||||
|
||||
void r2d(void)
|
||||
void rpn_r2d(void)
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||
|
||||
// add pi on stack
|
||||
pi();
|
||||
rpn_pi();
|
||||
|
||||
floating_t* pi = &((number*)_stack->pop_back())->_value;
|
||||
floating_t* left = &((number*)_stack->get_obj(0))->_value;
|
||||
|
@ -91,21 +91,21 @@ void rpn_asin(void)
|
|||
CHECK_MPFR(mpfr_set_d(i->re()->mpfr, 0.0, floating_t::s_mpfr_rnd));
|
||||
CHECK_MPFR(mpfr_set_d(i->im()->mpfr, 1.0, floating_t::s_mpfr_rnd));
|
||||
|
||||
dup();
|
||||
square();
|
||||
rpn_dup();
|
||||
rpn_square();
|
||||
num = (number*)_stack->allocate_back(number::calc_size(), cmd_number);
|
||||
CHECK_MPFR(mpfr_set_d(num->_value.mpfr, 1.0, floating_t::s_mpfr_rnd));
|
||||
minus();
|
||||
neg();
|
||||
squareroot();
|
||||
swap();
|
||||
rpn_minus();
|
||||
rpn_neg();
|
||||
rpn_squareroot();
|
||||
rpn_swap();
|
||||
stack::copy_and_push_back(_calc_stack, 0, *_stack);
|
||||
mul();
|
||||
plus();
|
||||
rpn_mul();
|
||||
rpn_plus();
|
||||
rpn_ln();
|
||||
stack::copy_and_push_back(_calc_stack, 0, *_stack);
|
||||
mul();
|
||||
neg();
|
||||
rpn_mul();
|
||||
rpn_neg();
|
||||
_calc_stack.pop_back();
|
||||
}
|
||||
else
|
||||
|
@ -161,12 +161,12 @@ void rpn_acos(void)
|
|||
{
|
||||
//acos(z)=pi/2-asin(z)
|
||||
rpn_asin();
|
||||
pi();
|
||||
rpn_pi();
|
||||
number* num = (number*)_stack->allocate_back(number::calc_size(), cmd_number);
|
||||
CHECK_MPFR(mpfr_set_d(num->_value.mpfr, 2.0, floating_t::s_mpfr_rnd));
|
||||
div();
|
||||
minus();
|
||||
neg();
|
||||
rpn_div();
|
||||
rpn_minus();
|
||||
rpn_neg();
|
||||
}
|
||||
else
|
||||
ERR_CONTEXT(ret_bad_operand_type);
|
||||
|
@ -239,22 +239,22 @@ void rpn_atan(void)
|
|||
CHECK_MPFR(mpfr_set_d(i->im()->mpfr, 1.0, floating_t::s_mpfr_rnd));
|
||||
|
||||
stack::copy_and_push_back(_calc_stack, 0, *_stack);
|
||||
mul();
|
||||
rpn_mul();
|
||||
num = (number*)_stack->allocate_back(number::calc_size(), cmd_number);
|
||||
CHECK_MPFR(mpfr_set_d(num->_value.mpfr, 1.0, floating_t::s_mpfr_rnd));
|
||||
minus();//iz-1
|
||||
neg();//1-iz
|
||||
dup();
|
||||
neg();//iz-1
|
||||
rpn_minus();//iz-1
|
||||
rpn_neg();//1-iz
|
||||
rpn_dup();
|
||||
rpn_neg();//iz-1
|
||||
num = (number*)_stack->allocate_back(number::calc_size(), cmd_number);
|
||||
CHECK_MPFR(mpfr_set_d(num->_value.mpfr, 2.0, floating_t::s_mpfr_rnd));
|
||||
plus();//iz+1
|
||||
div();
|
||||
rpn_plus();//iz+1
|
||||
rpn_div();
|
||||
|
||||
rpn_ln();
|
||||
CHECK_MPFR(mpfr_set_d(i->im()->mpfr, 0.5, floating_t::s_mpfr_rnd));
|
||||
stack::copy_and_push_back(_calc_stack, 0, *_stack);
|
||||
mul();
|
||||
rpn_mul();
|
||||
|
||||
_calc_stack.pop_back();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue