Make NaN -> int casting explicit

See the task for details, but the bottom line is that casting NaN to an
int in PHP is passed straight through to the hardware's
convert-floating-point-to-scalar instruction. This implementation
explicitly spells out the Intel instruction's behavior. The ARM
instruction always outputs zero instead, resulting in inconsistency.

To be clear, I'm OK with not checking this in. For one thing, I'd bet
that if you compiled Zend on ARM, it would cast NaN to zero (I haven't
tried it). The advantage that this gets us is consistent output on all
platforms.
Esse commit está contido em:
Owen Yamauchi
2013-04-08 12:09:19 -07:00
commit de Sara Golemon
commit 95afc7f255
+6 -2
Ver Arquivo
@@ -96,8 +96,12 @@ inline int64_t toInt64(short v) { return v;}
inline int64_t toInt64(int v) { return v;}
inline int64_t toInt64(int64_t v) { return v;}
inline int64_t toInt64(double v) {
return (v >= 0 ? v > std::numeric_limits<uint64_t>::max() ? 0u :
(uint64_t)v : (int64_t)v);
// If v >= 0 is false and v < 0 is false, then v is NaN. In that case, on
// Intel, you get 0x800..00, a.k.a. the minimum int64_t. We mimic that on all
// platforms, though this makes us sad.
return (v >= 0
? (v > std::numeric_limits<uint64_t>::max() ? 0u : (uint64_t)v)
: (v < 0 ? (int64_t)v : std::numeric_limits<int64_t>::min()));
}
inline int64_t toInt64(litstr v) { return StringData(v).toInt64();}
inline int64_t toInt64(const StringData *v) { return v ? v->toInt64() : 0;}