diff --git a/src/rpn-cmd.h b/src/rpn-cmd.h index abf966b..49dcb09 100644 --- a/src/rpn-cmd.h +++ b/src/rpn-cmd.h @@ -33,9 +33,9 @@ program::keyword_t program::_keywords[] = //REAL representation { cmd_undef, "", NULL, "\nREAL REPRESENTATION"}, - //{ cmd_keyword, "dec", &program::dec, "decimal representation" }, - //{ cmd_keyword, "hex", &program::hex, "hexadecimal representation" }, - //{ cmd_keyword, "bin", &program::bin, "binary representation" }, + { cmd_keyword, "dec", &program::dec, "decimal representation" }, + { cmd_keyword, "hex", &program::hex, "hexadecimal representation" }, + { cmd_keyword, "bin", &program::bin, "binary representation" }, { cmd_keyword, "std", &program::std, "standard floating numbers representation. ex: [25] std" }, { cmd_keyword, "fix", &program::fix, "fixed point representation. ex: 6 fix" }, { cmd_keyword, "sci", &program::sci, "scientific floating point representation. ex: 20 sci" }, diff --git a/src/rpn-real.h b/src/rpn-real.h index 369660d..7969005 100644 --- a/src/rpn-real.h +++ b/src/rpn-real.h @@ -126,3 +126,24 @@ void modulo() CHECK_MPFR(mpfr_fmod(left->_value.mpfr, left->_value.mpfr, right->_value.mpfr, s_mpfr_rnd)); } + +void hex() +{ + MIN_ARGUMENTS(1); + ARG_MUST_BE_OF_TYPE(0, cmd_number); + ((number*)_stack->back())->_representation = number::hex; +} + +void bin() +{ + MIN_ARGUMENTS(1); + ARG_MUST_BE_OF_TYPE(0, cmd_number); + ((number*)_stack->back())->_representation = number::bin; +} + +void dec() +{ + MIN_ARGUMENTS(1); + ARG_MUST_BE_OF_TYPE(0, cmd_number); + ((number*)_stack->back())->_representation = number::dec; +} diff --git a/src/rpn.cpp b/src/rpn.cpp index 140b78b..a76cd4e 100644 --- a/src/rpn.cpp +++ b/src/rpn.cpp @@ -48,12 +48,11 @@ using namespace std; #define MPFR_128BITS_PREC 128 #define MPFR_128BITS_STORING_LENGTH 16 -static string s_mpfr_printf_format_hex = "0x"; -static string s_mpfr_printf_format_bin = "0b"; static string s_mpfr_printf_format_beg = "%."; static string s_mpfr_printf_format_std = "Rg"; static string s_mpfr_printf_format_fix = "Rf"; static string s_mpfr_printf_format_sci = "Re"; +static string s_mpfr_printf_format_hex = "%Ra"; static string s_mpfr_printf_format = "%.12Rg"; static mpfr_prec_t s_mpfr_prec = MPFR_128BITS_PREC; static mpfr_rnd_t s_mpfr_rnd = MPFR_DEF_RND; @@ -373,8 +372,19 @@ void object::show(ostream& stream) switch(_type) { case cmd_number: - (void)mpfr_sprintf(buffer, s_mpfr_printf_format.c_str(), ((number*)this)->_value.mpfr); - stream<_representation) + { + case number::dec: + (void)mpfr_sprintf(buffer, s_mpfr_printf_format.c_str(), ((number*)this)->_value.mpfr); + stream<_value.mpfr); + stream<"; + } break; case cmd_string: stream << "\"" << ((ostring*)this)->_value << "\"";