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

Re: weird math



On Aug 25,  7:31pm, Steve Strassmann wrote:
...
> ? (coerce 1.4s0 'double-float)
> 1.399999976158142
> ? single-float-epsilon
> 1.1107651257113995E-16
> ? (> (- 1.4d0 1.4s0) single-float-epsilon)
> t

On Aug 26, 11:34am, "rudolf mittelmann" wrote:
> In message <ogSyAUS00WBO89I3Jn@andrew.cmu.edu> Steven Ritter writes:
> > According to my reading of CLtL2 (292-293), this should not happen:
> > ? (= 1.4 (/ 7 5))
> > NIL
> > 
> > Especially since:
> > ? (= 1.4 (coerce (/ 7 5) 'float))
> > T
> > 
> > This isn't a general bug because:
> > ? (= 1.5 (/ 3 2))
> > T
> > 
> > This is the kind of bug that can shake your faith in the truth and
> > purity of mathematics.
> > 
> > I'm using MCL 2.0p2
> > 
> > Steve
> 
> I tried your three statements in Lucid Common Lisp (Sun) and got
> *exactly* the same results.

And then again.... In Franz's ACL 4.1:

26=> (coerce 1.4s0 'double-float)
1.399999976158142d0
27=> single-float-epsilon
1.1920929e-7
28=> (> (- 1.4d0 1.4s0) single-float-epsilon)
NIL
29=> (= 1.4 (/ 7 5))
T

I think this is because Franz uses a less precise (more compact) format
for single precision floats.  Never forget that CLtL leaves a lot of
room for the implementor to make decisions about how the various forms
of floating point math are implemented.

--george