#34: update test commands

This commit is contained in:
Louis Rubet 2017-04-19 14:13:22 +02:00
parent a3e13d2823
commit f43bd3f9d9
3 changed files with 153 additions and 106 deletions

View file

@ -20,20 +20,30 @@ void bin()
void rtob()
{
//TODO
//MIN_ARGUMENTS(1);
//ARG_MUST_BE_OF_TYPE(0, cmd_number);
MIN_ARGUMENTS(1);
ARG_MUST_BE_OF_TYPE(0, cmd_number);
//binary bin;
//bin.set(((integer_t)getf()));
//_stack->push_back(&bin, bin.size(), cmd_binary);
number* left = (number*)_stack->back();
_stack->pop_back();
cout<<"TODO"<<endl;
binary bin;
bin._value = mpfr_get_sj(&left->_value.mpfr, s_mpfr_rnd);
_stack->push_back(&bin, bin.size(), cmd_binary);
}
void btor()
{
// TODO
//MIN_ARGUMENTS(1);
//ARG_MUST_BE_OF_TYPE(0, cmd_binary);
MIN_ARGUMENTS(1);
ARG_MUST_BE_OF_TYPE(0, cmd_binary);
//putf((floating_t)getb());
integer_t bin = getb();
cout<<"TODO"<<endl;
_stack->push_back(NULL, sizeof(number), cmd_number, true);
number* left = (number*)_stack->back();
left->_value = bin;
left->ensure_significand();
}

View file

