[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: 5.3.0-work3 and lossless integer conversion
- From: William Ahern <william@...>
- Date: Thu, 26 Jun 2014 13:13:29 -0700
On Thu, Jun 26, 2014 at 11:41:39AM -0700, Josh Haberman wrote:
> Let me try to alleviate some possible "floating-point anxiety."
>
> Doubles can represent integers [-2^53, 2^53] exactly. If you have
> integers in this range, addition, subtraction, and multiplication
> yield exact integers.
<snip>
> Because floating point numbers are inexact for decimals, people tend
> to assume that floating point numbers are approximate and unreliable
> in general. But as long as you are dealing with integer values, the
> values will stay integral.
>
> Division is another story, of course:
This is how I've always understood it, but I admit it's nice to hear it
stated clearly and adamantly ;) There are so many "floating point is frought
with danger" disclaimers, including numerous "you think you understand
floating point but you really don't" articles and essays that it does create
unreasonable anxiety, particularly in people who have the least reason to be
anxious--if you get anxious you're the type of person that pays attention to
that stuff in the first place.
As long you keep clear of decimal values and division operations, there's
nothing to worry about. Overflow is an issue with integers as well, so that
doesn't change much, although it is a slightly more complex issue with
floating point, in terms of avoidance and mitigation. And related to
overflow is the issue of value portability and string conversions. But the
predominance of IEEE754 floating point, and in particular its 64-bit double
precision type, really helps. Esoteric machines will cause headaches with
all integral types, not just floats.