Oliver Meyer
Oliver Meyer

Reputation: 412

How does IEEE 754 define equal?

How does IEEE-754 define equal for "regular" double floating point numbers? Is the java implementation of Double.equal in accordance with IEEE-754?

If I leave out the special values like NaN, -0, etc. are IEEE-754 double floating numbers equal, if and only if they have the same 64bits representing them?

IEEE-754 defines how an approximation of "10.12" is to be represented in 64bits as double. IEEE-754 defines how to calculate "6.0+4.12", by representing both values in 64bits and how to derive 64bits that represent the result. I know that the two 64bit patterns I receive are not the same.

What I do not know, if IEEE-754 defines some special equal-relation for those 64bit patterns that still defines them as equal?

I see a lot of documents on how to resemble mathematical equal with floating point numbers. They all claim that 10.12 != 6.0+4.12 if represented and calculated according to IEEE-754. If I do that in java with Double objects, java also claims that the two values are not equal. I like to know if the equal operation of java Double is in accordance with IEEE-754.

Upvotes: 1

Views: 849

Answers (1)

Alexey Romanov
Alexey Romanov

Reputation: 170839

If I leave out the special values like NaN, -0, etc. are IEEE-754 double floating number equal, if and only if they have the same 64bits representing them?

Yes.

I like to know if the equal operation of java Double is in accordance with IEEE-754.

No, there are two exceptions specifically listed in Double.equals documentation:

  1. Two Double objects corresponding to NaN are equal;

  2. Double objects corresponding to zero and to negative zero aren't equal.

Equality on primitive double is according to IEEE-754.

Upvotes: 1

Related Questions