@ -1,142 +1,171 @@
//TODO must work with binary, ostring (others ?)
void sup(void)
{
//TODO
//MIN_ARGUMENTS(2);
//ARG_MUST_BE_OF_TYPE(0, cmd_number);
//ARG_MUST_BE_OF_TYPE(1, cmd_number);
MIN_ARGUMENTS(2);
ARG_MUST_BE_OF_TYPE(0, cmd_number);
ARG_MUST_BE_OF_TYPE(1, cmd_number);
//floating_t first = getf();
//putf(getf() > first);
number* right = (number*)_stack->back();
_stack->pop_back();
number* left = (number*)_stack->back();
if (mpfr_cmp(&left->_value.mpfr, &right->_value.mpfr) > 0)
mpfr_set_si(&left->_value.mpfr, 1, s_mpfr_rnd);
else
mpfr_set_si(&left->_value.mpfr, 0, s_mpfr_rnd);
}
void sup_eq(void)
{
//TODO
//MIN_ARGUMENTS(2);
//ARG_MUST_BE_OF_TYPE(0, cmd_number);
//ARG_MUST_BE_OF_TYPE(1, cmd_number);
MIN_ARGUMENTS(2);
ARG_MUST_BE_OF_TYPE(0, cmd_number);
ARG_MUST_BE_OF_TYPE(1, cmd_number);
//floating_t first = getf();
//putf(getf() >= first);
number* right = (number*)_stack->back();
_stack->pop_back();
number* left = (number*)_stack->back();
if (mpfr_cmp(&left->_value.mpfr, &right->_value.mpfr) >= 0)
mpfr_set_si(&left->_value.mpfr, 1, s_mpfr_rnd);
else
mpfr_set_si(&left->_value.mpfr, 0, s_mpfr_rnd);
}
void inf(void)
{
//TODO
//MIN_ARGUMENTS(2);
//ARG_MUST_BE_OF_TYPE(0, cmd_number);
//ARG_MUST_BE_OF_TYPE(1, cmd_number);
MIN_ARGUMENTS(2);
ARG_MUST_BE_OF_TYPE(0, cmd_number);
ARG_MUST_BE_OF_TYPE(1, cmd_number);
//floating_t first = getf();
//putf(getf() < first);
number* right = (number*)_stack->back();
_stack->pop_back();
number* left = (number*)_stack->back();
if (mpfr_cmp(&left->_value.mpfr, &right->_value.mpfr) < 0)
mpfr_set_si(&left->_value.mpfr, 1, s_mpfr_rnd);
else
mpfr_set_si(&left->_value.mpfr, 0, s_mpfr_rnd);
}
void inf_eq(void)
{
//TODO
//MIN_ARGUMENTS(2);
//ARG_MUST_BE_OF_TYPE(0, cmd_number);
//ARG_MUST_BE_OF_TYPE(1, cmd_number);
MIN_ARGUMENTS(2);
ARG_MUST_BE_OF_TYPE(0, cmd_number);
ARG_MUST_BE_OF_TYPE(1, cmd_number);
//floating_t first = getf();
//putf(getf() <= first);
number* right = (number*)_stack->back();
_stack->pop_back();
number* left = (number*)_stack->back();
if (mpfr_cmp(&left->_value.mpfr, &right->_value.mpfr) <= 0)
mpfr_set_si(&left->_value.mpfr, 1, s_mpfr_rnd);
else
mpfr_set_si(&left->_value.mpfr, 0, s_mpfr_rnd);
}
void diff(void)
{
//TODO
//MIN_ARGUMENTS(2);
//ARG_MUST_BE_OF_TYPE(0, cmd_number);
//ARG_MUST_BE_OF_TYPE(1, cmd_number);
MIN_ARGUMENTS(2);
ARG_MUST_BE_OF_TYPE(0, cmd_number);
ARG_MUST_BE_OF_TYPE(1, cmd_number);
//floating_t first = getf();
//putf(getf() != first);
number* right = (number*)_stack->back();
_stack->pop_back();
number* left = (number*)_stack->back();
if (mpfr_cmp(&left->_value.mpfr, &right->_value.mpfr) != 0)
mpfr_set_si(&left->_value.mpfr, 1, s_mpfr_rnd);
else
mpfr_set_si(&left->_value.mpfr, 0, s_mpfr_rnd);
}
void eq(void)
{
//TODO
//MIN_ARGUMENTS(2);
//int type = _stack->get_type(0);
MIN_ARGUMENTS(2);
ARG_MUST_BE_OF_TYPE(0, cmd_number);
ARG_MUST_BE_OF_TYPE(1, cmd_number);
//if (_stack->get_type(1) == type)
//{
// switch(type)
// {
// case cmd_number:
// {
// floating_t first = getf();
// putf(getf() == first);
// }
// break;
//TODO
#if 0
case cmd_symbol:
{
string first = getn();
putf(getn() == first);
}
#endif
// break;
// default:
// _stack->pop_back();
// _stack->pop_back();
// putf(0);
// break;
// }
//}
//else
//{
// _stack->pop_back();
// _stack->pop_back();
// putf(0);
//}
number* right = (number*)_stack->back();
_stack->pop_back();
number* left = (number*)_stack->back();
if (mpfr_cmp(&left->_value.mpfr, &right->_value.mpfr) == 0)
mpfr_set_si(&left->_value.mpfr, 1, s_mpfr_rnd);
else
mpfr_set_si(&left->_value.mpfr, 0, s_mpfr_rnd);
}
void test_and(void)
{
//TODO
//MIN_ARGUMENTS(2);
//ARG_MUST_BE_OF_TYPE(0, cmd_number);
//ARG_MUST_BE_OF_TYPE(1, cmd_number);
MIN_ARGUMENTS(2);
ARG_MUST_BE_OF_TYPE(0, cmd_number);
ARG_MUST_BE_OF_TYPE(1, cmd_number);
//floating_t first = getf();
//floating_t second = getf();
//putf((first != 0) && (second != 0));
number* right = (number*)_stack->back();
_stack->pop_back();
number* left = (number*)_stack->back();
if ((mpfr_cmp_si(&left->_value.mpfr, 0) == 0)
&& (mpfr_cmp_si(&right->_value.mpfr, 0) == 0))
mpfr_set_si(&left->_value.mpfr, 1, s_mpfr_rnd);
else
mpfr_set_si(&left->_value.mpfr, 0, s_mpfr_rnd);
}
void test_or(void)
{
//TODO
//MIN_ARGUMENTS(2);
//ARG_MUST_BE_OF_TYPE(0, cmd_number);
//ARG_MUST_BE_OF_TYPE(1, cmd_number);
MIN_ARGUMENTS(2);
ARG_MUST_BE_OF_TYPE(0, cmd_number);
ARG_MUST_BE_OF_TYPE(1, cmd_number);
//floating_t first = getf();
//floating_t second = getf();
//putf((first != 0) || (second != 0));
number* right = (number*)_stack->back();
_stack->pop_back();
number* left = (number*)_stack->back();
if ((mpfr_cmp_si(&left->_value.mpfr, 0) == 0)
|| (mpfr_cmp_si(&right->_value.mpfr, 0) == 0))
mpfr_set_si(&left->_value.mpfr, 1, s_mpfr_rnd);
else
mpfr_set_si(&left->_value.mpfr, 0, s_mpfr_rnd);
}
void test_xor(void)
{
//TODO
//MIN_ARGUMENTS(2);
//ARG_MUST_BE_OF_TYPE(0, cmd_number);
//ARG_MUST_BE_OF_TYPE(1, cmd_number);
MIN_ARGUMENTS(2);
ARG_MUST_BE_OF_TYPE(0, cmd_number);
ARG_MUST_BE_OF_TYPE(1, cmd_number);
//floating_t first = getf();
//floating_t second = getf();
//putf(((first == 0) && (second != 0)) || ((first != 0) && (second == 0)));
number* right = (number*)_stack->back();
_stack->pop_back();
number* left = (number*)_stack->back();
if (mpfr_cmp_si(&left->_value.mpfr, 0) == 0)
{
if (mpfr_cmp_si(&right->_value.mpfr, 0) != 0)
mpfr_set_si(&left->_value.mpfr, 1, s_mpfr_rnd);
else
mpfr_set_si(&left->_value.mpfr, 0, s_mpfr_rnd);
}
else
{
if (mpfr_cmp_si(&right->_value.mpfr, 0) == 0)
mpfr_set_si(&left->_value.mpfr, 1, s_mpfr_rnd);
else
mpfr_set_si(&left->_value.mpfr, 0, s_mpfr_rnd);
}
}
void test_not(void)
{
//TODO
//MIN_ARGUMENTS(1);
//ARG_MUST_BE_OF_TYPE(0, cmd_number);
MIN_ARGUMENTS(1);
ARG_MUST_BE_OF_TYPE(0, cmd_number);
//floating_t first = getf();
//putf((first == 0) ? 1 : 0);
number* left = (number*)_stack->back();
if (mpfr_cmp_si(&left->_value.mpfr, 0) == 0)
mpfr_set_si(&left->_value.mpfr, 1, s_mpfr_rnd);
else
mpfr_set_si(&left->_value.mpfr, 0, s_mpfr_rnd);
}
void same(void)

