chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Possible numbers bug


From: Peter Bex
Subject: Re: [Chicken-users] Possible numbers bug
Date: Sun, 29 May 2011 23:39:31 +0200
User-agent: Mutt/1.4.2.3i

On Fri, May 27, 2011 at 10:58:04AM +0200, Dominic Pearson wrote:
> Hello folks,
> 
> I am trying to compute the sum i = 0 to n where n = 1000 of n^n, but
> chicken seems to return the incorrect answer.
> 
> http://paste.call-cc.org/paste?id=e0884580a684d1220f3dedb819f63201b6f5eb1a
> 
> Racket and scheme48 both seem to give different answers too.

I figured out where it goes wrong.  expt calls the base Chicken expt and
if that returns a fixnum, this result is used (if it's a flonum it might've
overflowed and is inexact anyway so it will use a different path).

This algorithm is sound. However, base Chicken produces wrong results
for some values (and this also depends on the platform, 64 bits NetBSD libc
in this case):

#;1> (expt 999 6)
994014980014993920

This should be:
gosh> (expt 999 6)
994014980014994001

Scheme48 and Racket concur with Gauche.

The reason this goes wrong is that Chicken core does not check errno
after calling C's pow() function.

I am unsure how to fix this.  It can be worked around easily in numbers
by always choosing the "slow" path, but I think this should really be
fixed in core.  Maybe core should return +nan or +inf in cases where
errno was modified?

Cheers,
Peter
-- 
http://sjamaan.ath.cx
--
"The process of preparing programs for a digital computer
 is especially attractive, not only because it can be economically
 and scientifically rewarding, but also because it can be an aesthetic
 experience much like composing poetry or music."
                                                        -- Donald Knuth



reply via email to

[Prev in Thread] Current Thread [Next in Thread]