#64: refactored constant.h

This commit is contained in:
RUBET Louis 2017-05-23 14:55:09 +02:00
parent e10161e42b
commit f0222643f4
5 changed files with 17 additions and 9 deletions

View file

@ -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" }

View file

@ -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

View file

@ -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)

View file

@ -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)
{

View file

@ -41,11 +41,11 @@ extern "C" {
#include <fstream>
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;
//