[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] Numbers weirdness
From: |
John Cowan |
Subject: |
Re: [Chicken-users] Numbers weirdness |
Date: |
Fri, 1 Apr 2016 12:48:54 -0400 |
User-agent: |
Mutt/1.5.20 (2009-06-14) |
Andy Bennett scripsit:
> #;5> (log2 (expt 2 251))
> 251.0
> #;6> (ceiling (log2 (expt 2 251)))
> 252.0
>
> Is it just late on a Friday? Am I crazy?
Trying (log2 (expt 2 251)) in Racket, which prints 64-bit floats
accurately (unlike Chicken, which depends on C to do it) returns
a value of 251.00000000000003. The ceiling of that is indeed 252.0.
As Kernighan and Plauger said back in 1974: "Floating point numbers
are like sandpiles: every time you move one, you lose a little sand
and pick up a little dirt." It's still true.
--
John Cowan http://www.ccil.org/~cowan address@hidden
Barry thirteen gules and argent on a canton azure fifty mullets of five
points of the second, six, five, six, five, six, five, six, five, and six.
--blazoning the U.S. flag