Generally when converting floats to integers it is best to add 0.5 so it 
rounds up.

Les

On 31/12/10 10:40, Michael Büsch wrote:
> Well, no. The reason for it seems to be that floating point
> numbers come with some inaccuracies.
> So the number 1 in floating point might be 1.0000001 or 0.99999998
> or something like that, depending on the CPU architecture
> and/or the operations that were done to the number before.
> However, when converted to int the 1.0000001 converts as 1 and
> the 0.99999998 converts as 0. And thus we have to add a "safe" value
> to it before casting it. 0.0001 is pretty safe for doubles and
> also seems to be safe for floats.
> This is also the reason why floating point numbers cannot be
> compared with ==. They often wouldn't match, even if it's
> actually the same number, due to inaccuracies.
>


------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and, 
should the need arise, upgrade to a full multi-node Oracle RAC database 
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Emc-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/emc-developers

Reply via email to