checking if double values equal
Extending from the float sample, is what I have below the correct version for double?
Specifically, it's the 0x8000000000000000....not sure if this is the right value for 0 in 64bit.
Can someone check if this is correct?
bool AlmostEqual2sComplement(double A, double B, long long maxUlps)
{
// Make sure maxUlps is non-negative and small enough that the default NAN won't compare as equal to anything.
assert(maxUlps > 0 && maxUlps < 8 * 1024 * 1024);
long long aInt = *(long long*)&A;
// Make aInt lexicographically ordered as a twos-complement int
if (aInt < 0)
{
aInt = 0x8000000000000000 - aInt;
}
// Make bInt lexicographically ordered as a twos-complement int
long long bInt = *(long long*)&B;
if (bInt < 0)
{
bInt = 0x8000000000000000 - bInt;
}
long long intDiff = aInt - bInt;
if (intDiff<0)
{
intDiff *= -1;
}
if (intDiff <= maxUlps)
{
return true;
}
return false;
}