View file

@ -21,6 +21,7 @@
*
*/
#include <stdlib.h>
#include <stdint.h> //for intmax_t
#include <mpfr.h>
#include <math.h>
@ -99,6 +100,8 @@ const char* cmd_type_string[cmd_max] = {
"undef", "number", "binary", "string", "symbol", "program", "keyword", "keyword"
};
typedef long long integer_t;
// MPFR object
struct floating_t
{
@ -111,13 +114,20 @@ struct floating_t
mpfr_custom_init_set(&mpfr, MPFR_NAN_KIND, 0, s_mpfr_prec, significand);
}
floating_t operator=(const long int val)
floating_t& operator=(const long int val)
{
mpfr_custom_init(significand, MPFR_128BITS_STORING_LENGTH);
mpfr_custom_init_set(&mpfr, MPFR_ZERO_KIND, 0, s_mpfr_prec, significand);
mpfr_set_si(&mpfr, val, s_mpfr_rnd);
}
floating_t& operator=(const integer_t val)
{
mpfr_custom_init(significand, MPFR_128BITS_STORING_LENGTH);
mpfr_custom_init_set(&mpfr, MPFR_ZERO_KIND, 0, s_mpfr_prec, significand);
mpfr_set_sj(&mpfr, val, s_mpfr_rnd);
}
operator int()
{
return (int)mpfr_get_si(&mpfr, s_mpfr_rnd);
@ -139,8 +149,6 @@ struct floating_t
}
};
typedef long long integer_t;
class program;
class object;
class branch;
@ -344,8 +352,8 @@ struct branch : public object
arg1 = -1;
arg2 = -1;
arg3 = -1;
farg1 = 0;
farg2 = 0;
farg1 = 0L;
farg2 = 0L;
arg_bool = 0;
if (value != NULL)
{