#133: added complex conj

This commit is contained in:
Louis Rubet 2017-06-16 12:00:59 +02:00
parent 0b1bd7bc85
commit aa6cd3a4de
3 changed files with 14 additions and 1 deletions

View file

@ -60,7 +60,7 @@ program::keyword_t program::s_keywords[] =
//COMPLEX //COMPLEX
{ cmd_keyword, "re", &program::re, "complex real part" }, { cmd_keyword, "re", &program::re, "complex real part" },
{ cmd_keyword, "im", &program::im, "complex imaginary part" }, { cmd_keyword, "im", &program::im, "complex imaginary part" },
//{ cmd_keyword, "conj", &program::conj, "complex conjugate" }, { cmd_keyword, "conj", &program::conj, "complex conjugate" },
{ cmd_keyword, "arg", &program::arg, "complex argument in radians" }, { cmd_keyword, "arg", &program::arg, "complex argument in radians" },
//TEST //TEST

View file

@ -38,3 +38,12 @@ void arg()
stack::copy_and_push_back(_branch_stack, 0, *_stack); stack::copy_and_push_back(_branch_stack, 0, *_stack);
_branch_stack.pop_back(); _branch_stack.pop_back();
} }
void conj()
{
MIN_ARGUMENTS(1);
ARG_MUST_BE_OF_TYPE(0, cmd_complex);
complex* cplx = (complex*)_stack->back();
CHECK_MPFR(mpfr_neg(cplx->im()->mpfr, cplx->im()->mpfr, floating_t::s_mpfr_rnd));
}

View file

@ -226,3 +226,7 @@ drop
(0,-1) arg pi neg 2 / == (0,-1) arg pi neg 2 / ==
-> stack should be 1 -> stack should be 1
drop drop
# conj
(1,2) conj dup conj
-> stack should be (1,-2), (1,2)