Now rounding is always towards zero; the rounding can be though as if
occurring on the original double. Only relevant for the 32-bit long
variant.
-3999999999999999475712.,
-3999999999999998951424.,
];
+ /* see if we're rounding negative numbers right */
+ $values[] = -2147483649.8;
foreach ($values as $v) {
var_dump((int)$v);
int(-2055208960)
int(-2054684672)
int(-2054160384)
+int(2147483647)
dmod = fmod(d, two_pow_32);
if (dmod < 0) {
- dmod += two_pow_32;
+ /* we're going to make this number positive; call ceil()
+ * to simulate rounding towards 0 of the negative number */
+ dmod = ceil(dmod) + two_pow_32;
}
return (long)(unsigned long)dmod;
}
dmod = fmod(d, two_pow_64);
if (dmod < 0) {
+ /* no need to call ceil; original double must have had no
+ * fractional part, hence dmod does not have one either */
dmod += two_pow_64;
}
return (long)(unsigned long)dmod;