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: scm_round_number using scm_round Date: Mon, 17 May 2004 09:12:14 +1000 Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: <87k6zcvuep.fsf@zip.com.au> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: sea.gmane.org 1084749320 17716 80.91.224.253 (16 May 2004 23:15:20 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 16 May 2004 23:15:20 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Mon May 17 01:15:12 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 1BPUqd-0000mj-00 for ; Mon, 17 May 2004 01:15:12 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.34) id 1BPUpf-0004Ql-BN for guile-devel@m.gmane.org; Sun, 16 May 2004 19:14:11 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.34) id 1BPUpV-0004KN-Jc for guile-devel@gnu.org; Sun, 16 May 2004 19:14:01 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.34) id 1BPUoo-0003SX-Sp for guile-devel@gnu.org; Sun, 16 May 2004 19:13:51 -0400 Original-Received: from [61.8.0.85] (helo=mailout2.pacific.net.au) by monty-python.gnu.org with esmtp (Exim 4.34) id 1BPUoj-0003Qo-Na for guile-devel@gnu.org; Sun, 16 May 2004 19:13:18 -0400 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 i4GND56r000466 for ; Mon, 17 May 2004 09:13:12 +1000 Original-Received: from localhost (ppp2C35.dyn.pacific.net.au [61.8.44.53]) by mailproxy2.pacific.net.au (8.12.3/8.12.3/Debian-6.6) with ESMTP id i4GNCKLR000336 for ; Mon, 17 May 2004 09:12:20 +1000 Original-Received: from gg by localhost with local (Exim 3.36 #1 (Debian)) id 1BPUnn-0007lF-00; Mon, 17 May 2004 09:12:15 +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.4 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:3726 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:3726 --=-=-= * numbers.c (scm_round_number): For inum and big, just return x. For real, use scm_round for problems with 2^54-1 etc covered there. The problem that afflicted scm_round arises in the same algorithm done with SCMs in scm_round_number. I think it can call scm_round to share code. --=-=-= Content-Disposition: attachment; filename=numbers.c.round-number.diff --- numbers.c.~1.243.~ 2004-05-12 07:19:25.000000000 +1000 +++ numbers.c 2004-05-17 07:36:30.000000000 +1000 @@ -5007,6 +5007,15 @@ "round towards the even one.") #define FUNC_NAME s_scm_round_number { + if (SCM_INUMP (x) || SCM_BIGP (x)) + return x; + else if (SCM_REALP (x)) + return scm_make_real (scm_round (SCM_REAL_VALUE (x))); + else + { + /* OPTIMIZE-ME: Fraction case could be done more efficiently by a + single quotient+remainder division then examining to see which way + the rounding should go. */ SCM plus_half = scm_sum (x, exactly_one_half); SCM result = scm_floor (plus_half); /* Adjust so that the scm_round is towards even. */ @@ -5015,6 +5024,7 @@ return scm_difference (result, SCM_MAKINUM (1)); else return result; + } } #undef FUNC_NAME --=-=-= 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 --=-=-=--