Bug 1918688 - Use standard headers for infinity, and float's max/min r=nbp,media-playback-reviewers,glandium,karlt

Still rely on mozilla aliases though, for readability and to avoid
confusion in the case of NegativeInfinity.

As a bonus, provide MaxNumberValue that mirrors MinNumberValue.

Differential Revision: https://phabricator.services.mozilla.com/D222119
This commit is contained in:
serge-sans-paille 2024-09-19 12:22:43 +00:00
parent 54a7d92d25
commit f759d0da74
2 changed files with 14 additions and 19 deletions

View File

@ -65,6 +65,7 @@ using mozilla::Abs;
using mozilla::AsciiAlphanumericToNumber; using mozilla::AsciiAlphanumericToNumber;
using mozilla::IsAsciiAlphanumeric; using mozilla::IsAsciiAlphanumeric;
using mozilla::IsAsciiDigit; using mozilla::IsAsciiDigit;
using mozilla::MaxNumberValue;
using mozilla::Maybe; using mozilla::Maybe;
using mozilla::MinNumberValue; using mozilla::MinNumberValue;
using mozilla::NegativeInfinity; using mozilla::NegativeInfinity;
@ -1447,7 +1448,7 @@ static const JSPropertySpec number_static_properties[] = {
JSPROP_READONLY | JSPROP_PERMANENT), JSPROP_READONLY | JSPROP_PERMANENT),
JS_DOUBLE_PS("NEGATIVE_INFINITY", mozilla::NegativeInfinity<double>(), JS_DOUBLE_PS("NEGATIVE_INFINITY", mozilla::NegativeInfinity<double>(),
JSPROP_READONLY | JSPROP_PERMANENT), JSPROP_READONLY | JSPROP_PERMANENT),
JS_DOUBLE_PS("MAX_VALUE", 1.7976931348623157E+308, JS_DOUBLE_PS("MAX_VALUE", MaxNumberValue<double>(),
JSPROP_READONLY | JSPROP_PERMANENT), JSPROP_READONLY | JSPROP_PERMANENT),
JS_DOUBLE_PS("MIN_VALUE", MinNumberValue<double>(), JS_DOUBLE_PS("MIN_VALUE", MinNumberValue<double>(),
JSPROP_READONLY | JSPROP_PERMANENT), JSPROP_READONLY | JSPROP_PERMANENT),

View File

@ -216,24 +216,14 @@ static MOZ_ALWAYS_INLINE int_fast16_t ExponentComponent(T aValue) {
/** Returns +Infinity. */ /** Returns +Infinity. */
template <typename T> template <typename T>
static MOZ_ALWAYS_INLINE T PositiveInfinity() { static constexpr MOZ_ALWAYS_INLINE T PositiveInfinity() {
/* return std::numeric_limits<T>::infinity();
* Positive infinity has all exponent bits set, sign bit set to 0, and no
* significand.
*/
typedef FloatingPoint<T> Traits;
return BitwiseCast<T>(Traits::kExponentBits);
} }
/** Returns -Infinity. */ /** Returns -Infinity. */
template <typename T> template <typename T>
static MOZ_ALWAYS_INLINE T NegativeInfinity() { static constexpr MOZ_ALWAYS_INLINE T NegativeInfinity() {
/* return -std::numeric_limits<T>::infinity();
* Negative infinity has all exponent bits set, sign bit set to 1, and no
* significand.
*/
typedef FloatingPoint<T> Traits;
return BitwiseCast<T>(Traits::kSignBit | Traits::kExponentBits);
} }
/** /**
@ -306,10 +296,14 @@ SpecificNaN(int signbit, typename FloatingPoint<T>::Bits significand) {
/** Computes the smallest non-zero positive float/double value. */ /** Computes the smallest non-zero positive float/double value. */
template <typename T> template <typename T>
static MOZ_ALWAYS_INLINE T MinNumberValue() { static constexpr MOZ_ALWAYS_INLINE T MinNumberValue() {
typedef FloatingPoint<T> Traits; return std::numeric_limits<T>::denorm_min();
typedef typename Traits::Bits Bits; }
return BitwiseCast<T>(Bits(1));
/** Computes the largest positive float/double value. */
template <typename T>
static constexpr MOZ_ALWAYS_INLINE T MaxNumberValue() {
return std::numeric_limits<T>::max();
} }
namespace detail { namespace detail {