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::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<double>(),
JSPROP_READONLY | JSPROP_PERMANENT),
JS_DOUBLE_PS("MAX_VALUE", 1.7976931348623157E+308,
JS_DOUBLE_PS("MAX_VALUE", MaxNumberValue<double>(),
JSPROP_READONLY | JSPROP_PERMANENT),
JS_DOUBLE_PS("MIN_VALUE", MinNumberValue<double>(),
JSPROP_READONLY | JSPROP_PERMANENT),

View File

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