diff --git a/src/rpn-stack.h b/src/rpn-stack.h index 15945a1..4fcba65 100644 --- a/src/rpn-stack.h +++ b/src/rpn-stack.h @@ -78,7 +78,9 @@ void rot(void) void depth(void) { - number num; - num.set((long)_stack->size()); - _stack->push_back(&num, num.size(), cmd_number); + unsigned long depth = (unsigned long)_stack->size(); + void* significand; + number* num = (number*)_stack->allocate_back(sizeof(number), cmd_number, MPFR_128BITS_STORING_LENGTH, &significand); + num->init(significand); + num->set(depth); } diff --git a/src/rpn.cpp b/src/rpn.cpp index 04474a3..54c494e 100644 --- a/src/rpn.cpp +++ b/src/rpn.cpp @@ -120,15 +120,16 @@ struct floating_t 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 unsigned long val) + { + mpfr_set_ui(&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); } @@ -196,13 +197,20 @@ struct number : public object { _type = cmd_number; _value.mpfr._mpfr_d = value.mpfr._mpfr_d; - //(void)memcpy(_value.significand, value.significand, sizeof(_value.significand)); } + void set(long value) { _type = cmd_number; _value = value; } + + void set(unsigned long value) + { + _type = cmd_number; + _value = value; + } + void set(integer_t value) { _type = cmd_number; @@ -400,13 +408,18 @@ struct branch : public object void object::show(ostream& stream) { + char buffer[512]; + switch(_type) { case cmd_number: - (void)mpfr_printf(s_mpfr_printf_format.c_str(), &((number*)this)->_value.mpfr); + //(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); + stream<s_mode) {