mirror of
https://github.com/louisrubet/rpn
synced 2025-01-16 03:41:28 +01:00
Merge branch 'expm-lnp1' into develop
This commit is contained in:
commit
313e1b9712
3 changed files with 113 additions and 30 deletions
|
@ -12,7 +12,6 @@ program::keyword_t program::s_keywords[] =
|
||||||
{ cmd_keyword, "help", &program::rpn_help, "this help message" },
|
{ cmd_keyword, "help", &program::rpn_help, "this help message" },
|
||||||
{ cmd_keyword, "h", &program::rpn_help, "" },
|
{ cmd_keyword, "h", &program::rpn_help, "" },
|
||||||
{ cmd_keyword, "?", &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, "quit", &program::rpn_good_bye, "quit software" },
|
||||||
{ cmd_keyword, "q", &program::rpn_good_bye, "" },
|
{ cmd_keyword, "q", &program::rpn_good_bye, "" },
|
||||||
{ cmd_keyword, "exit", &program::rpn_good_bye, "" },
|
{ cmd_keyword, "exit", &program::rpn_good_bye, "" },
|
||||||
|
@ -177,7 +176,9 @@ program::keyword_t program::s_keywords[] =
|
||||||
{ cmd_keyword, "e", &program::rpn_e, "Euler constant" },
|
{ cmd_keyword, "e", &program::rpn_e, "Euler constant" },
|
||||||
{ cmd_keyword, "ln", &program::rpn_ln, "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, "lnp1", &program::rpn_lnp1, "ln(1+x) which is useful when x is close to 0" },
|
||||||
{ cmd_keyword, "exp", &program::rpn_exp, "exponential" },
|
{ cmd_keyword, "exp", &program::rpn_exp, "exponential" },
|
||||||
|
{ cmd_keyword, "expm", &program::rpn_expm, "exp(x)-1 which is useful when x is close to 0" },
|
||||||
{ cmd_keyword, "log10", &program::rpn_log10, "logarithm base 10" },
|
{ cmd_keyword, "log10", &program::rpn_log10, "logarithm base 10" },
|
||||||
{ cmd_keyword, "alog10", &program::rpn_alog10, "exponential base 10" },
|
{ cmd_keyword, "alog10", &program::rpn_alog10, "exponential base 10" },
|
||||||
{ cmd_keyword, "exp10", &program::rpn_alog10, "" },
|
{ cmd_keyword, "exp10", &program::rpn_alog10, "" },
|
||||||
|
|
|
@ -154,6 +154,40 @@ void rpn_exp()
|
||||||
ERR_CONTEXT(ret_bad_operand_type);
|
ERR_CONTEXT(ret_bad_operand_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void rpn_expm()
|
||||||
|
{
|
||||||
|
MIN_ARGUMENTS(1);
|
||||||
|
|
||||||
|
if (_stack->get_type(0) == cmd_number || _stack->get_type(0) == cmd_complex)
|
||||||
|
{
|
||||||
|
//exp(x)-1
|
||||||
|
rpn_exp();
|
||||||
|
|
||||||
|
number* one = (number*)_stack->allocate_back(number::calc_size(), cmd_number);
|
||||||
|
CHECK_MPFR(mpfr_set_d(one->_value.mpfr, 1.0, floating_t::s_mpfr_rnd));
|
||||||
|
rpn_minus();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ERR_CONTEXT(ret_bad_operand_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
void rpn_lnp1()
|
||||||
|
{
|
||||||
|
MIN_ARGUMENTS(1);
|
||||||
|
|
||||||
|
if (_stack->get_type(0) == cmd_number || _stack->get_type(0) == cmd_complex)
|
||||||
|
{
|
||||||
|
//ln(x+1)
|
||||||
|
number* one = (number*)_stack->allocate_back(number::calc_size(), cmd_number);
|
||||||
|
CHECK_MPFR(mpfr_set_d(one->_value.mpfr, 1.0, floating_t::s_mpfr_rnd));
|
||||||
|
rpn_plus();
|
||||||
|
|
||||||
|
rpn_ln();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ERR_CONTEXT(ret_bad_operand_type);
|
||||||
|
}
|
||||||
|
|
||||||
void rpn_sinh()
|
void rpn_sinh()
|
||||||
{
|
{
|
||||||
MIN_ARGUMENTS(1);
|
MIN_ARGUMENTS(1);
|
||||||
|
|
|
@ -326,7 +326,7 @@ del
|
||||||
|
|
||||||
# sqrt (2)
|
# sqrt (2)
|
||||||
-3 sqrt
|
-3 sqrt
|
||||||
-> stack should be (-0.000000,1.732051)
|
-> stack should be (0.000000,1.732051)
|
||||||
del
|
del
|
||||||
|
|
||||||
# sin (1)
|
# sin (1)
|
||||||
|
@ -469,6 +469,30 @@ del
|
||||||
-> stack should be (0.804719,2.034444)
|
-> stack should be (0.804719,2.034444)
|
||||||
del
|
del
|
||||||
|
|
||||||
|
# lnp1 (1)
|
||||||
|
(1,2) lnp1
|
||||||
|
(1,2) 1 + ln ==
|
||||||
|
-> stack should be 1.000000
|
||||||
|
del
|
||||||
|
|
||||||
|
# lnp1 (2)
|
||||||
|
(1,-2) lnp1
|
||||||
|
(1,-2) 1 + ln ==
|
||||||
|
-> stack should be 1.000000
|
||||||
|
del
|
||||||
|
|
||||||
|
# lnp1 (3)
|
||||||
|
(-1,-2) lnp1
|
||||||
|
(-1,-2) 1 + ln ==
|
||||||
|
-> stack should be 1.000000
|
||||||
|
del
|
||||||
|
|
||||||
|
# lnp1 (4)
|
||||||
|
(-1,2) lnp1
|
||||||
|
(-1,2) 1 + ln ==
|
||||||
|
-> stack should be 1.000000
|
||||||
|
del
|
||||||
|
|
||||||
# log (1)
|
# log (1)
|
||||||
(1,2) log
|
(1,2) log
|
||||||
-> stack should be (0.804719,1.107149)
|
-> stack should be (0.804719,1.107149)
|
||||||
|
@ -549,6 +573,30 @@ del
|
||||||
-> stack should be (-0.153092,0.334512)
|
-> stack should be (-0.153092,0.334512)
|
||||||
del
|
del
|
||||||
|
|
||||||
|
# expm (1)
|
||||||
|
(1,2) expm
|
||||||
|
(1,2) exp 1 - ==
|
||||||
|
-> stack should be 1.000000
|
||||||
|
del
|
||||||
|
|
||||||
|
# expm (2)
|
||||||
|
(1,-2) expm
|
||||||
|
(1,-2) exp 1 - ==
|
||||||
|
-> stack should be 1.000000
|
||||||
|
del
|
||||||
|
|
||||||
|
# expm (3)
|
||||||
|
(-1,-2) expm
|
||||||
|
(-1,-2) exp 1 - ==
|
||||||
|
-> stack should be 1.000000
|
||||||
|
del
|
||||||
|
|
||||||
|
# expm (4)
|
||||||
|
(-1,2) expm
|
||||||
|
(-1,2) exp 1 - ==
|
||||||
|
-> stack should be 1.000000
|
||||||
|
del
|
||||||
|
|
||||||
# alog2 (1)
|
# alog2 (1)
|
||||||
(1,2) alog2
|
(1,2) alog2
|
||||||
-> stack should be (0.366914,1.966055)
|
-> stack should be (0.366914,1.966055)
|
||||||
|
|
Loading…
Reference in a new issue