[racket-dev] exact 0 and floating point operations

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Fri Jun 11 17:18:18 EDT 2010

I think that `*', `/', `lcm', `expt, and `exp' are the only operations
that produce an exact result when given some inexact arguments. The
`exp' and `expt' cases were documented before, and I've clarified the
rest in the docs.

The docs now also note that `sin', `tan', `asin', and `atan' produce an
exact 0 when given an exact 0.

Finally, the `atan' procedure now returns an exact 0 when it is given
two arguments, the first is an exact 0, and the second is an exact
positive number.

Why all the special cases? If I remember correctly, it makes
complex-number calculations work more naturally when you have an exact
zero as a real or imaginary part. In any case, after spending some time
on this at one point, I concluded that the special cases are worthwhile
(and that imitating Gambit in this area is a good rule of thumb).

At Fri, 11 Jun 2010 16:28:35 -0400, Sam Tobin-Hochstadt wrote:
> Currently, when given inputs some of which are floats, `*', `+', '/'
> and `-' almost always produce floats.  However, there are some cases
> where this is not true:
> 
> (* flt 0)
> (/ 0 flt)
> 
> Unfortunately, this makes the job of the typechecker and optimizer
> harder (since * and / don't have the closure properties you'd want).
> It's also not fully documented.  Here's the quote from the
> documentation:
> 
> "Certain operations on inexact numbers, however, produce an exact
> number, such as multiplying an inexact number with an exact 0."
> 
> I'd like it if these were changed to always produce floats, but I'd
> settle for complete documentation so that I can give everything the
> right type.
> -- 
> sam th
> samth at ccs.neu.edu
> _________________________________________________
>   For list-related administrative tasks:
>   http://lists.racket-lang.org/listinfo/dev


Posted on the dev mailing list.