float equality

Walter Bright newshound2 at digitalmars.com
Sun Feb 20 12:43:22 PST 2011


Jonathan M Davis wrote:
> It may be that you would still end up with situations where two values that you 
> would think would be the same aren't due to rounding error or whatnot. However, 
> with a fixed point value, you wouldn't have the problem where a particular value 
> could not be held in it even if it's within its range of precision. As I 
> understand it, there are a number of values which cannot be held in a floating 
> point and therefore end up being rounded up or down simply because of how 
> floating points work and not because there the precision isn't high enough.

That happens with decimal representations, too, just with a different set of 
numbers.

> It's definitely true however, that using fractions would be much more accurate 
> for a lot of stuff. That wouldn't be particulary efficient though. Still, if you're 
> doing a lot of math that needs to be accurate, that may be the way to go.

The set of irrational numbers cannot (by definition) be represented by a ratio.

For example, the square root of 2.


More information about the Digitalmars-d mailing list