diff --git a/js/src/jsnum.cpp b/js/src/jsnum.cpp index 065139fa2b01..767f221eab5d 100644 --- a/js/src/jsnum.cpp +++ b/js/src/jsnum.cpp @@ -65,6 +65,7 @@ using mozilla::Abs; using mozilla::AsciiAlphanumericToNumber; using mozilla::IsAsciiAlphanumeric; using mozilla::IsAsciiDigit; +using mozilla::MaxNumberValue; using mozilla::Maybe; using mozilla::MinNumberValue; using mozilla::NegativeInfinity; @@ -1447,7 +1448,7 @@ static const JSPropertySpec number_static_properties[] = { JSPROP_READONLY | JSPROP_PERMANENT), JS_DOUBLE_PS("NEGATIVE_INFINITY", mozilla::NegativeInfinity(), JSPROP_READONLY | JSPROP_PERMANENT), - JS_DOUBLE_PS("MAX_VALUE", 1.7976931348623157E+308, + JS_DOUBLE_PS("MAX_VALUE", MaxNumberValue(), JSPROP_READONLY | JSPROP_PERMANENT), JS_DOUBLE_PS("MIN_VALUE", MinNumberValue(), JSPROP_READONLY | JSPROP_PERMANENT), diff --git a/mfbt/FloatingPoint.h b/mfbt/FloatingPoint.h index 73dd8e9c3c5f..ad9362152ae9 100644 --- a/mfbt/FloatingPoint.h +++ b/mfbt/FloatingPoint.h @@ -216,24 +216,14 @@ static MOZ_ALWAYS_INLINE int_fast16_t ExponentComponent(T aValue) { /** Returns +Infinity. */ template -static MOZ_ALWAYS_INLINE T PositiveInfinity() { - /* - * Positive infinity has all exponent bits set, sign bit set to 0, and no - * significand. - */ - typedef FloatingPoint Traits; - return BitwiseCast(Traits::kExponentBits); +static constexpr MOZ_ALWAYS_INLINE T PositiveInfinity() { + return std::numeric_limits::infinity(); } /** Returns -Infinity. */ template -static MOZ_ALWAYS_INLINE T NegativeInfinity() { - /* - * Negative infinity has all exponent bits set, sign bit set to 1, and no - * significand. - */ - typedef FloatingPoint Traits; - return BitwiseCast(Traits::kSignBit | Traits::kExponentBits); +static constexpr MOZ_ALWAYS_INLINE T NegativeInfinity() { + return -std::numeric_limits::infinity(); } /** @@ -306,10 +296,14 @@ SpecificNaN(int signbit, typename FloatingPoint::Bits significand) { /** Computes the smallest non-zero positive float/double value. */ template -static MOZ_ALWAYS_INLINE T MinNumberValue() { - typedef FloatingPoint Traits; - typedef typename Traits::Bits Bits; - return BitwiseCast(Bits(1)); +static constexpr MOZ_ALWAYS_INLINE T MinNumberValue() { + return std::numeric_limits::denorm_min(); +} + +/** Computes the largest positive float/double value. */ +template +static constexpr MOZ_ALWAYS_INLINE T MaxNumberValue() { + return std::numeric_limits::max(); } namespace detail {