diff --git a/MANUAL.md b/MANUAL.md index 906433f..d7fa290 100644 --- a/MANUAL.md +++ b/MANUAL.md @@ -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 diff --git a/src/rpn-real.hpp b/src/rpn-real.hpp index eecd3be..f85e5b1 100644 --- a/src/rpn-real.hpp +++ b/src/rpn-real.hpp @@ -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() diff --git a/test/10-complex.txt b/test/10-complex.txt index 75deefe..a8a2d53 100644 --- a/test/10-complex.txt +++ b/test/10-complex.txt @@ -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