Re: float to int conversion

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



An old, but still very relevant document, which I think should be
essential reading for anyone doing numerical computation :-

What Every Computer Scientist Should Know About Floating-Point
Arithmetic
(http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html)

It goes into a lot more detail than necessary to explain this issue,
but it's important to understand how floating point values are
stored, and how calculations are performed on them.  If you don't,
you'll get unexpected, or erroneous results (often without realising
how wrong they might be).

Regards,

David P.

PS - there's also a "What Every Programmer Should Know About
Memory", which is worth reading too...

On 22 April 2013 10:03, ketmar <ketmar@xxxxxxxxxxxxxxxx> wrote:
> On Mon, 22 Apr 2013 08:48:55 +0000
> "Warlich, Christof" <christof.warlich@xxxxxxxxxxx> wrote:
>
>> Ok, fair enough. But then, what about my second example?:
> one of the numbers goes out of int range in conversion to float. change
> float to double and everything will be fine.
>
> 0x7fffffc0 can'be exactly represented in float, 'cause there is some
> bits occupied by exponent. so it is rounded so some other number, which
> is unfortunately too big to be converted to int. therefore conversion
> triggers undefined behavior.




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux