* guile accepts invalid complex number syntax
@ 2005-01-17 12:48 Bruno Haible
2005-01-17 17:54 ` Marius Vollmer
0 siblings, 1 reply; 2+ messages in thread
From: Bruno Haible @ 2005-01-17 12:48 UTC (permalink / raw)
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-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: guile accepts invalid complex number syntax
2005-01-17 12:48 guile accepts invalid complex number syntax Bruno Haible
@ 2005-01-17 17:54 ` Marius Vollmer
0 siblings, 0 replies; 2+ messages in thread
From: Marius Vollmer @ 2005-01-17 17:54 UTC (permalink / raw)
Cc: guile-devel
Bruno Haible <bruno@clisp.org> writes:
> Seen with guile-1.6.4:
>
> $ guile
> guile> 1.2+3.4+0ii
> 1.2+3.4i
Thanks for this report!
We have a completely new number parser in the 1.7 series (which is to
be released soonish, hopefully) that handles these cases fine.
The question now is should we port it back to 1.6 and risk the
instability that this might cause?
Right now, I'd say that we should leave 1.6 buggy, since no sane
program should be using symbols like '1.2+3.4+0ii'.
Opinions?
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-01-17 17:54 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-01-17 12:48 guile accepts invalid complex number syntax Bruno Haible
2005-01-17 17:54 ` Marius Vollmer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).