When I run the following code in VC++ 2013 (32-bit, no optimizations):
#include
#include
#include
double mulpow
9223372036854775808
is 0x8000000000000000
; that is, it is equal to INT64_MIN
cast to uint64_t
.
It looks like your compiler is casting the return value of floor
to long long
and then casting that result to unsigned long long
.
Note that it is quite usual for overflow in floating-point-to-integral conversion to yield the least representable value (e.g. cvttsd2siq
on x86-64):
When a conversion is inexact, a truncated result is returned. If a converted result is larger than the maximum signed doubleword integer, the floating-point invalid exception is raised, and if this exception is masked, the indefinite integer value (80000000H) is returned.
(this is from the doubleword documentation, but the quadword behaviour is the same.)