1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-08 22:22:26 +02:00

Read complex numbers where both parts are inexact decimals

Thanks to Bill Schottstaedt for reporting this problem!

* libguile/numbers.c (mem2ureal): Don't be misled by *p_exactness
  being INEXACT on entry (as is possible when reading a complex
  number): use local exactness variable x which starts as EXACT.
  Call mem2decimal_from_point () with &x instead of p_exactness.

* test-suite/tests/numbers.test ("string->number"): Add complex number
  tests suggested by Bill.
This commit is contained in:
Neil Jerram 2009-07-01 01:39:24 +01:00
parent c7c36fcf40
commit 04f9bc774a
3 changed files with 22 additions and 7 deletions

View file

@ -2739,6 +2739,10 @@ mem2ureal (const char* mem, size_t len, unsigned int *p_idx,
unsigned int idx = *p_idx;
SCM result;
/* Start off believing that the number will be exact. This changes
to INEXACT if we see a decimal point or a hash. */
enum t_exactness x = EXACT;
if (idx == len)
return SCM_BOOL_F;
@ -2750,8 +2754,6 @@ mem2ureal (const char* mem, size_t len, unsigned int *p_idx,
if (idx+4 < len && !strncmp (mem+idx, "nan.", 4))
{
enum t_exactness x = EXACT;
/* Cobble up the fractional part. We might want to set the
NaN's mantissa from it. */
idx += 4;
@ -2770,11 +2772,10 @@ mem2ureal (const char* mem, size_t len, unsigned int *p_idx,
return SCM_BOOL_F;
else
result = mem2decimal_from_point (SCM_I_MAKINUM (0), mem, len,
p_idx, p_exactness);
p_idx, &x);
}
else
{
enum t_exactness x = EXACT;
SCM uinteger;
uinteger = mem2uinteger (mem, len, &idx, radix, &x);
@ -2806,10 +2807,16 @@ mem2ureal (const char* mem, size_t len, unsigned int *p_idx,
result = uinteger;
*p_idx = idx;
if (x == INEXACT)
*p_exactness = x;
}
/* Update *p_exactness if the number just read was inexact. This is
important for complex numbers, so that a complex number is
treated as inexact overall if either its real or imaginary part
is inexact.
*/
if (x == INEXACT)
*p_exactness = x;
/* When returning an inexact zero, make sure it is represented as a
floating point value so that we can change its sign.
*/