#34: corrected mpfr issues

This commit is contained in:
Louis Rubet 2017-05-02 10:45:28 +02:00
parent db320874b6
commit 6fe768006a
3 changed files with 11 additions and 15 deletions

View file

@ -206,9 +206,9 @@ static bool get_symbol(const string& entry, program& prog, string& remaining_ent
if (entry_len>=1 && entry[0]=='\'')
{
// symbol entry, like 'toto'
if (entry_len == 1)
{
// void symbol entry, like '
// total object length
obj_len = sizeof(symbol)+1;
@ -218,6 +218,7 @@ static bool get_symbol(const string& entry, program& prog, string& remaining_ent
}
else
{
// symbol entry, like 'toto' or 'toto
int naked_entry_len;
// entry length without prefix / postfix
@ -336,17 +337,15 @@ static bool get_float(const string& entry, program& prog, string& remaining_entr
// detect the begining of a number, including nan, inf, @nan@, @inf@
if (entry.find_first_of("+-0123456789.ni@", 0) == 0)
{
void* significand;
number* num = (number*)prog.allocate_back((unsigned int)sizeof(number), cmd_number, MPFR_128BITS_STORING_LENGTH, &significand);
num->init(significand);
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);
if (endptr != entry.c_str())
if (endptr != NULL && endptr != entry.c_str())
{
ret = true;
// remaining string if any
if (endptr != NULL)
remaining_entry = endptr;
remaining_entry = endptr;
}
else
(void)prog.pop_back();

View file

@ -1,9 +1,8 @@
void rpn_e(void)
{
number num;
CHECK_MPFR(mpfr_const_euler(num._value.mpfr, s_mpfr_rnd));
_stack->push_back(&num, num.size(), cmd_number);
((number*)_stack->back())->ensure_significand();
number* euler = (number*)_stack->allocate_back(number::calc_size(), cmd_number);
euler->_value = 1L;
CHECK_MPFR(mpfr_exp(euler->_value.mpfr, euler->_value.mpfr, s_mpfr_rnd));
}
void rpn_log()

View file

@ -1,10 +1,8 @@
//
void pi(void)
{
number num;
CHECK_MPFR(mpfr_const_pi(num._value.mpfr, s_mpfr_rnd));
_stack->push_back(&num, num.size(), cmd_number);
((number*)_stack->back())->ensure_significand();
number* pi = (number*)_stack->allocate_back(number::calc_size(), cmd_number);
CHECK_MPFR(mpfr_const_pi(pi->_value.mpfr, s_mpfr_rnd));
}
void d2r(void)