unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* guile accepts invalid complex number
@ 2005-01-17 12:47 Bruno Haible
  0 siblings, 0 replies; only message in thread
From: Bruno Haible @ 2005-01-17 12:47 UTC (permalink / raw)


Hi,

guile-1.6.4 interprets a token of the form
    <real> + - 0 i
or
    <real> - + 0 i
as complex number, although it does not conform to the <complex> syntax
documented in r5rs.info node "Lexical structure". It should interpret it
as a symbol instead.

To reproduce:
$ guile
guile> 3.4+-0.0i
3.4
guile> 3.4-+0.0i
3.4

Here is an (untested) suggestion for a fix.

*** libguile/numbers.c	2002-12-07 23:41:32.000000000 +0100
--- libguile/numbers.c.new	2005-01-16 15:58:44.000000000 +0100
***************
*** 2674,2689 ****
    /* handles `x+i' and `x-i' */
    if (i == (len - 1))
      return scm_make_complex (res, lead_sgn);
!   /* get a `ureal' for complex part */
!   second = scm_istr2flo (&str[i], (long) ((len - i) - 1), radix);
    if (!SCM_INEXACTP (second))
      return SCM_BOOL_F;		/* not `ureal' */
    if (SCM_SLOPPY_COMPLEXP (second))
      return SCM_BOOL_F;		/* not `ureal' */
!   tmp = SCM_REAL_VALUE (second);
!   if (tmp < 0.0)
!     return SCM_BOOL_F;		/* not `ureal' */
!   return scm_make_complex (res, (lead_sgn * tmp));
  }
  
  
--- 2674,2686 ----
    /* handles `x+i' and `x-i' */
    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))
      return SCM_BOOL_F;		/* not `ureal' */
!   return scm_make_complex (res, SCM_REAL_VALUE (second));
  }
  
  



_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-01-17 12:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-01-17 12:47 guile accepts invalid complex number Bruno Haible

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).