Question: Can two floating point values (IEEE 754 binary64) be compared as integers? Eg.

```
long long a = * (long long *) ptr_to_double1,
          b = * (long long *) ptr_to_double2;
if (a < b) {...}

```

assuming the size of `long long` and `double` is the same.

Answer: 
YES - Comparing the bit-patterns for two floats as if they were integers (aka "type-punning") produces meaningful results under some restricted scenarios...

***Identical to floating-point comparison when:***

* Both numbers are positive, positive-zero, or positive-infinity.
* One positive and one negative number, and you are using a signed integer comparison.

***Inverse of floating-point comparison when:***

* Both numbers are negative, negative-zero, or negative-infinity.
* One positive and one negative number, and you are using a unsigned integer comparison.

***Not comparable to floating-point comparison when:***

* Either number is one of the NaN values - Floating point comparisons with a NaN always returns false, and this simply can't be modeled in integer operations where exactly one of the following is always true: (A < B), (A == B), (B < A).

Negative floating-point numbers are a bit funky b/c they are handled very differently than in the 2's complement arithmetic used for integers. Doing an integer +1 on the representation for a negative float will make it a bigger negative number.

With a little bit manipulation, you can make both positive and negative floats comparable with integer operations (this can come in handy for some optimizations):

```
int32 float_to_comparable_integer(float f) {
  const uint32 bits = *reinterpret_cast<uint32*>(&f);
  const uint32 sign_bit = bits & 0x80000000ul;
  // Modern compilers turn this IF-statement into a conditional move (CMOV) on x86,
  // which is much faster than a branch that the cpu might mis-predict.
  if (sign_bit) {
    bits = 0x7FFFFFF - bits;
  }
  return static_cast<int32>(bits);
}

```

Again, this does *not* work for NaN values, which always return false from comparisons, and have multiple valid bit representations:

* Signaling NaNs (w/ sign bit): Anything between 0xFF800001, and 0xFFBFFFFF.
* Signaling NaNs (w/o sign bit): Anything between 0x7F800001, and 0x7FBFFFFF.
* Quiet NaNs (w/ sign bit): Anything between 0xFFC00000, and 0xFFFFFFFF.
* Quiet NaNs (w/o sign bit): Anything between 0x7FC00000, and 0x7FFFFFFF.

IEEE-754 bit format: <http://www.puntoflotante.net/FLOATING-POINT-FORMAT-IEEE-754.htm>

More on Type-Punning: <https://randomascii.wordpress.com/2012/01/23/stupid-float-tricks-2/>
There are two parts to your question:

1. **Can two floating point numbers be compared?** The answer to this is yes. it is perfectly valid to compare size of floating point numbers. Generally you want to avoid equals comparisons due to truncation issues see [here](https://randomascii.wordpress.com/2012/06/26/doubles-are-not-floats-so-dont-compare-them/), but 

```
if (a < b)

```

will work just fine.
2. **Can two floating point numbers be compared as integers?** This answer is also yes, but this will require casting. This question should help with that answer: [convert from long long to int and the other way back in c++](https://stackoverflow.com/questions/12031302/convert-from-long-long-to-int-and-the-other-way-back-in-c)