Index: src/utils.cc |
diff --git a/src/utils.cc b/src/utils.cc |
index c159fc13ea7ca105549cc12464efd91527daab08..1c33cff55955ee8e4d27c10a71e2e229a8b15f0b 100644 |
--- a/src/utils.cc |
+++ b/src/utils.cc |
@@ -375,4 +375,24 @@ void init_memcopy_functions() { |
} |
+bool DoubleToBoolean(double d) { |
+ // NaN, +0, and -0 should return the false object |
+#if __BYTE_ORDER == __LITTLE_ENDIAN |
+ union IeeeDoubleLittleEndianArchType u; |
+#elif __BYTE_ORDER == __BIG_ENDIAN |
+ union IeeeDoubleBigEndianArchType u; |
+#endif |
+ u.d = d; |
+ if (u.bits.exp == 2047) { |
+ // Detect NaN for IEEE double precision floating point. |
+ if ((u.bits.man_low | u.bits.man_high) != 0) return false; |
+ } |
+ if (u.bits.exp == 0) { |
+ // Detect +0, and -0 for IEEE double precision floating point. |
+ if ((u.bits.man_low | u.bits.man_high) == 0) return false; |
+ } |
+ return true; |
+} |
+ |
+ |
} } // namespace v8::internal |