Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Unified Diff: src/conversions-inl.h

Issue 844006: Merge changes up to V8 version 2.1.3 into the partial snapshots (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/partial_snapshots/
Patch Set: Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/conversions.h ('k') | src/data-flow.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« no previous file with comments | « src/conversions.h ('k') | src/data-flow.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698