[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: CLTL compatible type contagion?
I'll spare another the trouble...
220.127.116.11 Rule of Float Approximation
Computations with floats are only approximate, although they are
described as if the results were mathematically accurate. Two
mathematically identical expressions may be computationally different
because of erros inherent in the floating-point approximation
process. The precision of a float is not necessarily correlated with
the accuracy of that number. For instance, 3.142857142857142857 is a
more precise approximation to pi than 3.14159, but the latter is more
accurate. The precision refers to the number of bits retained in the
representation. When a operation combines a short float with a long
float, the result will be a long float. Common Lisp functions assume
that the accuracy of arguments to them does not exceed their
precision. Therefore when two small floats are combined, the result
is a small float. Common Lisp functions never convert automatically
from a larger size to a smaller size.
Yet, CLISP does, and my understanding is that it does this because:
"Common Lisp functions assume that the accuracy of arguments to them
does not exceed their precision"
is such a wildly optimistic assumption.
Seems to me it is fairly easy to set things up to avoid the need for
contagion, and the same program will work fine on a CL that doesn't
mind playing it fast and loose with floating point precision.