#132: added complex sign

This commit is contained in:
Louis Rubet 2017-06-16 10:49:12 +02:00
parent 98ef0be9a0
commit 7c870f42c4
3 changed files with 32 additions and 6 deletions

View file

@ -102,7 +102,7 @@ rpn>
|hex| hexadecimal representation
|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```
|round| set float rounding mode. Authoerized values are: ```["nearest", "toward zero", "toward +inf", "toward -inf", "away from zero"] round```. ex: ```"nearest" round```
|sign| 1 if number at stack level 1 is > 0, 0 if == 0, -1 if <= 0
|sign| sign of a real, unary vector in the same direction for a complex
### real

View file

@ -410,12 +410,23 @@ void fact()
void sign()
{
MIN_ARGUMENTS(1);
ARG_MUST_BE_OF_TYPE(0, cmd_number);
// fact(n) = gamma(n+1)
number* left = (number*)_stack->back();
int result = mpfr_sgn(left->_value.mpfr);
left->_value = (long)result;
if (_stack->get_type(0) == cmd_number)
{
// fact(n) = gamma(n+1)
number* left = (number*)_stack->back();
int result = mpfr_sgn(left->_value.mpfr);
left->_value = (long)result;
}
else if (_stack->get_type(0) == cmd_complex)
{
// calc x/sqrt(x*x+y*y) +iy/sqrt(x*x+y*y)
dup();
rpn_abs();
div();
}
else
ERR_CONTEXT(ret_bad_operand_type);
}
void mant()

View file

@ -146,3 +146,18 @@ drop
(3,4) abs
-> stack should be 5
drop
# sign (1)
(1,0) sign
-> stack should be (1,0)
drop
# sign (2)
(0,1) sign
-> stack should be (0,1)
drop
# sign (3)
(3,-4) sign
-> stack should be (0.6,-0.8)
drop