mirror of
https://github.com/louisrubet/rpn
synced 2024-11-17 07:47:50 +01:00
#133: added complex im arg
This commit is contained in:
parent
ee9181b7fb
commit
0b1bd7bc85
3 changed files with 57 additions and 0 deletions
|
@ -60,6 +60,8 @@ program::keyword_t program::s_keywords[] =
|
|||
//COMPLEX
|
||||
{ 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" },
|
||||
|
||||
//TEST
|
||||
{ cmd_undef, "", NULL, "\nTEST"},
|
||||
|
|
|
@ -23,3 +23,18 @@ void im()
|
|||
CHECK_MPFR(mpfr_set(im->_value.mpfr, ((complex*)_branch_stack.get_obj(0))->im()->mpfr, floating_t::s_mpfr_rnd));
|
||||
_branch_stack.pop_back();
|
||||
}
|
||||
|
||||
void arg()
|
||||
{
|
||||
MIN_ARGUMENTS(1);
|
||||
ARG_MUST_BE_OF_TYPE(0, cmd_complex);
|
||||
|
||||
// calc atan2(x/y)
|
||||
complex* cplx = (complex*)_stack->pop_back();
|
||||
number* num = (number*)_branch_stack.allocate_back(number::calc_size(), cmd_number);
|
||||
|
||||
CHECK_MPFR(mpfr_atan2(num->_value.mpfr, cplx->im()->mpfr, cplx->re()->mpfr, floating_t::s_mpfr_rnd));
|
||||
|
||||
stack::copy_and_push_back(_branch_stack, 0, *_stack);
|
||||
_branch_stack.pop_back();
|
||||
}
|
||||
|
|
|
@ -186,3 +186,43 @@ drop
|
|||
(12,10) sq
|
||||
-> stack should be (44,240)
|
||||
drop
|
||||
|
||||
# arg (1)
|
||||
(1,1) arg pi 4 / ==
|
||||
-> stack should be 1
|
||||
drop
|
||||
|
||||
# arg (2)
|
||||
(-1,1) arg pi 3 * 4 / ==
|
||||
-> stack should be 1
|
||||
drop
|
||||
|
||||
# arg (3)
|
||||
(1,-1) arg -45 d->r ==
|
||||
-> stack should be 1
|
||||
drop
|
||||
|
||||
# arg (4)
|
||||
(-1,-1) arg pi -3 * 4 / ==
|
||||
-> stack should be 1
|
||||
drop
|
||||
|
||||
# arg (5)
|
||||
(1,0) arg 0 ==
|
||||
-> stack should be 1
|
||||
drop
|
||||
|
||||
# arg (6)
|
||||
(0,1) arg pi 2 / ==
|
||||
-> stack should be 1
|
||||
drop
|
||||
|
||||
# arg (7)
|
||||
(-1,0) arg pi ==
|
||||
-> stack should be 1
|
||||
drop
|
||||
|
||||
# arg (8)
|
||||
(0,-1) arg pi neg 2 / ==
|
||||
-> stack should be 1
|
||||
drop
|
||||
|
|
Loading…
Reference in a new issue