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

Unified Diff: src/conversions-inl.h

Issue 661275: Added implementation if Uint32::Value. (Closed)
Patch Set: Added IsUint32 Created 10 years, 10 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') | test/cctest/test-api.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/conversions-inl.h
diff --git a/src/conversions-inl.h b/src/conversions-inl.h
index ba7220a4a62b90151b41275e3dbfaa23f3b878ff..36c7015177c1a31aa41a3ad0eaf219e26e4252bf 100644
--- a/src/conversions-inl.h
+++ b/src/conversions-inl.h
@@ -59,6 +59,30 @@ static inline int FastD2I(double x) {
}
+// 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; }
Mads Ager (chromium) 2010/03/03 13:16:50 Remove the braces or split on multiple lines.
+ 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') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698