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: angle and scm_flo0 Date: Fri, 18 Jul 2003 09:45:42 +1000 Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: <87fzl41zvd.fsf@zip.com.au> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: main.gmane.org 1058485718 21481 80.91.224.249 (17 Jul 2003 23:48:38 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Thu, 17 Jul 2003 23:48:38 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Fri Jul 18 01:48:32 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 19dIUC-0005Zb-00 for ; Fri, 18 Jul 2003 01:48:32 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.20) id 19dITJ-0006ua-5l for guile-devel@m.gmane.org; Thu, 17 Jul 2003 19:47:37 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.20) id 19dIS5-0006W4-V9 for guile-devel@gnu.org; Thu, 17 Jul 2003 19:46:21 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.20) id 19dIRw-0006R2-LI for guile-devel@gnu.org; Thu, 17 Jul 2003 19:46:12 -0400 Original-Received: from snoopy.pacific.net.au ([61.8.0.36]) by monty-python.gnu.org with esmtp (Exim 4.20) id 19dIRb-0006Hi-1m for guile-devel@gnu.org; Thu, 17 Jul 2003 19:45:51 -0400 Original-Received: from sunny.pacific.net.au (sunny.pacific.net.au [203.2.228.40]) by snoopy.pacific.net.au (8.12.3/8.12.3/Debian-6.3) with ESMTP id h6HNjmZY002551 for ; Fri, 18 Jul 2003 09:45:48 +1000 Original-Received: from wisma.pacific.net.au (wisma.pacific.net.au [210.23.129.72]) by sunny.pacific.net.au with ESMTP id h6HNjmQg004541 for ; Fri, 18 Jul 2003 09:45:48 +1000 (EST) Original-Received: from localhost (ppp74.dyn228.pacific.net.au [203.143.228.74]) by wisma.pacific.net.au (8.12.9/8.12.9) with ESMTP id h6HNjknh014948 for ; Fri, 18 Jul 2003 09:45:47 +1000 (EST) Original-Received: from gg by localhost with local (Exim 3.35 #1 (Debian)) id 19dIRT-0004T7-00; Fri, 18 Jul 2003 09:45:43 +1000 Original-To: guile-devel@gnu.org Mail-Copies-To: never User-Agent: Gnus/5.090019 (Oort Gnus v0.19) Emacs/21.2 (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:2630 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:2630 --=-=-= To save a bit of consing and calls to atan2, * numbers.c (scm_angle): Use scm_flo0 for non-negative inum, bignum and real. I guess the same can be done for negatives, returning pi. Would scm_sys_protects be the right place to add an scm_flo_pi? I see abs_most_negative_fixnum uses scm_permanent_object instead. For the actual pi value, I guess there'd be a choice between M_PI and the return from atan2(0.0,-1.0). The two ought to be the same of course. Maybe use the constant and have one of the tests see that atan2 agrees. --=-=-= Content-Disposition: attachment; filename=numbers.c.angle-flo0.diff --- numbers.c.~1.193.~ 2003-07-08 10:28:38.000000000 +1000 +++ numbers.c 2003-07-17 10:10:52.000000000 +1000 @@ -3947,7 +3947,7 @@ { if (SCM_INUMP (z)) { if (SCM_INUM (z) >= 0) { - return scm_make_real (atan2 (0.0, 1.0)); + return scm_flo0; } else { return scm_make_real (atan2 (0.0, -1.0)); } @@ -3957,10 +3957,13 @@ if (sgn < 0) { return scm_make_real (atan2 (0.0, -1.0)); } else { - return scm_make_real (atan2 (0.0, 1.0)); + return scm_flo0; } } else if (SCM_REALP (z)) { - return scm_make_real (atan2 (0.0, SCM_REAL_VALUE (z))); + if (SCM_REAL_VALUE (z) >= 0) + return scm_flo0; + else + return scm_make_real (atan2 (0.0, -1.0)); } else if (SCM_COMPLEXP (z)) { return scm_make_real (atan2 (SCM_COMPLEX_IMAG (z), SCM_COMPLEX_REAL (z))); } else { --=-=-= Content-Disposition: attachment; filename=angle.test (with-test-prefix "angle" (define pi 3.14159265358979323846) (define (almost= x y) (> 0.01 (magnitude (- x y)))) (pass-if "inum +ve" (= 0 (angle 1))) (pass-if "inum -ve" (almost= pi (angle -1))) (pass-if "bignum +ve" (= 0 (angle (1+ fixnum-max)))) (pass-if "bignum -ve" (almost= pi (angle (1- fixnum-min)))) (pass-if "flonum +ve" (= 0 (angle 1.5))) (pass-if "flonum -ve" (almost= pi (angle -1.5)))) --=-=-= 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 --=-=-=--