diff --git a/src/constant.h b/src/constant.h index 280a717..5714513 100644 --- a/src/constant.h +++ b/src/constant.h @@ -1,25 +1,33 @@ +// default values +// + // default mode and number of printed digits // #define DEFAULT_MODE number::std #define DEFAULT_PRECISION 20 +#define MPFR_DEFAULT_FORMAT "%.20Rg" -// MPFR related constants +// MPFR related defaults // // rounding method -#define MPFR_DEF_RND MPFR_RNDN +#define MPFR_DEFAULT_RND MPFR_RNDN + // 128 bits significand precision #define MPFR_DEFAULT_PREC_BITS 128 + // 128 bits significand storing length in bytes, result of mpfr_custom_get_size(128) #define MPFR_DEFAULT_STORING_LENGTH_BYTES 16 +// constants +// + // show formats #define MPFR_FORMAT_BEG "%." #define MPFR_FORMAT_STD "Rg" #define MPFR_FORMAT_FIX "Rf" #define MPFR_FORMAT_SCI "Re" #define MPFR_FORMAT_HEX "%Ra" -#define MPFR_FORMAT "%.20Rg" #define MPFR_RND_STRINGS { "nearest", "toward zero", "toward +inf", "toward -inf", "away from zero" } diff --git a/src/parse.h b/src/parse.h index 7a86fce..7a314a1 100644 --- a/src/parse.h +++ b/src/parse.h @@ -340,7 +340,7 @@ static bool get_number(const string& entry, program& prog, string& remaining_ent { number* num = (number*)prog.allocate_back(number::calc_size(), cmd_number); - 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_DEFAULT_RND); if (endptr != NULL && endptr != entry.c_str()) { // determine representation diff --git a/src/rpn-branch.h b/src/rpn-branch.h index 4078f79..ce1181d 100644 --- a/src/rpn-branch.h +++ b/src/rpn-branch.h @@ -125,7 +125,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_DEFAULT_RND); // for command: increment symbol too if (start_or_for->arg1 != -1) @@ -181,7 +181,7 @@ int rpn_step(branch& myobj) } // increment then test - mpfr_add(myobj.farg1->_value.mpfr, myobj.farg1->_value.mpfr, step->_value.mpfr, MPFR_DEF_RND); + mpfr_add(myobj.farg1->_value.mpfr, myobj.farg1->_value.mpfr, step->_value.mpfr, MPFR_DEFAULT_RND); // for command: increment symbol too if (start_or_for->arg1 != -1) diff --git a/src/rpn-general.h b/src/rpn-general.h index d99ab69..5da11a4 100644 --- a/src/rpn-general.h +++ b/src/rpn-general.h @@ -168,7 +168,7 @@ void round() ostring* str = (ostring*)_stack->pop_back(); bool done = false; - for(int rnd = (int)MPFR_DEF_RND; rnd <= (int)MPFR_RNDA; rnd++) + for(int rnd = (int)MPFR_DEFAULT_RND; rnd <= (int)MPFR_RNDA; rnd++) { if (string(s_mpfr_rnd_str[rnd]) == str->_value) { diff --git a/src/rpn.cpp b/src/rpn.cpp index 0d1db54..383004b 100644 --- a/src/rpn.cpp +++ b/src/rpn.cpp @@ -41,11 +41,11 @@ extern "C" { #include using namespace std; -static string s_mpfr_printf_format = string(MPFR_FORMAT); +static string s_mpfr_printf_format = string(MPFR_DEFAULT_FORMAT); static mpfr_prec_t s_mpfr_prec = MPFR_DEFAULT_PREC_BITS; static unsigned int s_mpfr_prec_bytes = MPFR_DEFAULT_STORING_LENGTH_BYTES; -static mpfr_rnd_t s_mpfr_rnd = MPFR_DEF_RND; +static mpfr_rnd_t s_mpfr_rnd = MPFR_DEFAULT_RND; static const char* s_mpfr_rnd_str[5] = MPFR_RND_STRINGS; //