On Fri, 18 Dec 2009 12:34:09 -0500, bearophile <bearophileh...@lycos.com> wrote:

Steven Schveighoffer:

If I have 2 identical floating point values, how do I ensure they are
binary equivalents of eachother?

Try this inside std.math of Phobos2:
bool isIdentical(real x, real y);

Thanks, that seems to be what I want.



I thought 'a is b' would work, but it just morphs into a == b, which isn't
helpful.  Why doesn't 'is' just do a bit compare for floating points?

"is" is used to compare references.

to me, is means "ignore semantic meaning, do a bitwise compare" regardless of reference status.

For example comparing 2 array structs using == will check that all the data is the same, but using "is" makes it compare bitwise the structs directly.

I see no difference with floating points, except you can't get at the bits easily. The existence of isIdentical could be completely replaced by one or two instructions generated by the compiler when it sees "float is float".

-Steve

Reply via email to