}
/* }}} */
+#if !ZEND_DVAL_TO_LVAL_CAST_OK
+# if SIZEOF_ZEND_LONG == 4
+ZEND_API zend_long zend_dval_to_lval_slow(double d)
+{
+ double two_pow_32 = pow(2., 32.),
+ dmod;
+
+ dmod = fmod(d, two_pow_32);
+ if (dmod < 0) {
+ /* 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 (zend_long)(zend_ulong)dmod;
+}
+#else
+ZEND_API zend_long zend_dval_to_lval_slow(double d)
+{
+ double two_pow_64 = pow(2., 64.),
+ 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 (zend_long)(zend_ulong)dmod;
+}
+#endif
+#endif
+
/*
* Local variables:
* tab-width: 4
return 0;
}
}
-#elif SIZEOF_ZEND_LONG == 4
-static zend_always_inline zend_long zend_dval_to_lval(double d)
-{
- if (UNEXPECTED(!zend_finite(d)) || UNEXPECTED(zend_isnan(d))) {
- return 0;
- } else if (!ZEND_DOUBLE_FITS_LONG(d)) {
- double two_pow_32 = pow(2., 32.),
- dmod;
-
- dmod = fmod(d, two_pow_32);
- if (dmod < 0) {
- /* 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 (zend_long)(zend_ulong)dmod;
- }
- return (zend_long)d;
-}
#else
+ZEND_API zend_long zend_dval_to_lval_slow(double d);
+
static zend_always_inline zend_long zend_dval_to_lval(double d)
{
if (UNEXPECTED(!zend_finite(d)) || UNEXPECTED(zend_isnan(d))) {
return 0;
} else if (!ZEND_DOUBLE_FITS_LONG(d)) {
- double two_pow_64 = pow(2., 64.),
- 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 (zend_long)(zend_ulong)dmod;
+ return zend_dval_to_lval_slow(d);
}
return (zend_long)d;
}