Is int->double->int guaranteed to be value-preserving?

c++, c++11

Solution

No it isn't. The standard says nothing about the relative sizes of `int` and `double`.

If `int` is a 64-bit integer and `double` is the standard IEEE double-precision, then it will already fail for numbers bigger than `2^53`.

That said, `int` is still 32-bit on the majority of environments today. So it will still hold in many cases.

Problem

If I have an `int`, convert it to a `double`, then convert the `double` back to an `int`, am I guaranteed to get the same value back that I started with? In other words, given this function: ``` int passThroughDouble(int input) { double d = input; return d; } ``` Am I guaranteed that `passThroughDouble(x) == x` for all `int`s `x`?

Original source