Prev: aserve on Linux anyone? [was Re: Good functional programminghabbit?]
Next: need help implementing hooks in Common lisp
From: William D Clinger on 4 May 2010 10:17 Aravindh Johendran wrote: > In MIT-Scheme, if I define average to be as follows, > (define (average x y) > (/ (+ x y) 2)) > > Why are the following incantations not giving me the correct/expected > answers? > > (+ 0.9999999999999999e23 1.0000000000000001e23) > ;Value: 1.9999999999999998e23 > > (average 0.9999999999999999e23 1.0000000000000001e23) > ;Value: 0.9999999999999999e23 > > Is all of this related to floating point arithmetic? Yes. What's more, I strongly suspect that MIT Scheme's output routine fails to satisfy the requirements imposed by R5RS 6.2.6. If MIT Scheme were using extended precision, then the first result would have been more accurate and more precise (more digits). It appears that MIT Scheme is using double precision with a non-conforming output routine. In implementations of Scheme that use IEEE double precision and conform to the R5RS or R6RS, you should get these results: > (+ 0.9999999999999999e23 1.0000000000000001e23) 2.0e23 > (average 0.9999999999999999e23 1.0000000000000001e23) 1.0e23 It so happens that 10^23 lies exactly halfway between the two nearest IEEE double precision approximations, which is why this is a difficult test case. Will
From: George Neuner on 9 May 2010 00:59 On Mon, 3 May 2010 00:04:03 -0700 (PDT), Aravindh Johendran <ajohendran(a)gmail.com> wrote: >Is there a good source to understand [floating point arithmetic]? >Wikipedia entry is dense. Soming late to this, but I'm surprised nobody mentioned: David Goldberg, "What every computer scientist should know about floating-point arithmetic" http://docs.sun.com/source/806-3568/ncg_goldberg.html It's also a bit dense, but IMO less so than the Wikipedia entry. There's a lot more information too. George
From: Tamas K Papp on 9 May 2010 05:10 On Sun, 09 May 2010 00:59:55 -0400, George Neuner wrote: > On Mon, 3 May 2010 00:04:03 -0700 (PDT), Aravindh Johendran > <ajohendran(a)gmail.com> wrote: > > >>Is there a good source to understand [floating point arithmetic]? >>Wikipedia entry is dense. > > Soming late to this, but I'm surprised nobody mentioned: > > David Goldberg, "What every computer scientist should know about > floating-point arithmetic" > http://docs.sun.com/source/806-3568/ncg_goldberg.html I mentioned it in the first reply to the OP, then Pascal gave the URL above. Tamas
From: George Neuner on 9 May 2010 15:42
On 9 May 2010 09:10:42 GMT, Tamas K Papp <tkpapp(a)gmail.com> wrote: >On Sun, 09 May 2010 00:59:55 -0400, George Neuner wrote: > >> Soming late to this, but I'm surprised nobody mentioned: >> >> David Goldberg, "What every computer scientist should know about >> floating-point arithmetic" >> http://docs.sun.com/source/806-3568/ncg_goldberg.html > >I mentioned it in the first reply to the OP, then Pascal gave the URL >above. > >Tamas Oops, you're right. I didn't connect the reference to Goldberg ... I was thinking about the name of the article rather than the author. George |