2015-07-23 13:22:42 +02:00
|
|
|
void plus()
|
|
|
|
{
|
|
|
|
MIN_ARGUMENTS(2);
|
|
|
|
|
2017-04-18 22:53:55 +02:00
|
|
|
// float
|
|
|
|
if (IS_ARG_TYPE(0, cmd_number))
|
|
|
|
{
|
|
|
|
ARG_MUST_BE_OF_TYPE(1, cmd_number);
|
|
|
|
|
2017-04-21 13:58:44 +02:00
|
|
|
number* right = (number*)_stack->pop_back();
|
2017-04-18 22:53:55 +02:00
|
|
|
number* left = (number*)_stack->back();
|
2017-04-29 16:48:14 +02:00
|
|
|
CHECK_MPFR(mpfr_add(left->_value.mpfr, left->_value.mpfr, right->_value.mpfr, s_mpfr_rnd));
|
2017-04-18 22:53:55 +02:00
|
|
|
}
|
|
|
|
// binary
|
|
|
|
else if (IS_ARG_TYPE(0, cmd_binary))
|
|
|
|
{
|
|
|
|
ARG_MUST_BE_OF_TYPE(1, cmd_binary);
|
|
|
|
|
2017-04-21 13:58:44 +02:00
|
|
|
binary* right = (binary*)_stack->pop_back();
|
2017-04-18 22:53:55 +02:00
|
|
|
binary* left = (binary*)_stack->back();
|
|
|
|
left->_value += right->_value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ERR_CONTEXT(ret_bad_operand_type);
|
2015-07-23 13:22:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void minus()
|
|
|
|
{
|
|
|
|
MIN_ARGUMENTS(2);
|
|
|
|
|
2017-04-18 22:53:55 +02:00
|
|
|
// float
|
|
|
|
if (IS_ARG_TYPE(0, cmd_number))
|
|
|
|
{
|
|
|
|
ARG_MUST_BE_OF_TYPE(1, cmd_number);
|
|
|
|
|
2017-04-21 13:58:44 +02:00
|
|
|
number* right = (number*)_stack->pop_back();
|
2017-04-18 22:53:55 +02:00
|
|
|
number* left = (number*)_stack->back();
|
2017-04-29 16:48:14 +02:00
|
|
|
CHECK_MPFR(mpfr_sub(left->_value.mpfr, left->_value.mpfr, right->_value.mpfr, s_mpfr_rnd));
|
2017-04-18 22:53:55 +02:00
|
|
|
}
|
|
|
|
// binary
|
|
|
|
else if (IS_ARG_TYPE(0, cmd_binary))
|
|
|
|
{
|
|
|
|
ARG_MUST_BE_OF_TYPE(1, cmd_binary);
|
|
|
|
|
2017-04-21 13:58:44 +02:00
|
|
|
binary* right = (binary*)_stack->pop_back();
|
2017-04-18 22:53:55 +02:00
|
|
|
binary* left = (binary*)_stack->back();
|
|
|
|
left->_value -= right->_value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ERR_CONTEXT(ret_bad_operand_type);
|
2015-07-23 13:22:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void mul()
|
|
|
|
{
|
2017-04-18 22:53:55 +02:00
|
|
|
// float
|
|
|
|
if (IS_ARG_TYPE(0, cmd_number))
|
|
|
|
{
|
|
|
|
ARG_MUST_BE_OF_TYPE(1, cmd_number);
|
|
|
|
|
2017-04-21 13:58:44 +02:00
|
|
|
number* right = (number*)_stack->pop_back();
|
2017-04-18 22:53:55 +02:00
|
|
|
number* left = (number*)_stack->back();
|
2017-04-29 16:48:14 +02:00
|
|
|
CHECK_MPFR(mpfr_mul(left->_value.mpfr, left->_value.mpfr, right->_value.mpfr, s_mpfr_rnd));
|
2017-04-18 22:53:55 +02:00
|
|
|
}
|
|
|
|
// binary
|
|
|
|
else if (IS_ARG_TYPE(0, cmd_binary))
|
|
|
|
{
|
|
|
|
ARG_MUST_BE_OF_TYPE(1, cmd_binary);
|
|
|
|
|
2017-04-21 13:58:44 +02:00
|
|
|
binary* right = (binary*)_stack->pop_back();
|
2017-04-18 22:53:55 +02:00
|
|
|
binary* left = (binary*)_stack->back();
|
|
|
|
left->_value *= right->_value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ERR_CONTEXT(ret_bad_operand_type);
|
2015-07-23 13:22:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void div()
|
|
|
|
{
|
2017-04-18 22:53:55 +02:00
|
|
|
MIN_ARGUMENTS(2);
|
|
|
|
|
|
|
|
// float
|
|
|
|
if (IS_ARG_TYPE(0, cmd_number))
|
|
|
|
{
|
|
|
|
ARG_MUST_BE_OF_TYPE(1, cmd_number);
|
|
|
|
|
2017-04-21 13:58:44 +02:00
|
|
|
number* right = (number*)_stack->pop_back();
|
2017-04-18 22:53:55 +02:00
|
|
|
number* left = (number*)_stack->back();
|
2017-04-29 16:48:14 +02:00
|
|
|
CHECK_MPFR(mpfr_div(left->_value.mpfr, left->_value.mpfr, right->_value.mpfr, s_mpfr_rnd));
|
2017-04-18 22:53:55 +02:00
|
|
|
}
|
|
|
|
// binary
|
|
|
|
else if (IS_ARG_TYPE(0, cmd_binary))
|
|
|
|
{
|
|
|
|
ARG_MUST_BE_OF_TYPE(1, cmd_binary);
|
|
|
|
if (((binary*)_stack->get_obj(0))->_value == 0)
|
|
|
|
{
|
|
|
|
ERR_CONTEXT(ret_div_by_zero);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-04-21 13:58:44 +02:00
|
|
|
binary* right = (binary*)_stack->pop_back();
|
2017-04-18 22:53:55 +02:00
|
|
|
binary* left = (binary*)_stack->back();
|
|
|
|
left->_value /= right->_value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ERR_CONTEXT(ret_bad_operand_type);
|
2015-07-23 13:22:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void neg()
|
|
|
|
{
|
2017-04-18 22:53:55 +02:00
|
|
|
MIN_ARGUMENTS(1);
|
|
|
|
|
|
|
|
// float
|
|
|
|
if (IS_ARG_TYPE(0, cmd_number))
|
|
|
|
{
|
|
|
|
number* left = (number*)_stack->back();
|
2017-04-29 16:48:14 +02:00
|
|
|
CHECK_MPFR(mpfr_neg(left->_value.mpfr, left->_value.mpfr, s_mpfr_rnd));
|
2017-04-18 22:53:55 +02:00
|
|
|
}
|
|
|
|
// binary
|
|
|
|
else if (IS_ARG_TYPE(0, cmd_binary))
|
|
|
|
((binary*)_stack->back())->_value *= -1;
|
|
|
|
else
|
|
|
|
ERR_CONTEXT(ret_bad_operand_type);
|
2015-07-23 13:22:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void inv()
|
|
|
|
{
|
2017-04-18 22:53:55 +02:00
|
|
|
MIN_ARGUMENTS(1);
|
|
|
|
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
2015-07-23 13:22:42 +02:00
|
|
|
|
2017-04-18 22:53:55 +02:00
|
|
|
number* left = (number*)_stack->back();
|
2017-04-29 16:48:14 +02:00
|
|
|
CHECK_MPFR(mpfr_si_div(left->_value.mpfr, 1L, left->_value.mpfr, s_mpfr_rnd));
|
2015-07-23 13:22:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void purcent()
|
|
|
|
{
|
2017-04-18 22:53:55 +02:00
|
|
|
MIN_ARGUMENTS(2);
|
|
|
|
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
|
|
|
ARG_MUST_BE_OF_TYPE(1, cmd_number);
|
|
|
|
|
2017-04-21 13:58:44 +02:00
|
|
|
number* right = (number*)_stack->pop_back();
|
2017-04-18 22:53:55 +02:00
|
|
|
number* left = (number*)_stack->back();
|
2015-07-23 13:22:42 +02:00
|
|
|
|
2017-04-29 16:48:14 +02:00
|
|
|
CHECK_MPFR(mpfr_mul(left->_value.mpfr, left->_value.mpfr, right->_value.mpfr, s_mpfr_rnd));
|
|
|
|
CHECK_MPFR(mpfr_div_si(left->_value.mpfr, left->_value.mpfr, 100L, s_mpfr_rnd));
|
2015-07-23 13:22:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void purcentCH()
|
|
|
|
{
|
2017-04-18 22:53:55 +02:00
|
|
|
MIN_ARGUMENTS(2);
|
|
|
|
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
|
|
|
ARG_MUST_BE_OF_TYPE(1, cmd_number);
|
|
|
|
|
2017-04-21 13:58:44 +02:00
|
|
|
number* right = (number*)_stack->pop_back();
|
2017-04-18 22:53:55 +02:00
|
|
|
number* left = (number*)_stack->back();
|
|
|
|
|
2017-04-29 16:48:14 +02:00
|
|
|
CHECK_MPFR(mpfr_mul_si(right->_value.mpfr, right->_value.mpfr, 100L, s_mpfr_rnd));
|
|
|
|
CHECK_MPFR(mpfr_div(left->_value.mpfr, right->_value.mpfr, left->_value.mpfr, s_mpfr_rnd));
|
2015-07-23 13:22:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void power()
|
|
|
|
{
|
2017-04-18 22:53:55 +02:00
|
|
|
MIN_ARGUMENTS(2);
|
|
|
|
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
|
|
|
ARG_MUST_BE_OF_TYPE(1, cmd_number);
|
|
|
|
|
2017-04-21 13:58:44 +02:00
|
|
|
number* right = (number*)_stack->pop_back();
|
2017-04-18 22:53:55 +02:00
|
|
|
number* left = (number*)_stack->back();
|
2017-04-29 16:48:14 +02:00
|
|
|
CHECK_MPFR(mpfr_pow(left->_value.mpfr, left->_value.mpfr, right->_value.mpfr, s_mpfr_rnd));
|
2015-07-23 13:22:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void squareroot()
|
|
|
|
{
|
2017-04-18 22:53:55 +02:00
|
|
|
MIN_ARGUMENTS(1);
|
|
|
|
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
2015-07-23 13:22:42 +02:00
|
|
|
|
2017-04-18 22:53:55 +02:00
|
|
|
number* left = (number*)_stack->back();
|
2017-04-29 16:48:14 +02:00
|
|
|
CHECK_MPFR(mpfr_sqrt(left->_value.mpfr, left->_value.mpfr, s_mpfr_rnd));
|
2015-07-23 13:22:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void square()
|
|
|
|
{
|
2017-04-18 22:53:55 +02:00
|
|
|
MIN_ARGUMENTS(1);
|
|
|
|
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
2015-07-23 13:22:42 +02:00
|
|
|
|
2017-04-18 22:53:55 +02:00
|
|
|
number* left = (number*)_stack->back();
|
2017-04-29 16:48:14 +02:00
|
|
|
CHECK_MPFR(mpfr_sqr(left->_value.mpfr, left->_value.mpfr, s_mpfr_rnd));
|
2015-07-23 13:22:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void modulo()
|
|
|
|
{
|
2017-04-18 22:53:55 +02:00
|
|
|
MIN_ARGUMENTS(2);
|
|
|
|
ARG_MUST_BE_OF_TYPE(0, cmd_number);
|
|
|
|
ARG_MUST_BE_OF_TYPE(1, cmd_number);
|
|
|
|
|
2017-04-21 13:58:44 +02:00
|
|
|
number* right = (number*)_stack->pop_back();
|
2017-04-18 22:53:55 +02:00
|
|
|
number* left = (number*)_stack->back();
|
|
|
|
|
2017-04-29 16:48:14 +02:00
|
|
|
CHECK_MPFR(mpfr_fmod(left->_value.mpfr, left->_value.mpfr, right->_value.mpfr, s_mpfr_rnd));
|
2015-07-23 13:22:42 +02:00
|
|
|
}
|