1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 20:00:19 +02:00

* numbers.c (mem2decimal_from_point): Cleaned up the parsing a

little bit - should even be somewhat more accurate now.
This commit is contained in:
Dirk Herrmann 2001-10-09 20:56:36 +00:00
parent d918965272
commit 79d34f68e7
2 changed files with 16 additions and 15 deletions

View file

@ -1,3 +1,8 @@
2001-10-09 Dirk Herrmann <D.Herrmann@tu-bs.de>
* numbers.c (mem2decimal_from_point): Cleaned up the parsing a
little bit - should even be somewhat more accurate now.
2001-10-08 Rob Browning <rlb@defaultvalue.org> 2001-10-08 Rob Browning <rlb@defaultvalue.org>
* gc.c: support ia64 register backing store. * gc.c: support ia64 register backing store.

View file

@ -39,7 +39,6 @@
* whether to permit this exception to apply to your modifications. * whether to permit this exception to apply to your modifications.
* If you do not wish that, delete this exception notice. */ * If you do not wish that, delete this exception notice. */
#include <math.h> #include <math.h>
@ -2343,31 +2342,29 @@ mem2uinteger (const char* mem, size_t len, unsigned int *p_idx,
/* R5RS, section 7.1.1, lexical structure of numbers: <decimal 10>. Only /* R5RS, section 7.1.1, lexical structure of numbers: <decimal 10>. Only
* covers the parts of the rules that start at a potential point. The value * covers the parts of the rules that start at a potential point. The value
* of the digits up to the point have been parsed by the caller and are given * of the digits up to the point have been parsed by the caller and are given
* in variable prepoint. The content of *p_exactness indicates, whether a * in variable result. The content of *p_exactness indicates, whether a hash
* hash has already been seen in the digits before the point. * has already been seen in the digits before the point.
*/ */
/* In non ASCII-style encodings the following macro might not work. */ /* In non ASCII-style encodings the following macro might not work. */
#define DIGIT2UINT(d) ((d) - '0') #define DIGIT2UINT(d) ((d) - '0')
static SCM static SCM
mem2decimal_from_point (SCM prepoint, const char* mem, size_t len, mem2decimal_from_point (SCM result, const char* mem, size_t len,
unsigned int *p_idx, enum t_exactness *p_exactness) unsigned int *p_idx, enum t_exactness *p_exactness)
{ {
unsigned int idx = *p_idx; unsigned int idx = *p_idx;
enum t_exactness x = *p_exactness; enum t_exactness x = *p_exactness;
SCM big_shift = SCM_MAKINUM (1);
SCM big_add = SCM_MAKINUM (0);
SCM result;
if (idx == len) if (idx == len)
return prepoint; return result;
if (mem[idx] == '.') if (mem[idx] == '.')
{ {
scm_t_bits shift = 1; scm_t_bits shift = 1;
scm_t_bits add = 0; scm_t_bits add = 0;
unsigned int digit_value; unsigned int digit_value;
SCM big_shift = SCM_MAKINUM (1);
idx++; idx++;
while (idx != len) while (idx != len)
@ -2392,9 +2389,9 @@ mem2decimal_from_point (SCM prepoint, const char* mem, size_t len,
if (SCM_MOST_POSITIVE_FIXNUM / 10 < shift) if (SCM_MOST_POSITIVE_FIXNUM / 10 < shift)
{ {
big_shift = scm_product (big_shift, SCM_MAKINUM (shift)); big_shift = scm_product (big_shift, SCM_MAKINUM (shift));
big_add = scm_product (big_add, SCM_MAKINUM (shift)); result = scm_product (result, SCM_MAKINUM (shift));
if (add > 0) if (add > 0)
big_add = scm_sum (big_add, SCM_MAKINUM (add)); result = scm_sum (result, SCM_MAKINUM (add));
shift = 10; shift = 10;
add = digit_value; add = digit_value;
@ -2409,17 +2406,16 @@ mem2decimal_from_point (SCM prepoint, const char* mem, size_t len,
if (add > 0) if (add > 0)
{ {
big_shift = scm_product (big_shift, SCM_MAKINUM (shift)); big_shift = scm_product (big_shift, SCM_MAKINUM (shift));
big_add = scm_product (big_add, SCM_MAKINUM (shift)); result = scm_product (result, SCM_MAKINUM (shift));
big_add = scm_sum (big_add, SCM_MAKINUM (add)); result = scm_sum (result, SCM_MAKINUM (add));
} }
result = scm_divide (result, big_shift);
/* We've seen a decimal point, thus the value is implicitly inexact. */ /* We've seen a decimal point, thus the value is implicitly inexact. */
x = INEXACT; x = INEXACT;
} }
big_add = scm_divide (big_add, big_shift);
result = scm_sum (prepoint, big_add);
if (idx != len) if (idx != len)
{ {
int sign = 1; int sign = 1;