mirror of
https://github.com/louisrubet/rpn
synced 2025-01-16 03:41:28 +01:00
#42: abs, log2, alog2 and aliases exp2, exp10, pow, sqr
This commit is contained in:
parent
2d41c64268
commit
5d8096088c
3 changed files with 49 additions and 14 deletions
|
@ -13,22 +13,25 @@ program::keyword_t program::_keywords[] =
|
|||
{ cmd_keyword, "version", &program::rpn_version, "show rpn version" },
|
||||
{ cmd_keyword, "uname", &program::rpn_uname, "show rpn complete identification string" },
|
||||
{ cmd_keyword, "type", &program::type, "show first stack entry type" },
|
||||
{ cmd_keyword, "default", &program::rpn_default, "setting precision, float representation, float precision and verbosity to default" },
|
||||
{ cmd_keyword, "default", &program::rpn_default, "set float representation and precision to default" },
|
||||
|
||||
//REAL
|
||||
{ cmd_undef, "", NULL, "\nREAL"},
|
||||
{ cmd_keyword, "+", &program::plus, "binary operator +" },
|
||||
{ cmd_keyword, "-", &program::minus, "binary operator -" },
|
||||
{ cmd_keyword, "neg", &program::neg , "unary operator - (negation)" },
|
||||
{ cmd_keyword, "*", &program::mul, "binary operator *" },
|
||||
{ cmd_keyword, "/", &program::div, "binary operator /" },
|
||||
{ cmd_keyword, "inv", &program::inv, "unarity operator inverse (1/)" },
|
||||
{ cmd_keyword, "%", &program::purcent, "binary operator purcent" },
|
||||
{ cmd_keyword, "%CH", &program::purcentCH, "binary operator inverse purcent" },
|
||||
{ cmd_keyword, "^", &program::power, "binary operator power" },
|
||||
{ cmd_keyword, "sqrt", &program::squareroot, "unarity operator square root" },
|
||||
{ cmd_keyword, "sq", &program::square, "unarity operator square" },
|
||||
{ cmd_keyword, "mod", &program::modulo, "binary operator modulo" },
|
||||
{ cmd_keyword, "+", &program::plus, "addition" },
|
||||
{ cmd_keyword, "-", &program::minus, "substraction" },
|
||||
{ cmd_keyword, "neg", &program::neg , "negation" },
|
||||
{ cmd_keyword, "*", &program::mul, "multiplication" },
|
||||
{ cmd_keyword, "/", &program::div, "division" },
|
||||
{ cmd_keyword, "inv", &program::inv, "inverse" },
|
||||
{ cmd_keyword, "%", &program::purcent, "purcent" },
|
||||
{ cmd_keyword, "%CH", &program::purcentCH, "inverse purcent" },
|
||||
{ cmd_keyword, "^", &program::power, "(or pow) power" },
|
||||
{ cmd_keyword, "pow", &program::power, "" },
|
||||
{ cmd_keyword, "sqrt", &program::squareroot, "square root" },
|
||||
{ cmd_keyword, "sq", &program::square, "(or sqr) square" },
|
||||
{ cmd_keyword, "sqr", &program::square, "" },
|
||||
{ cmd_keyword, "mod", &program::modulo, "modulo" },
|
||||
{ cmd_keyword, "abs", &program::rpn_abs, "absolute value" },
|
||||
|
||||
//REAL representation
|
||||
{ cmd_undef, "", NULL, "\nREAL REPRESENTATION"},
|
||||
|
@ -110,7 +113,11 @@ program::keyword_t program::_keywords[] =
|
|||
{ cmd_undef, "", NULL, "\nLOGS"},
|
||||
{ cmd_keyword, "e", &program::rpn_e, "exp(0) constant" },
|
||||
{ cmd_keyword, "log", &program::rpn_log, "logarithm base 10" },
|
||||
{ cmd_keyword, "alog", &program::rpn_alog, "exponential base 10" },
|
||||
{ cmd_keyword, "alog", &program::rpn_alog, "(or exp10) exponential base 10" },
|
||||
{ cmd_keyword, "exp10", &program::rpn_alog, "" },
|
||||
{ cmd_keyword, "log2", &program::rpn_log2, "logarithm base 2" },
|
||||
{ cmd_keyword, "alog2", &program::rpn_alog2, "(or exp2) exponential base 2" },
|
||||
{ cmd_keyword, "exp2", &program::rpn_alog2, "" },
|
||||
{ cmd_keyword, "ln", &program::rpn_ln, "logarithm base e" },
|
||||
{ cmd_keyword, "exp", &program::rpn_exp, "exponential" },
|
||||
{ cmd_keyword, "sinh", &program::rpn_sinh, "hyperbolic sine" },
|
||||
|
|
|
@ -23,6 +23,24 @@ void rpn_alog()
|
|||
CHECK_MPFR(mpfr_exp10(left->mpfr, left->mpfr, s_mpfr_rnd));
|
||||
}
|
||||
|
||||
void rpn_log2()
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||
|
||||
floating_t* left = &((number*)_stack->get_obj(0))->_value;
|
||||
CHECK_MPFR(mpfr_log2(left->mpfr, left->mpfr, s_mpfr_rnd));
|
||||
}
|
||||
|
||||
void rpn_alog2()
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||
|
||||
floating_t* left = &((number*)_stack->get_obj(0))->_value;
|
||||
CHECK_MPFR(mpfr_exp2(left->mpfr, left->mpfr, s_mpfr_rnd));
|
||||
}
|
||||
|
||||
void rpn_ln()
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
|
|
|
@ -127,6 +127,16 @@ void modulo()
|
|||
CHECK_MPFR(mpfr_fmod(left->_value.mpfr, left->_value.mpfr, right->_value.mpfr, s_mpfr_rnd));
|
||||
}
|
||||
|
||||
void rpn_abs()
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
||||
|
||||
number* left = (number*)_stack->back();
|
||||
|
||||
CHECK_MPFR(mpfr_abs(left->_value.mpfr, left->_value.mpfr, s_mpfr_rnd));
|
||||
}
|
||||
|
||||
void hex()
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
|
|
Loading…
Reference in a new issue