weird behavior for machine epsilon in float, double and real
Walter Bright
newshound1 at digitalmars.com
Sat Apr 11 11:03:12 PDT 2009
Andrew Spott wrote:
> So, for the following code, I get something I think is a little off.
> I get the same value for all three variable types. I'm kind of new
> to this, but I would think that a 32 bit would give me a different
> "smallest value" than a 64 bit or 80 bit (if real even evaluates to
> 80 bit on my machine).
>
> What am I doing wrong, or is this a bug?
The expression: (ep + n != n) is evaluated at 80 bit precision,
regardless of the size of its operands. The idea is that the floating
point sizes only specify a minimum precision, and the compiler (where it
makes sense) can use a larger precision to do constant folding and/or
for intermediate values.
If you need the epsilon values, use float.epsilon, double.epsilon, and
real.epsilon.
More information about the Digitalmars-d
mailing list