[Top][All Lists]

[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/

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.
> 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)

This should be:
gosh> (expt 999 6)

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?

"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]