diff --git a/src/parse.h b/src/parse.h index fbefa80..c1c4f67 100644 --- a/src/parse.h +++ b/src/parse.h @@ -340,7 +340,7 @@ static bool get_float(const string& entry, program& prog, string& remaining_entr number* num = (number*)prog.allocate_back((unsigned int)sizeof(number), cmd_number, MPFR_128BITS_STORING_LENGTH, &significand); num->init(significand); - int mpfr_ret = mpfr_strtofr(&num->_value.mpfr, entry.c_str(), &endptr, 0, MPFR_DEF_RND); + int mpfr_ret = mpfr_strtofr(num->_value.mpfr, entry.c_str(), &endptr, 0, MPFR_DEF_RND); if (endptr != entry.c_str()) { ret = true; diff --git a/src/rpn-binary.h b/src/rpn-binary.h index 2207460..ac12d94 100644 --- a/src/rpn-binary.h +++ b/src/rpn-binary.h @@ -26,7 +26,7 @@ void rtob() number* left = (number*)_stack->pop_back(); binary bin; - bin.set(mpfr_get_sj(&left->_value.mpfr, s_mpfr_rnd)); + bin.set(mpfr_get_sj(left->_value.mpfr, s_mpfr_rnd)); _stack->push_back(&bin, bin.size(), cmd_binary); } diff --git a/src/rpn-branch.h b/src/rpn-branch.h index 2ceea7a..12d616d 100644 --- a/src/rpn-branch.h +++ b/src/rpn-branch.h @@ -6,7 +6,7 @@ int rpn_if(branch& myobj) MIN_ARGUMENTS_RET(1, -1); ARG_MUST_BE_OF_TYPE_RET(0, cmd_number, -1); - if (mpfr_cmp_si(&((number*)_stack->get_obj(0))->_value.mpfr, 0UL) != 0) + if (mpfr_cmp_si(((number*)_stack->get_obj(0))->_value.mpfr, 0UL) != 0) myobj.arg1 = 1; else myobj.arg1 = 0; @@ -55,27 +55,15 @@ int rpn_start(branch& myobj) // farg1 = first value of start command // farg2 = last value of start command -cout<<__FUNCTION__<<": copy_and_push_back(farg2)"<get_obj(0)="; ((number*)_stack->get_obj(0))->show(cout);cout<<"]\n"; -cout<<"(number*)_stack->get_obj(0)="<<(void*)_stack->get_obj(0)<<"="; -dump8((unsigned char*)_stack->get_obj(0), 0, 40); myobj.farg2 = (number*)_branch_stack.get_obj(0); myobj.farg2->init(_branch_stack.get_blob(0)); _stack->pop_back(); -cout<<"myobj.farg2="<<(void*)myobj.farg2<<"="; -dump8((unsigned char*)myobj.farg2, 0, 40); -cout<<"[-> arg2="; myobj.farg2->show(cout);cout<<"]\n"; -cout<<__FUNCTION__<<": copy_and_push_back(farg1)"<get_obj(0)="; ((number*)_stack->get_obj(0))->show(cout);cout<<"]\n"; -cout<<"[_branch_stack.size()="<<_branch_stack.size()<<"]\n"; myobj.farg1 = (number*)_branch_stack.get_obj(0); myobj.farg1->init(_branch_stack.get_blob(0)); _stack->pop_back(); -cout<<"[myobj.farg2->_value.mpfr._mpfr_d="; myobj.farg2->_value.mpfr._mpfr_d;cout<<"]\n"; -cout<<"[-> arg2="; myobj.farg2->show(cout);cout<<"]\n"; return -1; } @@ -118,7 +106,7 @@ int rpn_next(branch& myobj) } // increment then test - mpfr_add_si(&myobj.farg1->_value.mpfr, &myobj.farg1->_value.mpfr, 1UL, MPFR_DEF_RND); + mpfr_add_si(myobj.farg1->_value.mpfr, myobj.farg1->_value.mpfr, 1UL, MPFR_DEF_RND); // for command: increment symbol too if (start_or_for->arg1 != -1) diff --git a/src/rpn-logs.h b/src/rpn-logs.h index 31bc7e6..49ce87f 100644 --- a/src/rpn-logs.h +++ b/src/rpn-logs.h @@ -1,7 +1,7 @@ void rpn_e(void) { number num; - CHECK_MPFR(mpfr_const_euler(&num._value.mpfr, s_mpfr_rnd)); + CHECK_MPFR(mpfr_const_euler(num._value.mpfr, s_mpfr_rnd)); _stack->push_back(&num, num.size(), cmd_number); ((number*)_stack->back())->ensure_significand(); } @@ -12,7 +12,7 @@ void rpn_log() 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)); + CHECK_MPFR(mpfr_log10(left->mpfr, left->mpfr, s_mpfr_rnd)); } void rpn_alog() @@ -21,7 +21,7 @@ void rpn_alog() 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)); + CHECK_MPFR(mpfr_exp10(left->mpfr, left->mpfr, s_mpfr_rnd)); } void rpn_ln() @@ -30,7 +30,7 @@ void rpn_ln() 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)); + CHECK_MPFR(mpfr_log(left->mpfr, left->mpfr, s_mpfr_rnd)); } void rpn_exp() @@ -39,7 +39,7 @@ void rpn_exp() 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)); + CHECK_MPFR(mpfr_exp(left->mpfr, left->mpfr, s_mpfr_rnd)); } void rpn_sinh() @@ -48,7 +48,7 @@ void rpn_sinh() 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)); + CHECK_MPFR(mpfr_sinh(left->mpfr, left->mpfr, s_mpfr_rnd)); } void rpn_asinh() @@ -57,7 +57,7 @@ void rpn_asinh() ARG_MUST_BE_OF_TYPE(0, cmd_number); floating_t* left = &((number*)_stack->get_obj(0))->_value; - CHECK_MPFR(mpfr_asinh(&left->mpfr, &left->mpfr, s_mpfr_rnd)); + CHECK_MPFR(mpfr_asinh(left->mpfr, left->mpfr, s_mpfr_rnd)); } void rpn_cosh() @@ -66,7 +66,7 @@ void rpn_cosh() 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)); + CHECK_MPFR(mpfr_cosh(left->mpfr, left->mpfr, s_mpfr_rnd)); } void rpn_acosh() @@ -75,7 +75,7 @@ void rpn_acosh() 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)); + CHECK_MPFR(mpfr_cosh(left->mpfr, left->mpfr, s_mpfr_rnd)); } void rpn_tanh() @@ -84,7 +84,7 @@ void rpn_tanh() 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)); + CHECK_MPFR(mpfr_tanh(left->mpfr, left->mpfr, s_mpfr_rnd)); } void rpn_atanh() @@ -93,5 +93,5 @@ void rpn_atanh() ARG_MUST_BE_OF_TYPE(0, cmd_number); floating_t* left = &((number*)_stack->get_obj(0))->_value; - CHECK_MPFR(mpfr_atanh(&left->mpfr, &left->mpfr, s_mpfr_rnd)); + CHECK_MPFR(mpfr_atanh(left->mpfr, left->mpfr, s_mpfr_rnd)); } diff --git a/src/rpn-real.h b/src/rpn-real.h index 5955f83..38b667e 100644 --- a/src/rpn-real.h +++ b/src/rpn-real.h @@ -9,7 +9,7 @@ void plus() number* right = (number*)_stack->pop_back(); number* left = (number*)_stack->back(); - CHECK_MPFR(mpfr_add(&left->_value.mpfr, &left->_value.mpfr, &right->_value.mpfr, s_mpfr_rnd)); + CHECK_MPFR(mpfr_add(left->_value.mpfr, left->_value.mpfr, right->_value.mpfr, s_mpfr_rnd)); } // binary else if (IS_ARG_TYPE(0, cmd_binary)) @@ -35,7 +35,7 @@ void minus() number* right = (number*)_stack->pop_back(); number* left = (number*)_stack->back(); - CHECK_MPFR(mpfr_sub(&left->_value.mpfr, &left->_value.mpfr, &right->_value.mpfr, s_mpfr_rnd)); + CHECK_MPFR(mpfr_sub(left->_value.mpfr, left->_value.mpfr, right->_value.mpfr, s_mpfr_rnd)); } // binary else if (IS_ARG_TYPE(0, cmd_binary)) @@ -59,7 +59,7 @@ void mul() number* right = (number*)_stack->pop_back(); number* left = (number*)_stack->back(); - CHECK_MPFR(mpfr_mul(&left->_value.mpfr, &left->_value.mpfr, &right->_value.mpfr, s_mpfr_rnd)); + CHECK_MPFR(mpfr_mul(left->_value.mpfr, left->_value.mpfr, right->_value.mpfr, s_mpfr_rnd)); } // binary else if (IS_ARG_TYPE(0, cmd_binary)) @@ -85,7 +85,7 @@ void div() number* right = (number*)_stack->pop_back(); number* left = (number*)_stack->back(); - CHECK_MPFR(mpfr_div(&left->_value.mpfr, &left->_value.mpfr, &right->_value.mpfr, s_mpfr_rnd)); + CHECK_MPFR(mpfr_div(left->_value.mpfr, left->_value.mpfr, right->_value.mpfr, s_mpfr_rnd)); } // binary else if (IS_ARG_TYPE(0, cmd_binary)) @@ -114,7 +114,7 @@ void neg() if (IS_ARG_TYPE(0, cmd_number)) { number* left = (number*)_stack->back(); - CHECK_MPFR(mpfr_neg(&left->_value.mpfr, &left->_value.mpfr, s_mpfr_rnd)); + CHECK_MPFR(mpfr_neg(left->_value.mpfr, left->_value.mpfr, s_mpfr_rnd)); } // binary else if (IS_ARG_TYPE(0, cmd_binary)) @@ -129,7 +129,7 @@ void inv() ARG_MUST_BE_OF_TYPE(0, cmd_number); number* left = (number*)_stack->back(); - CHECK_MPFR(mpfr_si_div(&left->_value.mpfr, 1L, &left->_value.mpfr, s_mpfr_rnd)); + CHECK_MPFR(mpfr_si_div(left->_value.mpfr, 1L, left->_value.mpfr, s_mpfr_rnd)); } void purcent() @@ -141,8 +141,8 @@ void purcent() number* right = (number*)_stack->pop_back(); number* left = (number*)_stack->back(); - 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)); + 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)); } void purcentCH() @@ -154,8 +154,8 @@ void purcentCH() number* right = (number*)_stack->pop_back(); number* left = (number*)_stack->back(); - 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)); + 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)); } void power() @@ -166,7 +166,7 @@ void power() number* right = (number*)_stack->pop_back(); number* left = (number*)_stack->back(); - CHECK_MPFR(mpfr_pow(&left->_value.mpfr, &left->_value.mpfr, &right->_value.mpfr, s_mpfr_rnd)); + CHECK_MPFR(mpfr_pow(left->_value.mpfr, left->_value.mpfr, right->_value.mpfr, s_mpfr_rnd)); } void squareroot() @@ -175,7 +175,7 @@ void squareroot() ARG_MUST_BE_OF_TYPE(0, cmd_number); number* left = (number*)_stack->back(); - CHECK_MPFR(mpfr_sqrt(&left->_value.mpfr, &left->_value.mpfr, s_mpfr_rnd)); + CHECK_MPFR(mpfr_sqrt(left->_value.mpfr, left->_value.mpfr, s_mpfr_rnd)); } void square() @@ -184,7 +184,7 @@ void square() ARG_MUST_BE_OF_TYPE(0, cmd_number); number* left = (number*)_stack->back(); - CHECK_MPFR(mpfr_sqr(&left->_value.mpfr, &left->_value.mpfr, s_mpfr_rnd)); + CHECK_MPFR(mpfr_sqr(left->_value.mpfr, left->_value.mpfr, s_mpfr_rnd)); } void modulo() @@ -196,5 +196,5 @@ void modulo() number* right = (number*)_stack->pop_back(); number* left = (number*)_stack->back(); - CHECK_MPFR(mpfr_fmod(&left->_value.mpfr, &left->_value.mpfr, &right->_value.mpfr, s_mpfr_rnd)); + CHECK_MPFR(mpfr_fmod(left->_value.mpfr, left->_value.mpfr, right->_value.mpfr, s_mpfr_rnd)); } diff --git a/src/rpn-stack.h b/src/rpn-stack.h index 42c40bf..0fc0719 100644 --- a/src/rpn-stack.h +++ b/src/rpn-stack.h @@ -1,17 +1,15 @@ -stack _stack_manip; - // void swap(void) { MIN_ARGUMENTS(2); - - stack::copy_and_push_back(*_stack, _stack->size()-1, _stack_manip); - stack::copy_and_push_back(*_stack, _stack->size()-2, _stack_manip); + stack::copy_and_push_back(*_stack, _stack->size()-1, _branch_stack); + stack::copy_and_push_back(*_stack, _stack->size()-2, _branch_stack); (void)_stack->pop_back(); (void)_stack->pop_back(); - stack::copy_and_push_back(_stack_manip, 0, *_stack); - stack::copy_and_push_back(_stack_manip, 1, *_stack); - _stack_manip.erase(); + stack::copy_and_push_back(_branch_stack, 0, *_stack); + stack::copy_and_push_back(_branch_stack, 1, *_stack); + (void)_branch_stack.pop_back(); + (void)_branch_stack.pop_back(); } void drop(void) @@ -67,17 +65,18 @@ void rot(void) { MIN_ARGUMENTS(3); - //TODO could be optimized - stack::copy_and_push_back(*_stack, _stack->size()-3, _stack_manip); - stack::copy_and_push_back(*_stack, _stack->size()-2, _stack_manip); - stack::copy_and_push_back(*_stack, _stack->size()-1, _stack_manip); + stack::copy_and_push_back(*_stack, _stack->size()-3, _branch_stack); + stack::copy_and_push_back(*_stack, _stack->size()-2, _branch_stack); + stack::copy_and_push_back(*_stack, _stack->size()-1, _branch_stack); (void)_stack->pop_back(); (void)_stack->pop_back(); (void)_stack->pop_back(); - stack::copy_and_push_back(_stack_manip, 2, *_stack); - stack::copy_and_push_back(_stack_manip, 1, *_stack); - stack::copy_and_push_back(_stack_manip, 0, *_stack); - _stack_manip.erase(); + stack::copy_and_push_back(_branch_stack, 2, *_stack); + stack::copy_and_push_back(_branch_stack, 1, *_stack); + stack::copy_and_push_back(_branch_stack, 0, *_stack); + (void)_branch_stack.pop_back(); + (void)_branch_stack.pop_back(); + (void)_branch_stack.pop_back(); } void depth(void) diff --git a/src/rpn-test.h b/src/rpn-test.h index 4ef1d4a..8f62c92 100644 --- a/src/rpn-test.h +++ b/src/rpn-test.h @@ -7,10 +7,10 @@ void sup(void) number* right = (number*)_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); + 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); + mpfr_set_si(left->_value.mpfr, 0, s_mpfr_rnd); } void sup_eq(void) @@ -22,10 +22,10 @@ void sup_eq(void) number* right = (number*)_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); + 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); + mpfr_set_si(left->_value.mpfr, 0, s_mpfr_rnd); } void inf(void) @@ -37,10 +37,10 @@ void inf(void) number* right = (number*)_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); + 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); + mpfr_set_si(left->_value.mpfr, 0, s_mpfr_rnd); } void inf_eq(void) @@ -52,10 +52,10 @@ void inf_eq(void) number* right = (number*)_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); + 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); + mpfr_set_si(left->_value.mpfr, 0, s_mpfr_rnd); } void diff(void) @@ -67,10 +67,10 @@ void diff(void) number* right = (number*)_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); + 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); + mpfr_set_si(left->_value.mpfr, 0, s_mpfr_rnd); } void eq(void) @@ -82,10 +82,10 @@ void eq(void) number* right = (number*)_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); + 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); + mpfr_set_si(left->_value.mpfr, 0, s_mpfr_rnd); } void test_and(void) @@ -97,11 +97,11 @@ void test_and(void) number* right = (number*)_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); + 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); + mpfr_set_si(left->_value.mpfr, 0, s_mpfr_rnd); } void test_or(void) @@ -113,11 +113,11 @@ void test_or(void) number* right = (number*)_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); + 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); + mpfr_set_si(left->_value.mpfr, 0, s_mpfr_rnd); } void test_xor(void) @@ -129,19 +129,19 @@ void test_xor(void) number* right = (number*)_stack->pop_back(); number* left = (number*)_stack->back(); - if (mpfr_cmp_si(&left->_value.mpfr, 0) == 0) + 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); + 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); + 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); + 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); + mpfr_set_si(left->_value.mpfr, 0, s_mpfr_rnd); } } @@ -151,10 +151,10 @@ void test_not(void) 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, s_mpfr_rnd); + 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); + mpfr_set_si(left->_value.mpfr, 0, s_mpfr_rnd); } void same(void) diff --git a/src/rpn-trig.h b/src/rpn-trig.h index 8ba911c..33c2d38 100644 --- a/src/rpn-trig.h +++ b/src/rpn-trig.h @@ -2,7 +2,7 @@ void pi(void) { number num; - CHECK_MPFR(mpfr_const_pi(&num._value.mpfr, s_mpfr_rnd)); + CHECK_MPFR(mpfr_const_pi(num._value.mpfr, s_mpfr_rnd)); _stack->push_back(&num, num.size(), cmd_number); ((number*)_stack->back())->ensure_significand(); } @@ -14,9 +14,9 @@ void d2r(void) 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)); + 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) @@ -26,9 +26,9 @@ void r2d(void) 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)); + 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) @@ -37,7 +37,7 @@ void rpn_sin(void) 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)); + CHECK_MPFR(mpfr_sin(left->mpfr, left->mpfr, s_mpfr_rnd)); } void rpn_asin(void) @@ -46,7 +46,7 @@ void rpn_asin(void) 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)); + CHECK_MPFR(mpfr_asin(left->mpfr, left->mpfr, s_mpfr_rnd)); } void rpn_cos(void) @@ -55,7 +55,7 @@ void rpn_cos(void) 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)); + CHECK_MPFR(mpfr_cos(left->mpfr, left->mpfr, s_mpfr_rnd)); } void rpn_acos(void) @@ -64,7 +64,7 @@ void rpn_acos(void) 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)); + CHECK_MPFR(mpfr_acos(left->mpfr, left->mpfr, s_mpfr_rnd)); } void rpn_tan(void) @@ -73,7 +73,7 @@ void rpn_tan(void) 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)); + CHECK_MPFR(mpfr_tan(left->mpfr, left->mpfr, s_mpfr_rnd)); } void rpn_atan(void) @@ -82,5 +82,5 @@ void rpn_atan(void) 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)); + CHECK_MPFR(mpfr_atan(left->mpfr, left->mpfr, s_mpfr_rnd)); } diff --git a/src/rpn.cpp b/src/rpn.cpp index 2e4b1d4..a16e9e8 100644 --- a/src/rpn.cpp +++ b/src/rpn.cpp @@ -106,52 +106,52 @@ typedef long long integer_t; // MPFR object struct floating_t { - __mpfr_struct mpfr; + mpfr_t mpfr; void init(void* significand) { mpfr_custom_init(significand, MPFR_128BITS_STORING_LENGTH); - mpfr_custom_init_set(&mpfr, MPFR_ZERO_KIND, 0, s_mpfr_prec, significand); + mpfr_custom_init_set(mpfr, MPFR_ZERO_KIND, 0, s_mpfr_prec, significand); } void set_significand(void* significand) { - mpfr._mpfr_d = (mp_limb_t*)significand; + mpfr->_mpfr_d = (mp_limb_t*)significand; } floating_t& operator=(const long int val) { - mpfr_set_si(&mpfr, val, s_mpfr_rnd); + mpfr_set_si(mpfr, val, s_mpfr_rnd); } floating_t& operator=(const unsigned long val) { - mpfr_set_ui(&mpfr, val, s_mpfr_rnd); + mpfr_set_ui(mpfr, val, s_mpfr_rnd); } floating_t& operator=(const integer_t val) { - mpfr_set_sj(&mpfr, val, s_mpfr_rnd); + mpfr_set_sj(mpfr, val, s_mpfr_rnd); } operator int() { - return (int)mpfr_get_si(&mpfr, s_mpfr_rnd); + return (int)mpfr_get_si(mpfr, s_mpfr_rnd); } void ensure_significand() { - //mpfr._mpfr_d = (mp_limb_t*)significand; + //mpfr->_mpfr_d = (mp_limb_t*)significand; } bool operator>(const floating_t right) { - return mpfr_cmp(&mpfr, &right.mpfr) > 0; + return mpfr_cmp(mpfr, right.mpfr) > 0; } bool operator<(const floating_t right) { - return mpfr_cmp(&mpfr, &right.mpfr) < 0; + return mpfr_cmp(mpfr, right.mpfr) < 0; } }; @@ -190,14 +190,14 @@ struct number : public object void copy(number& op) { _value = op._value; - memcpy(_value.mpfr._mpfr_d, op._value.mpfr._mpfr_d, MPFR_128BITS_STORING_LENGTH); + memcpy(_value.mpfr->_mpfr_d, op._value.mpfr->_mpfr_d, MPFR_128BITS_STORING_LENGTH); } // void set(const floating_t& value) { _type = cmd_number; - _value.mpfr._mpfr_d = value.mpfr._mpfr_d; + _value.mpfr->_mpfr_d = value.mpfr->_mpfr_d; } void set(long value) @@ -221,7 +221,7 @@ struct number : public object void ensure_significand() { - //_value.mpfr._mpfr_d = (mp_limb_t*)_value.significand; + //_value.mpfr->_mpfr_d = (mp_limb_t*)_value.significand; } // @@ -382,8 +382,8 @@ struct branch : public object arg1 = -1; arg2 = -1; arg3 = -1; - farg1 = 0L; - farg2 = 0L; + farg1 = NULL; + farg2 = NULL; arg_bool = 0; if (value != NULL) { @@ -401,7 +401,7 @@ struct branch : public object branch_fn_t _fn; // args used by cmd_branch cmds int arg1, arg2, arg3; - floating_t farg1, farg2; + number *farg1, *farg2; bool arg_bool; unsigned int _len; char _value[0]; @@ -415,7 +415,7 @@ void object::show(ostream& stream) { case cmd_number: //(void)mpfr_printf(s_mpfr_printf_format.c_str(), &((number*)this)->_value.mpfr); - (void)mpfr_sprintf(buffer, s_mpfr_printf_format.c_str(), &((number*)this)->_value.mpfr); + (void)mpfr_sprintf(buffer, s_mpfr_printf_format.c_str(), ((number*)this)->_value.mpfr); stream<get_type(num) != (type)) { ERR_CONTEXT(ret_bad_operand_type); return; } } while(0) #define ARG_MUST_BE_OF_TYPE_RET(num, type, ret) do { if (_stack->get_type(num) != (type)) { ERR_CONTEXT(ret_bad_operand_type); return (ret); } } while(0) #define IS_ARG_TYPE(num, type) (_stack->get_type(num) == (type)) - //TODO #define CHECK_MPFR(op) do { (void)(op); } while(0) // keywords implementation diff --git a/src/stack.h b/src/stack.h index a7f9d6d..0cac9b2 100644 --- a/src/stack.h +++ b/src/stack.h @@ -61,7 +61,7 @@ public: } } - // index_from is counted from back, last entry is 0 + // static void copy_and_push_back(stack& from, unsigned int index_from, stack& to) { // copy a whole stack entry (with blob) and push it back to another stack @@ -83,6 +83,7 @@ public: _base = (char*)realloc(_base, _total_size); _current = _base + offset; } + if (_current_blob + blob_size > _blob + _total_blob_size) { unsigned long offset = _current_blob - _blob; @@ -105,7 +106,6 @@ public: _vtype.push_back(type); _count++; -//cout<<__FUNCTION__<<": -> stack size is "<<_count<