diff --git a/src/parse.h b/src/parse.h index 05f3d04..4d7efe5 100644 --- a/src/parse.h +++ b/src/parse.h @@ -27,7 +27,6 @@ static ret_value get_fn(const char* fn_name, program_fn_t& fn, cmd_type_t& type) static bool _cut(const char* entry, vector& entries) { string tmp; - //TODO borner int len = strlen(entry); for (int i=0; i < len; i++) @@ -482,22 +481,6 @@ static bool _obj_from_string(const string& entry, object*& obj, unsigned int& ob return ret; } -static void _delete_obj_from_string(object* obj) -{ - if (obj != NULL) - { - switch (obj->_type) - { - case cmd_number: - case cmd_binary: - break; - default: - free(obj); - break; - } - } -} - static char* entry_completion_generator(const char* text, int state) { static int list_index, len, too_far; @@ -561,15 +544,7 @@ static ret_value parse(const char* entry, program& prog) // ex: entry="1 2+" -> vector = {"1", "2+"} -> first "1", second "2" and remaining_entry="+" // this remaining entry is treated as an entry if(_obj_from_string(main_entry, obj, obj_size, type, remaining_entry)) - { prog.push_back(obj, obj_size, type); - //TODO wtf !? - //_delete_obj_from_string(obj); - } - else - { - // no syntax error for now, an unknown obj form is considered as a symbol - } main_entry = remaining_entry; } } diff --git a/src/rpn-logs.h b/src/rpn-logs.h index 7ba28e9..31bc7e6 100644 --- a/src/rpn-logs.h +++ b/src/rpn-logs.h @@ -1,105 +1,97 @@ -#define _USE_MATH_DEFINES - -// void rpn_e(void) { - //TODO - //putf(M_E); + number num; + CHECK_MPFR(mpfr_const_euler(&num._value.mpfr, s_mpfr_rnd)); + _stack->push_back(&num, num.size(), cmd_number); + ((number*)_stack->back())->ensure_significand(); } void rpn_log() { - //TODO - //MIN_ARGUMENTS(1); - //ARG_MUST_BE_OF_TYPE(0, cmd_number); - //((number*)_stack->get_obj(0))->_value = log10(((number*)_stack->get_obj(0))->_value); + MIN_ARGUMENTS(1); + ARG_MUST_BE_OF_TYPE(0, cmd_number); + + floating_t* left = &((number*)_stack->get_obj(0))->_value; + CHECK_MPFR(mpfr_log10(&left->mpfr, &left->mpfr, s_mpfr_rnd)); } void rpn_alog() { - //TODO - //MIN_ARGUMENTS(1); - //ARG_MUST_BE_OF_TYPE(0, cmd_number); - //((number*)_stack->get_obj(0))->_value = pow(((number*)_stack->get_obj(0))->_value, 10); + MIN_ARGUMENTS(1); + ARG_MUST_BE_OF_TYPE(0, cmd_number); + + floating_t* left = &((number*)_stack->get_obj(0))->_value; + CHECK_MPFR(mpfr_exp10(&left->mpfr, &left->mpfr, s_mpfr_rnd)); } void rpn_ln() { - //TODO - //MIN_ARGUMENTS(1); - //ARG_MUST_BE_OF_TYPE(0, cmd_number); - //((number*)_stack->get_obj(0))->_value = log(((number*)_stack->get_obj(0))->_value); + MIN_ARGUMENTS(1); + ARG_MUST_BE_OF_TYPE(0, cmd_number); + + floating_t* left = &((number*)_stack->get_obj(0))->_value; + CHECK_MPFR(mpfr_log(&left->mpfr, &left->mpfr, s_mpfr_rnd)); } void rpn_exp() { - //TODO - //MIN_ARGUMENTS(1); - //ARG_MUST_BE_OF_TYPE(0, cmd_number); - //((number*)_stack->get_obj(0))->_value = exp(((number*)_stack->get_obj(0))->_value); + MIN_ARGUMENTS(1); + ARG_MUST_BE_OF_TYPE(0, cmd_number); + + floating_t* left = &((number*)_stack->get_obj(0))->_value; + CHECK_MPFR(mpfr_exp(&left->mpfr, &left->mpfr, s_mpfr_rnd)); } void rpn_sinh() { - //TODO - //MIN_ARGUMENTS(1); - //ARG_MUST_BE_OF_TYPE(0, cmd_number); - //((number*)_stack->get_obj(0))->_value = sinh(((number*)_stack->get_obj(0))->_value); + MIN_ARGUMENTS(1); + ARG_MUST_BE_OF_TYPE(0, cmd_number); + + floating_t* left = &((number*)_stack->get_obj(0))->_value; + CHECK_MPFR(mpfr_sinh(&left->mpfr, &left->mpfr, s_mpfr_rnd)); } void rpn_asinh() { - //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 value = ((number*)_stack->get_obj(0))->_value; - //if(value>0) - // value = log(value + sqrt(value * value + 1)); - //else - // value = -log(-value + sqrt(value * value + 1)); - - //((number*)_stack->get_obj(0))->_value = value; + floating_t* left = &((number*)_stack->get_obj(0))->_value; + CHECK_MPFR(mpfr_asinh(&left->mpfr, &left->mpfr, s_mpfr_rnd)); } void rpn_cosh() { - //TODO - //MIN_ARGUMENTS(1); - //ARG_MUST_BE_OF_TYPE(0, cmd_number); - //((number*)_stack->get_obj(0))->_value = cosh(((number*)_stack->get_obj(0))->_value); + MIN_ARGUMENTS(1); + ARG_MUST_BE_OF_TYPE(0, cmd_number); + + floating_t* left = &((number*)_stack->get_obj(0))->_value; + CHECK_MPFR(mpfr_cosh(&left->mpfr, &left->mpfr, s_mpfr_rnd)); } void rpn_acosh() { - //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 value = ((number*)_stack->get_obj(0))->_value; - //if(value>0) - // value = log(value + sqrt(value * value - 1)); - //else - // value = -log(-value + sqrt(value * value - 1)); - - //((number*)_stack->get_obj(0))->_value = value; + floating_t* left = &((number*)_stack->get_obj(0))->_value; + CHECK_MPFR(mpfr_cosh(&left->mpfr, &left->mpfr, s_mpfr_rnd)); } void rpn_tanh() { - //TODO - //MIN_ARGUMENTS(1); - //ARG_MUST_BE_OF_TYPE(0, cmd_number); - //((number*)_stack->get_obj(0))->_value = tanh(((number*)_stack->get_obj(0))->_value); + MIN_ARGUMENTS(1); + ARG_MUST_BE_OF_TYPE(0, cmd_number); + + floating_t* left = &((number*)_stack->get_obj(0))->_value; + CHECK_MPFR(mpfr_tanh(&left->mpfr, &left->mpfr, s_mpfr_rnd)); } void rpn_atanh() { - //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 value = ((number*)_stack->get_obj(0))->_value; - //value = (log(1 + value) - log(1 - value)) / 2; - //((number*)_stack->get_obj(0))->_value = value; + floating_t* left = &((number*)_stack->get_obj(0))->_value; + CHECK_MPFR(mpfr_atanh(&left->mpfr, &left->mpfr, s_mpfr_rnd)); } diff --git a/src/rpn-real.h b/src/rpn-real.h index c2f6a4c..56ea95a 100644 --- a/src/rpn-real.h +++ b/src/rpn-real.h @@ -22,17 +22,6 @@ void plus() binary* left = (binary*)_stack->back(); left->_value += right->_value; } - -#if 0 - // string - else if (IS_ARG_TYPE(0, cmd_string)) - { - ARG_MUST_BE_OF_TYPE(1, cmd_string); - string& second = *((ostring*)_stack->back())->_value; - _stack->pop_back(); - *((ostring*)_stack->back())->_value += second; - } -#endif else ERR_CONTEXT(ret_bad_operand_type); } diff --git a/src/rpn-test-core.h b/src/rpn-test-core.h index b67543b..5dd98a6 100644 --- a/src/rpn-test-core.h +++ b/src/rpn-test-core.h @@ -86,7 +86,7 @@ void program::test() if (stack_is != stack_should_be) { cout<push_back(&num, num.size(), cmd_number); + ((number*)_stack->back())->ensure_significand(); } void d2r(void) { - //TODO - //MIN_ARGUMENTS(1); - //ARG_MUST_BE_OF_TYPE(0, cmd_number); - //((number*)_stack->get_obj(0))->_value *= M_PI / 360; + MIN_ARGUMENTS(1); + ARG_MUST_BE_OF_TYPE(0, cmd_number); + + floating_t pi; + floating_t* left = &((number*)_stack->get_obj(0))->_value; + CHECK_MPFR(mpfr_const_pi(&pi.mpfr, s_mpfr_rnd)); + CHECK_MPFR(mpfr_mul(&left->mpfr, &left->mpfr, &pi.mpfr, s_mpfr_rnd)); + CHECK_MPFR(mpfr_div_si(&left->mpfr, &left->mpfr, 180, s_mpfr_rnd)); } void r2d(void) { - //TODO - //MIN_ARGUMENTS(1); - //ARG_MUST_BE_OF_TYPE(0, cmd_number); - //((number*)_stack->get_obj(0))->_value *= 360 / M_PI; + MIN_ARGUMENTS(1); + ARG_MUST_BE_OF_TYPE(0, cmd_number); + + floating_t pi; + floating_t* left = &((number*)_stack->get_obj(0))->_value; + CHECK_MPFR(mpfr_const_pi(&pi.mpfr, s_mpfr_rnd)); + CHECK_MPFR(mpfr_mul_si(&left->mpfr, &left->mpfr, 180, s_mpfr_rnd)); + CHECK_MPFR(mpfr_div(&left->mpfr, &left->mpfr, &pi.mpfr, s_mpfr_rnd)); } void rpn_sin(void) { - //TODO - //MIN_ARGUMENTS(1); - //ARG_MUST_BE_OF_TYPE(0, cmd_number); - //((number*)_stack->get_obj(0))->_value = sin(((number*)_stack->get_obj(0))->_value); + MIN_ARGUMENTS(1); + ARG_MUST_BE_OF_TYPE(0, cmd_number); + + floating_t* left = &((number*)_stack->get_obj(0))->_value; + CHECK_MPFR(mpfr_sin(&left->mpfr, &left->mpfr, s_mpfr_rnd)); } void rpn_asin(void) { - //TODO - //MIN_ARGUMENTS(1); - //ARG_MUST_BE_OF_TYPE(0, cmd_number); - //((number*)_stack->get_obj(0))->_value = asin(((number*)_stack->get_obj(0))->_value); + MIN_ARGUMENTS(1); + ARG_MUST_BE_OF_TYPE(0, cmd_number); + + floating_t* left = &((number*)_stack->get_obj(0))->_value; + CHECK_MPFR(mpfr_asin(&left->mpfr, &left->mpfr, s_mpfr_rnd)); } void rpn_cos(void) { - //TODO - //MIN_ARGUMENTS(1); - //ARG_MUST_BE_OF_TYPE(0, cmd_number); - //((number*)_stack->get_obj(0))->_value = cos(((number*)_stack->get_obj(0))->_value); + MIN_ARGUMENTS(1); + ARG_MUST_BE_OF_TYPE(0, cmd_number); + + floating_t* left = &((number*)_stack->get_obj(0))->_value; + CHECK_MPFR(mpfr_cos(&left->mpfr, &left->mpfr, s_mpfr_rnd)); } void rpn_acos(void) { - //TODO - //MIN_ARGUMENTS(1); - //ARG_MUST_BE_OF_TYPE(0, cmd_number); - //((number*)_stack->get_obj(0))->_value = acos(((number*)_stack->get_obj(0))->_value); + MIN_ARGUMENTS(1); + ARG_MUST_BE_OF_TYPE(0, cmd_number); + + floating_t* left = &((number*)_stack->get_obj(0))->_value; + CHECK_MPFR(mpfr_acos(&left->mpfr, &left->mpfr, s_mpfr_rnd)); } void rpn_tan(void) { - //TODO - //MIN_ARGUMENTS(1); - //ARG_MUST_BE_OF_TYPE(0, cmd_number); - //((number*)_stack->get_obj(0))->_value = tan(((number*)_stack->get_obj(0))->_value); + MIN_ARGUMENTS(1); + ARG_MUST_BE_OF_TYPE(0, cmd_number); + + floating_t* left = &((number*)_stack->get_obj(0))->_value; + CHECK_MPFR(mpfr_tan(&left->mpfr, &left->mpfr, s_mpfr_rnd)); } void rpn_atan(void) { - //TODO - //MIN_ARGUMENTS(1); - //ARG_MUST_BE_OF_TYPE(0, cmd_number); - //((number*)_stack->get_obj(0))->_value = atan(((number*)_stack->get_obj(0))->_value); + MIN_ARGUMENTS(1); + ARG_MUST_BE_OF_TYPE(0, cmd_number); + + floating_t* left = &((number*)_stack->get_obj(0))->_value; + CHECK_MPFR(mpfr_atan(&left->mpfr, &left->mpfr, s_mpfr_rnd)); } diff --git a/src/rpn.cpp b/src/rpn.cpp index 2be69de..f84bae8 100644 --- a/src/rpn.cpp +++ b/src/rpn.cpp @@ -192,7 +192,7 @@ struct number : public object _type = cmd_number; _value = value; } - unsigned int size() { return (unsigned int)sizeof(floating_t); } + unsigned int size() { return (unsigned int)sizeof(number); } void ensure_significand() { @@ -376,7 +376,6 @@ struct branch : public object branch_fn_t _fn; // args used by cmd_branch cmds int arg1, arg2, arg3; - //TODO change to int floating_t farg1, farg2; bool arg_bool; unsigned int _len; @@ -385,11 +384,14 @@ struct branch : public object void object::show(ostream& stream) { + //TODO please don't do that + char buffer_for_number[256]; switch(_type) { case cmd_number: ((number*)this)->ensure_significand(); - (void)mpfr_printf(s_mpfr_printf_format.c_str(), &((number*)this)->_value.mpfr); + (void)mpfr_sprintf(buffer_for_number, s_mpfr_printf_format.c_str(), &((number*)this)->_value.mpfr); + stream< vlayout; - int layout_index=-1;// TODO remplacable par vlayout.size()-1 + int layout_index=-1; // for start-end-step vector vstartindex; @@ -930,6 +932,8 @@ int main(int argc, char* argv[]) program::show_stack(global_stack, separator); } } - + + mpfr_free_cache(); + return ret; } diff --git a/src/version.h b/src/version.h index c00cc27..2c6f10a 100644 --- a/src/version.h +++ b/src/version.h @@ -1,6 +1,6 @@ // version and soft name -static const char version[] = "1.3.3"; -static const char uname[] = "rpn v1.3.3, (c) 2013 , GNU General Public License"; +static const char version[] = "2.0 RC1"; +static const char uname[] = "rpn v2.0 RC1, (c) 2013 , GNU General Public License"; static const char g_cursor[] = "> "; static const string g_show_stack_separator = "> "; @@ -9,7 +9,7 @@ static const string g_show_stack_separator = "> "; static const char* syntax[] = { ATTR_BOLD "R" ATTR_OFF "everse " ATTR_BOLD "P" ATTR_OFF "olish " - ATTR_BOLD "N" ATTR_OFF "otation language, based on hewlett-Packard RPL", + ATTR_BOLD "N" ATTR_OFF "otation language, based on Hewlett-Packard RPL", "", "Syntax: rpn [command]", "with optional command = list of commands",