guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

guile accepts invalid complex number


From: Bruno Haible
Subject: guile accepts invalid complex number
Date: Mon, 17 Jan 2005 13:47:00 +0100
User-agent: KMail/1.5

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));
  }
  
  





reply via email to

[Prev in Thread] Current Thread [Next in Thread]