rpn/src/rpn-test.hpp

164 lines
4.5 KiB
C++
Raw Normal View History

void sup(void)
{
2017-04-19 14:13:22 +02:00
MIN_ARGUMENTS(2);
ARG_MUST_BE_OF_TYPE(0, cmd_number);
ARG_MUST_BE_OF_TYPE(1, cmd_number);
number* right = (number*)_stack->pop_back();
2017-04-19 14:13:22 +02:00
number* left = (number*)_stack->back();
if (mpfr_cmp(left->_value.mpfr, right->_value.mpfr) > 0)
mpfr_set_si(left->_value.mpfr, 1, floating_t::s_mpfr_rnd);
2017-04-19 14:13:22 +02:00
else
mpfr_set_si(left->_value.mpfr, 0, floating_t::s_mpfr_rnd);
}
void sup_eq(void)
{
2017-04-19 14:13:22 +02:00
MIN_ARGUMENTS(2);
ARG_MUST_BE_OF_TYPE(0, cmd_number);
ARG_MUST_BE_OF_TYPE(1, cmd_number);
number* right = (number*)_stack->pop_back();
2017-04-19 14:13:22 +02:00
number* left = (number*)_stack->back();
if (mpfr_cmp(left->_value.mpfr, right->_value.mpfr) >= 0)
mpfr_set_si(left->_value.mpfr, 1, floating_t::s_mpfr_rnd);
2017-04-19 14:13:22 +02:00
else
mpfr_set_si(left->_value.mpfr, 0, floating_t::s_mpfr_rnd);
}
void inf(void)
{
2017-04-19 14:13:22 +02:00
MIN_ARGUMENTS(2);
ARG_MUST_BE_OF_TYPE(0, cmd_number);
ARG_MUST_BE_OF_TYPE(1, cmd_number);
number* right = (number*)_stack->pop_back();
2017-04-19 14:13:22 +02:00
number* left = (number*)_stack->back();
if (mpfr_cmp(left->_value.mpfr, right->_value.mpfr) < 0)
mpfr_set_si(left->_value.mpfr, 1, floating_t::s_mpfr_rnd);
2017-04-19 14:13:22 +02:00
else
mpfr_set_si(left->_value.mpfr, 0, floating_t::s_mpfr_rnd);
}
void inf_eq(void)
{
2017-04-19 14:13:22 +02:00
MIN_ARGUMENTS(2);
ARG_MUST_BE_OF_TYPE(0, cmd_number);
ARG_MUST_BE_OF_TYPE(1, cmd_number);
number* right = (number*)_stack->pop_back();
2017-04-19 14:13:22 +02:00
number* left = (number*)_stack->back();
if (mpfr_cmp(left->_value.mpfr, right->_value.mpfr) <= 0)
mpfr_set_si(left->_value.mpfr, 1, floating_t::s_mpfr_rnd);
2017-04-19 14:13:22 +02:00
else
mpfr_set_si(left->_value.mpfr, 0, floating_t::s_mpfr_rnd);
}
void diff(void)
{
2017-04-19 14:13:22 +02:00
MIN_ARGUMENTS(2);
ARG_MUST_BE_OF_TYPE(0, cmd_number);
ARG_MUST_BE_OF_TYPE(1, cmd_number);
number* right = (number*)_stack->pop_back();
2017-04-19 14:13:22 +02:00
number* left = (number*)_stack->back();
if (mpfr_cmp(left->_value.mpfr, right->_value.mpfr) != 0)
mpfr_set_si(left->_value.mpfr, 1, floating_t::s_mpfr_rnd);
2017-04-19 14:13:22 +02:00
else
mpfr_set_si(left->_value.mpfr, 0, floating_t::s_mpfr_rnd);
}
void eq(void)
{
2017-04-19 14:13:22 +02:00
MIN_ARGUMENTS(2);
ARG_MUST_BE_OF_TYPE(0, cmd_number);
ARG_MUST_BE_OF_TYPE(1, cmd_number);
number* right = (number*)_stack->pop_back();
2017-04-19 14:13:22 +02:00
number* left = (number*)_stack->back();
if (mpfr_cmp(left->_value.mpfr, right->_value.mpfr) == 0)
mpfr_set_si(left->_value.mpfr, 1, floating_t::s_mpfr_rnd);
2017-04-19 14:13:22 +02:00
else
mpfr_set_si(left->_value.mpfr, 0, floating_t::s_mpfr_rnd);
}
void test_and(void)
{
2017-04-19 14:13:22 +02:00
MIN_ARGUMENTS(2);
ARG_MUST_BE_OF_TYPE(0, cmd_number);
ARG_MUST_BE_OF_TYPE(1, cmd_number);
number* right = (number*)_stack->pop_back();
2017-04-19 14:13:22 +02:00
number* left = (number*)_stack->back();
2017-05-02 11:27:04 +02:00
if ((mpfr_cmp_si(left->_value.mpfr, 0) != 0)
&& (mpfr_cmp_si(right->_value.mpfr, 0) != 0))
mpfr_set_si(left->_value.mpfr, 1, floating_t::s_mpfr_rnd);
2017-04-19 14:13:22 +02:00
else
mpfr_set_si(left->_value.mpfr, 0, floating_t::s_mpfr_rnd);
}
void test_or(void)
{
2017-04-19 14:13:22 +02:00
MIN_ARGUMENTS(2);
ARG_MUST_BE_OF_TYPE(0, cmd_number);
ARG_MUST_BE_OF_TYPE(1, cmd_number);
number* right = (number*)_stack->pop_back();
2017-04-19 14:13:22 +02:00
number* left = (number*)_stack->back();
2017-05-02 11:27:04 +02:00
if ((mpfr_cmp_si(left->_value.mpfr, 0) != 0)
|| (mpfr_cmp_si(right->_value.mpfr, 0) != 0))
mpfr_set_si(left->_value.mpfr, 1, floating_t::s_mpfr_rnd);
2017-04-19 14:13:22 +02:00
else
mpfr_set_si(left->_value.mpfr, 0, floating_t::s_mpfr_rnd);
}
void test_xor(void)
{
2017-04-19 14:13:22 +02:00
MIN_ARGUMENTS(2);
ARG_MUST_BE_OF_TYPE(0, cmd_number);
ARG_MUST_BE_OF_TYPE(1, cmd_number);
number* right = (number*)_stack->pop_back();
2017-04-19 14:13:22 +02:00
number* left = (number*)_stack->back();
if (mpfr_cmp_si(left->_value.mpfr, 0) == 0)
2017-04-19 14:13:22 +02:00
{
if (mpfr_cmp_si(right->_value.mpfr, 0) != 0)
mpfr_set_si(left->_value.mpfr, 1, floating_t::s_mpfr_rnd);
2017-04-19 14:13:22 +02:00
else
mpfr_set_si(left->_value.mpfr, 0, floating_t::s_mpfr_rnd);
2017-04-19 14:13:22 +02:00
}
else
{
if (mpfr_cmp_si(right->_value.mpfr, 0) == 0)
mpfr_set_si(left->_value.mpfr, 1, floating_t::s_mpfr_rnd);
2017-04-19 14:13:22 +02:00
else
mpfr_set_si(left->_value.mpfr, 0, floating_t::s_mpfr_rnd);
2017-04-19 14:13:22 +02:00
}
}
void test_not(void)
{
2017-04-19 14:13:22 +02:00
MIN_ARGUMENTS(1);
ARG_MUST_BE_OF_TYPE(0, cmd_number);
number* left = (number*)_stack->back();
if (mpfr_cmp_si(left->_value.mpfr, 0) == 0)
mpfr_set_si(left->_value.mpfr, 1, floating_t::s_mpfr_rnd);
2017-04-19 14:13:22 +02:00
else
mpfr_set_si(left->_value.mpfr, 0, floating_t::s_mpfr_rnd);
}
void same(void)
{
2015-05-19 17:51:03 +02:00
eq();
}