mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 22:32:46 +00:00
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:
parent
54a7d92d25
commit
f759d0da74
@ -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),
|
||||||
|
@ -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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user