[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
guile accepts invalid complex number syntax
From: |
Bruno Haible |
Subject: |
guile accepts invalid complex number syntax |
Date: |
Mon, 17 Jan 2005 13:48:00 +0100 |
User-agent: |
KMail/1.5 |
Seen with guile-1.6.4:
$ guile
guile> 1.2+3.4+0ii
1.2+3.4i
This should be parsed as a symbol, not as a number (according to
r5rs.info node "Lexical structure").
Here is an (untested) suggestion for a fix.
*** libguile/numbers.c 2005-01-16 15:58:44.000000000 +0100
--- libguile/numbers.c.new 2005-01-16 16:34:37.000000000 +0100
***************
*** 2401,2407 ****
}
SCM
! scm_istr2flo (char *str, long len, long radix)
{
register int c, i = 0;
double lead_sgn;
--- 2401,2407 ----
}
SCM
! scm_istr2flo (char *str, long len, long radix, int allow_complex)
{
register int c, i = 0;
double lead_sgn;
***************
*** 2429,2435 ****
if (i == len)
return SCM_BOOL_F; /* bad if lone `+' or `-' */
! if (str[i] == 'i' || str[i] == 'I')
{ /* handle `+i' and `-i' */
if (lead_sgn == 0.0)
return SCM_BOOL_F; /* must have leading sign */
--- 2429,2435 ----
if (i == len)
return SCM_BOOL_F; /* bad if lone `+' or `-' */
! if (allow_complex && (str[i] == 'i' || str[i] == 'I'))
{ /* handle `+i' and `-i' */
if (lead_sgn == 0.0)
return SCM_BOOL_F; /* must have leading sign */
***************
*** 2636,2641 ****
--- 2636,2644 ----
if (i == len)
return scm_make_real (res);
+ if (!allow_complex)
+ return SCM_BOOL_F;
+
if (str[i] == 'i' || str[i] == 'I')
{ /* pure imaginary number */
if (lead_sgn == 0.0)
***************
*** 2656,2662 ****
case '@':
{ /* polar input for complex number */
/* get a `real' for scm_angle */
! second = scm_istr2flo (&str[i], (long) (len - i), radix);
if (!SCM_SLOPPY_INEXACTP (second))
return SCM_BOOL_F; /* not `real' */
if (SCM_SLOPPY_COMPLEXP (second))
--- 2659,2665 ----
case '@':
{ /* polar input for complex number */
/* get a `real' for scm_angle */
! second = scm_istr2flo (&str[i], (long) (len - i), radix, 0);
if (!SCM_SLOPPY_INEXACTP (second))
return SCM_BOOL_F; /* not `real' */
if (SCM_SLOPPY_COMPLEXP (second))
***************
*** 2675,2681 ****
if (i == (len - 1))
return scm_make_complex (res, lead_sgn);
/* get a `real' for imaginary part */
! second = scm_istr2flo (&str[i - 1], (long) (len - i), radix);
if (!SCM_INEXACTP (second))
return SCM_BOOL_F; /* not `ureal' */
if (SCM_SLOPPY_COMPLEXP (second))
--- 2678,2684 ----
if (i == (len - 1))
return scm_make_complex (res, lead_sgn);
/* get a `real' for imaginary part */
! second = scm_istr2flo (&str[i - 1], (long) (len - i), radix, 0);
if (!SCM_INEXACTP (second))
return SCM_BOOL_F; /* not `ureal' */
if (SCM_SLOPPY_COMPLEXP (second))
***************
*** 2748,2754 ****
if (!SCM_FALSEP (res))
return res;
case 2:
! return scm_istr2flo (&str[i], len - i, radix);
}
return SCM_BOOL_F;
}
--- 2751,2757 ----
if (!SCM_FALSEP (res))
return res;
case 2:
! return scm_istr2flo (&str[i], len - i, radix, 1);
}
return SCM_BOOL_F;
}
- guile accepts invalid complex number syntax,
Bruno Haible <=