On my platform this prints 9223372036854775808.
double x = 1e19;
std::cout << static_cast<unsigned __int64>(x) << '\n';
I tried Boost.NumericConversion, but got the same result.
Splitting x into 2 equal part, then adding together converted halves give the correct result. But I need a generic solution to use in a template code.
Thank you in advance.
EDIT: This problem shows up on Visual Studio 2008, but not MinGW. Casting 4.0e9 into unsigned long works fine.