From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Bruno Haible Newsgroups: gmane.lisp.guile.devel Subject: guile accepts invalid complex number syntax Date: Mon, 17 Jan 2005 13:48:00 +0100 Message-ID: <200501171348.00544.bruno@clisp.org> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1105966706 9045 80.91.229.6 (17 Jan 2005 12:58:26 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 17 Jan 2005 12:58:26 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Mon Jan 17 13:58:16 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1CqWSW-0002ax-00 for ; Mon, 17 Jan 2005 13:58:16 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1CqWeN-00067q-A4 for guile-devel@m.gmane.org; Mon, 17 Jan 2005 08:10:31 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1CqWb7-0004jj-6s for guile-devel@gnu.org; Mon, 17 Jan 2005 08:07:09 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1CqWYK-0003qc-Nu for guile-devel@gnu.org; Mon, 17 Jan 2005 08:04:17 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1CqWYJ-0003pb-UA for guile-devel@gnu.org; Mon, 17 Jan 2005 08:04:16 -0500 Original-Received: from [81.80.162.195] (helo=ftp.ilog.fr) by monty-python.gnu.org with esmtp (Exim 4.34) id 1CqWLR-0001P2-05 for guile-devel@gnu.org; Mon, 17 Jan 2005 07:50:57 -0500 Original-Received: from laposte.ilog.fr (cerbere-qfe0 [81.80.162.193]) by ftp.ilog.fr (8.13.1/8.13.0) with ESMTP id j0HCotmC007392 for ; Mon, 17 Jan 2005 13:50:55 +0100 (MET) Original-Received: from honolulu.ilog.fr ([172.16.15.122]) by laposte.ilog.fr (8.13.1/8.13.1) with ESMTP id j0HCooiE021133; Mon, 17 Jan 2005 13:50:50 +0100 (MET) Original-Received: from localhost (localhost [127.0.0.1]) by honolulu.ilog.fr (Postfix) with ESMTP id 6D57E17723; Mon, 17 Jan 2005 12:48:01 +0000 (UTC) Original-To: guile-devel@gnu.org User-Agent: KMail/1.5 Content-Disposition: inline X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.devel:4684 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:4684 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