diff --git a/src/rpn-cmd.h b/src/rpn-cmd.h index 23257ea..c0cda20 100644 --- a/src/rpn-cmd.h +++ b/src/rpn-cmd.h @@ -31,6 +31,11 @@ program::keyword_t program::_keywords[] = { cmd_keyword, "<=", &program::inf_eq, "binary operator <=" }, { cmd_keyword, "!=", &program::diff, "binary operator != (different)" }, { cmd_keyword, "==", &program::eq , "binary operator == (equal)" }, + { cmd_keyword, "and", &program::test_and , "boolean operator and" }, + { cmd_keyword, "or", &program::test_or , "boolean operator or" }, + { cmd_keyword, "xor", &program::test_xor , "boolean operator xor" }, + { cmd_keyword, "not", &program::test_not , "boolean operator not" }, + { cmd_keyword, "same", &program::same , "boolean operator same (equal)" }, //STACK { cmd_undef, "", NULL, "\nSTACK"}, diff --git a/src/rpn-test.h b/src/rpn-test.h index 2f59935..2f244b6 100644 --- a/src/rpn-test.h +++ b/src/rpn-test.h @@ -83,3 +83,46 @@ void eq(void) putf(0); } } + +void test_and(void) +{ + MIN_ARGUMENTS(2); + ARG_IS_OF_TYPE(0, cmd_number); + ARG_IS_OF_TYPE(1, cmd_number); + + putf((getf() != 0) && (getf() != 0)); +} + +void test_or(void) +{ + MIN_ARGUMENTS(2); + ARG_IS_OF_TYPE(0, cmd_number); + ARG_IS_OF_TYPE(1, cmd_number); + + putf((getf() != 0) || (getf() != 0)); +} + +void test_xor(void) +{ + MIN_ARGUMENTS(2); + ARG_IS_OF_TYPE(0, cmd_number); + ARG_IS_OF_TYPE(1, cmd_number); + + floating_t first = getf(); + floating_t second = getf(); + putf(((first == 0) && (second != 0)) || ((first != 0) && (second == 0))); +} + +void test_not(void) +{ + MIN_ARGUMENTS(1); + ARG_IS_OF_TYPE(0, cmd_number); + + floating_t first = getf(); + putf((first == 0) ? 1 : 0); +} + +void same(void) +{ + eq(); +}