{
const double D32 = 4294967296.0;
if ((number >= 0 && number < D32))
- return static_cast<int>(number);
+ return static_cast<uint>(number);
if (!std::isfinite(number))
return +0;
inline unsigned short __qmljs_to_uint16(Value value, Context *ctx)
{
+ if (value.isInteger())
+ return (ushort)(uint)value.integerValue();
+
double number = __qmljs_to_number(value, ctx);
- if (! number || qIsNaN(number) || std::isinf(number))
+
+ double D16 = 65536.0;
+ if ((number >= 0 && number < D16))
+ return static_cast<ushort>(number);
+
+ if (!std::isfinite(number))
return +0;
- double sign = (number < 0) ? -1.0 : 1.0;
- double abs_n = ::fabs(number);
+ double d = ::floor(::fabs(number));
+ if (std::signbit(number))
+ d = -d;
- double D16 = 65536.0;
- number = ::fmod(sign * ::floor(abs_n), D16);
+ number = ::fmod(d , D16);
if (number < 0)
number += D16;