Bug 1114351 - Use mozilla::IsNaN() in DOUBLE_TO_JSVAL(); r=Waldo

Note that this requires making sure that IsNaN is constexpr because it
needs to be passed to the constexpr IMPL_TO_JSVALUE() function in
DOUBLE_TO_JSVAL().

--HG--
extra : amend_source : dbd8bb0659b53e7d36d2600ac97f0a753ef772c7
This commit is contained in:
Ehsan Akhgari 2014-12-21 19:16:49 -05:00
parent 8daffda8e5
commit d803a0513e
2 changed files with 5 additions and 6 deletions

View File

@ -1922,7 +1922,7 @@ DOUBLE_TO_JSVAL(double d)
* because GCC from XCode 3.1.4 miscompiles the above code.
*/
#if defined(JS_VALUE_IS_CONSTEXPR)
return IMPL_TO_JSVAL(MOZ_UNLIKELY(d != d)
return IMPL_TO_JSVAL(MOZ_UNLIKELY(mozilla::IsNaN(d))
? (jsval_layout) { .asBits = 0x7FF8000000000000LL }
: (jsval_layout) { .asDouble = d });
#else

View File

@ -115,9 +115,9 @@ struct FloatingPoint : public SelectTrait<T>
static_assert(sizeof(T) == sizeof(Bits), "Bits must be same size as T");
};
/** Determines whether a double is NaN. */
/** Determines whether a float/double is NaN. */
template<typename T>
static MOZ_ALWAYS_INLINE bool
static MOZ_ALWAYS_INLINE MOZ_CONSTEXPR bool
IsNaN(T aValue)
{
/*
@ -126,9 +126,8 @@ IsNaN(T aValue)
*/
typedef FloatingPoint<T> Traits;
typedef typename Traits::Bits Bits;
Bits bits = BitwiseCast<Bits>(aValue);
return (bits & Traits::kExponentBits) == Traits::kExponentBits &&
(bits & Traits::kSignificandBits) != 0;
return (BitwiseCast<Bits>(aValue) & Traits::kExponentBits) == Traits::kExponentBits &&
(BitwiseCast<Bits>(aValue) & Traits::kSignificandBits) != 0;
}
/** Determines whether a float/double is +Infinity or -Infinity. */