Why don't we switch to C like floating pointed arithmetic instead of automatic expansion to reals?

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Thu Aug 4 13:58:57 PDT 2016


On 8/4/2016 1:29 PM, Fool wrote:
> I'm afraid, I don't understand your implementation. Isn't toFloat(x) +
> toFloat(y) computed in real precision (first rounding)? Why doesn't
> toFloat(toFloat(x) + toFloat(y)) involve another rounding?

You're right, in that case, it does. But C does, too:

http://www.exploringbinary.com/double-rounding-errors-in-floating-point-conversions/

This is important to remember when advocating for "C-like" floating point - 
because C simply does not behave as most programmers seem to assume it does.

What toFloat() does is guarantee that its argument is rounded to float.

The best way to approach this when designing fp algorithms is to not require 
them to have reduced precision.

It's also important to realize that on some machines, the hardware does not 
actually support float precision operations, or may do so at a large runtime 
penalty (x87).


More information about the Digitalmars-d mailing list