# [racket] What is inexactness about?

On Wed, Sep 1, 2010 at 7:30 AM, Prabhakar Ragde <plragde at uwaterloo.ca> wrote:
>*
*>* "Inexact" in Racket is code for IEEE double-precision floating point.
*
And for a particular, somewhat idiosyncratic `contagion' policy.
As Noel pointed out, the reason that we have floating-point is for speed.
(Well, also to approximate rationals and computable reals with a parsimonious
representation, but that is much less important these days.)
>* This represents a fixed set of numbers in such a way that many computations that
*>* would mathematically produce a value not in that set will instead produce as
*>* close a value in the set as possible.
*
This is correct, but bizarre (that is, it accurately describes the
weird behavior
of Scheme's `inexact' numbers).
Floating-point has two components: first, it defines a representation
of a subset
of the rational numbers. The representation is specified in enough detail that
one can build hardware that operates on that representation. Second, it
defines a set of arithmetic-like operations on this representation. These
operations have the property that they act as much as possible as exact
rational arithmetic, provided that the answer can represented, and they
produce erroneous, but the best representable approximation to the answer
otherwise.
What is bizarre is that the normal arithmetic operations such as add, subtract,
etc. are changed to the floating-point approximations based on the
*representation*
of the input number.
(= 1 1.0) => #t
(= (+ 1 1) (+ 1.0 1)) => #t
(= (+ 1 (expt 2 -53)) (+ 1.0 (expt 2 -53))) => #f
`1', and `1.0' are different representations for the same number, and
we expect that
equals added to equals are equal, yet example three shows they are not. This is
because the `+' in the right-hand clause is not the same operation as
the `+' in the
left hand clause because one of the operands was in floating-point
representation.
--
~jrm