Floating point to integer conversion

This post serves mainly as a personal reminder and came up due to a question on stackoverflow.com. The question was: How exactly does C++ casting between numeric types work? In my code, I do something like the following: double a = 3.0; uint64_t b = static_cast(a); double c = static_cast(b); Interestingly, this works as I would expect (a == c), as long as a is positive, but if a is negative, c ends up as an arbitrarily large positive number. [Read More]