From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Kevin Ryde Newsgroups: gmane.lisp.guile.devel Subject: Re: real == frac Date: Tue, 17 Feb 2004 09:09:23 +1000 Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: <87ptcevcyk.fsf@zip.com.au> References: <87u14xphf4.fsf@zip.com.au> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: sea.gmane.org 1076973328 19892 80.91.224.253 (16 Feb 2004 23:15:28 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 16 Feb 2004 23:15:28 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Tue Feb 17 00:15:19 2004 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1AsrxP-0004RD-00 for ; Tue, 17 Feb 2004 00:15:19 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1Asruk-0004S0-Qj for guile-devel@m.gmane.org; Mon, 16 Feb 2004 18:12:34 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.24) id 1AsrsZ-0002xb-MJ for guile-devel@gnu.org; Mon, 16 Feb 2004 18:10:19 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1Asrrq-0002IW-FL for guile-devel@gnu.org; Mon, 16 Feb 2004 18:10:08 -0500 Original-Received: from [61.8.0.85] (helo=mailout2.pacific.net.au) by monty-python.gnu.org with esmtp (Exim 4.24) id 1Asrrp-0002Gb-AR for guile-devel@gnu.org; Mon, 16 Feb 2004 18:09:33 -0500 Original-Received: from mailproxy2.pacific.net.au (mailproxy2.pacific.net.au [61.8.0.87]) by mailout2.pacific.net.au (8.12.3/8.12.3/Debian-6.6) with ESMTP id i1GN9U5O016081 for ; Tue, 17 Feb 2004 10:09:30 +1100 Original-Received: from localhost (ppp88.dyn250.pacific.net.au [203.143.250.88]) by mailproxy2.pacific.net.au (8.12.3/8.12.3/Debian-6.6) with ESMTP id i1GN9Tcg005639 for ; Tue, 17 Feb 2004 10:09:29 +1100 Original-Received: from gg by localhost with local (Exim 3.36 #1 (Debian)) id 1Asrrf-0001Te-00; Tue, 17 Feb 2004 09:09:23 +1000 Original-To: guile-devel@gnu.org Mail-Copies-To: never User-Agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3 (gnu/linux) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Developers list for Guile, the GNU extensibility library List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.devel:3393 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:3393 --=-=-= * numbers.c (scm_num_eq_p): For real==frac, complex==frac, frac==real and frac==complex, make an exact comparison rather than converting with fraction2double. I've added code under the complex cases because it was there already. But I might have mentioned before that I thought all those could be false immediately, if COMPLEXP always has a non-zero imaginary part. --=-=-= Content-Disposition: inline; filename=numbers.c.eq-frac.diff --- numbers.c.~1.221.~ 2004-01-07 07:54:59.000000000 +1000 +++ numbers.c 2004-02-12 11:58:18.000000000 +1000 @@ -2945,6 +2945,7 @@ SCM scm_num_eq_p (SCM x, SCM y) { + again: if (SCM_INUMP (x)) { long xx = SCM_INUM (x); @@ -3019,7 +3020,15 @@ return SCM_BOOL ((SCM_REAL_VALUE (x) == SCM_COMPLEX_REAL (y)) && (0.0 == SCM_COMPLEX_IMAG (y))); else if (SCM_FRACTIONP (y)) - return SCM_BOOL (SCM_REAL_VALUE (x) == scm_i_fraction2double (y)); + { + double xx = SCM_REAL_VALUE (x); + if (xisnan (xx)) + return SCM_BOOL_F; + if (xisinf (xx)) + return SCM_BOOL (xx < 0.0); + x = scm_inexact_to_exact (x); /* with x as frac or int */ + goto again; + } else SCM_WTA_DISPATCH_2 (g_eq_p, x, y, SCM_ARGn, s_eq_p); } @@ -3046,8 +3055,18 @@ return SCM_BOOL ((SCM_COMPLEX_REAL (x) == SCM_COMPLEX_REAL (y)) && (SCM_COMPLEX_IMAG (x) == SCM_COMPLEX_IMAG (y))); else if (SCM_FRACTIONP (y)) - return SCM_BOOL ((SCM_COMPLEX_REAL (x) == scm_i_fraction2double (y)) - && (SCM_COMPLEX_IMAG (x) == 0.0)); + { + double xx; + if (SCM_COMPLEX_IMAG (x) != 0.0) + return SCM_BOOL_F; + xx = SCM_COMPLEX_REAL (x); + if (xisnan (xx)) + return SCM_BOOL_F; + if (xisinf (xx)) + return SCM_BOOL (xx < 0.0); + x = scm_inexact_to_exact (x); /* with x as frac or int */ + goto again; + } else SCM_WTA_DISPATCH_2 (g_eq_p, x, y, SCM_ARGn, s_eq_p); } @@ -3058,10 +3077,28 @@ else if (SCM_BIGP (y)) return SCM_BOOL_F; else if (SCM_REALP (y)) - return SCM_BOOL (scm_i_fraction2double (x) == SCM_REAL_VALUE (y)); + { + double yy = SCM_REAL_VALUE (y); + if (xisnan (yy)) + return SCM_BOOL_F; + if (xisinf (yy)) + return SCM_BOOL (0.0 < yy); + y = scm_inexact_to_exact (y); /* with y as frac or int */ + goto again; + } else if (SCM_COMPLEXP (y)) - return SCM_BOOL ((scm_i_fraction2double (x) == SCM_COMPLEX_REAL (y)) - && (0.0 == SCM_COMPLEX_IMAG (y))); + { + double yy; + if (SCM_COMPLEX_IMAG (y) != 0.0) + return SCM_BOOL_F; + yy = SCM_COMPLEX_REAL (y); + if (xisnan (yy)) + return SCM_BOOL_F; + if (xisinf (yy)) + return SCM_BOOL (0.0 < yy); + y = scm_inexact_to_exact (y); /* with y as frac or int */ + goto again; + } else if (SCM_FRACTIONP (y)) return scm_i_fraction_equalp (x, y); else --=-=-= Content-Disposition: inline; filename=numbers.test.eq-frac.diff --- numbers.test.~1.40.~ 2003-12-09 15:06:40.000000000 +1000 +++ numbers.test 2004-02-17 09:07:42.000000000 +1000 @@ -1308,7 +1308,25 @@ ;; in gmp prior to 4.2, mpz_cmp_d ended up treating NaN as 3*2^1023, make ;; sure we've avoided that (pass-if (not (= (ash 3 1023) +nan.0))) - (pass-if (not (= +nan.0 (ash 3 1023))))) + (pass-if (not (= +nan.0 (ash 3 1023)))) + + (pass-if (= 1/2 0.5)) + (pass-if (not (= 1/3 0.333333333333333333333333333333333))) + (pass-if (not (= 2/3 0.5))) + (pass-if (not (= 0.5 (+ 1/2 (/ 1 (ash 1 1000)))))) + + (pass-if (= 1/2 0.5+0i)) + (pass-if (not (= 0.333333333333333333333333333333333 1/3))) + (pass-if (not (= 2/3 0.5+0i))) + (pass-if (not (= 1/2 0+0.5i))) + + (pass-if (= 0.5 1/2)) + (pass-if (not (= 0.5 2/3))) + (pass-if (not (= (+ 1/2 (/ 1 (ash 1 1000))) 0.5))) + + (pass-if (= 0.5+0i 1/2)) + (pass-if (not (= 0.5+0i 2/3))) + (pass-if (not (= 0+0.5i 1/2)))) ;;; ;;; < --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel --=-=-=--