From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Emsley Newsgroups: gmane.lisp.guile.user Subject: Re: strange behaviour of (floor .) Date: Mon, 28 Dec 2009 19:42:35 +0000 Message-ID: <4B390A2B.1020501@bioch.ox.ac.uk> References: <20091228170236.GA27921@shoikan.fritz.box> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1262029406 26762 80.91.229.12 (28 Dec 2009 19:43:26 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 28 Dec 2009 19:43:26 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Mon Dec 28 20:43:19 2009 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1NPLUs-00051X-Op for guile-user@m.gmane.org; Mon, 28 Dec 2009 20:43:19 +0100 Original-Received: from localhost ([127.0.0.1]:40444 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NPLUt-0006vX-64 for guile-user@m.gmane.org; Mon, 28 Dec 2009 14:43:19 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NPLUd-0006vI-Lv for guile-user@gnu.org; Mon, 28 Dec 2009 14:43:03 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NPLUc-0006tU-13 for guile-user@gnu.org; Mon, 28 Dec 2009 14:43:03 -0500 Original-Received: from [199.232.76.173] (port=52281 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NPLUb-0006tO-Sz for guile-user@gnu.org; Mon, 28 Dec 2009 14:43:01 -0500 Original-Received: from smtp817.mail.ird.yahoo.com ([77.238.189.17]:44897) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1NPLUb-0001Bn-8S for guile-user@gnu.org; Mon, 28 Dec 2009 14:43:01 -0500 Original-Received: (qmail 11188 invoked from network); 28 Dec 2009 19:42:36 -0000 Original-Received: from unknown (HELO ?192.168.0.12?) (paul.emsley@86.157.185.236 with plain) by smtp817.mail.ird.yahoo.com with SMTP; 28 Dec 2009 19:42:36 -0000 X-Yahoo-SMTP: IUeZZ6WswBAkJfbMfxU.UbsYh843HC0rrshqU6q7BEixHmWviE77Qqp10qHRI1w- X-YMail-OSG: VN9Q0n4VM1nDMWy85Yk3Ze2IypbBOfQYpwldg7zPF0LTKDS1Z6GFiBy7ScfPgYlUF0pvVFsyrjV9GNYE9sdZ6abKu00kmsy2g64Smz25ALOhI1FjxOsH.V_AWFxgLlOrFppR1_ZKocFXNkJOUf0LBDrBRvWjQMZNGUNQw_gQozY0cTEmZYCljnXop9t7o9UPgnYWADF7DRadn362EBFU0NSxb4Ug5ErvwwaaUMSG6TYVT0wog.3OnUbRLMwO_vZhmNwI6lmjPHP2iL.qLcmHlTO00JTBPQNQTwn9XSHPsw-- X-Yahoo-Newman-Property: ymail-3 User-Agent: Thunderbird 2.0.0.23 (X11/20090817) In-Reply-To: <20091228170236.GA27921@shoikan.fritz.box> X-detected-operating-system: by monty-python.gnu.org: FreeBSD 6.x (1) X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:7587 Archived-At: guign@mails.selgrad.org wrote: > Hej all :) > > I'm a little confused by the results of (floor .) in a simple > computation to get the fractional part of a monetary value. Maybe > someone can comment on this, as especially in the last test case below > the results seem very strange to me... > > The starting point is: > guile> (rationalize (floor (* (- 12.34 (floor 12.34)) 100)) .0) > 33 > > The actual result shoud be 34. > > That's one of the answers you will get if you use a computer to calculate the results. 33 is the other. floor is working fine. Consider the following: (floor (* (- 12.34000000000001 (floor 12.34)) 100)) (floor (* (- 12.33999999999999 (floor 12.34)) 100)) Given that floating point number storage is not precise, different values is entirely reasonable. You have to be a bit more sophisticated in your floor usage. Paul.