| Index: src/conversions-inl.h
|
| ===================================================================
|
| --- src/conversions-inl.h (revision 3964)
|
| +++ src/conversions-inl.h (working copy)
|
| @@ -59,6 +59,32 @@
|
| }
|
|
|
|
|
| +// The fast double-to-unsigned-int conversion routine does not guarantee
|
| +// rounding towards zero.
|
| +static inline unsigned int FastD2UI(double x) {
|
| + // There is no unsigned version of lrint, so there is no fast path
|
| + // in this function as there is in FastD2I. Using lrint doesn't work
|
| + // for values of 2^31 and above.
|
| +
|
| + // Convert "small enough" doubles to uint32_t by fixing the 32
|
| + // least significant non-fractional bits in the low 32 bits of the
|
| + // double, and reading them from there.
|
| + const double k2Pow52 = 4503599627370496.0;
|
| + bool negative = x < 0;
|
| + if (negative) {
|
| + x = -x;
|
| + }
|
| + if (x < k2Pow52) {
|
| + x += k2Pow52;
|
| + uint32_t result;
|
| + memcpy(&result, &x, sizeof(result)); // Copy low 32 bits.
|
| + return negative ? ~result + 1 : result;
|
| + }
|
| + // Large number (outside uint32 range), Infinity or NaN.
|
| + return 0x80000000u; // Return integer indefinite.
|
| +}
|
| +
|
| +
|
| static inline double DoubleToInteger(double x) {
|
| if (isnan(x)) return 0;
|
| if (!isfinite(x) || x == 0) return x;
|
|
|