Bug 1548908: Add InfinityBits to FloatingPoint.h r=jwalden

We can't generate a constexpr uint64_t containing the bits for positive/negative infinity, because of a (very sensible) static_assert in SpecificNaNBits. This patch adds support to FloatingPoint.h for infinity. The next patch will use it to make JS::InfinityValue constexpr (to match JS::NaNValue).

Differential Revision: https://phabricator.services.mozilla.com/D29869

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Iain Ireland 2019-06-03 15:59:21 +00:00
parent 5a8c83aeaa
commit 00ae116a04
2 changed files with 16 additions and 0 deletions

View File

@ -344,6 +344,10 @@ constexpr uint64_t CanonicalizedNaNBits =
mozilla::SpecificNaNBits<double, detail::CanonicalizedNaNSignBit,
detail::CanonicalizedNaNSignificand>::value;
constexpr int InfinitySignBit = 0;
constexpr uint64_t InfinityBits =
mozilla::InfinityBits<double, detail::InfinitySignBit>::value;
} // namespace detail
/**

View File

@ -277,6 +277,18 @@ static MOZ_ALWAYS_INLINE T NegativeInfinity() {
return BitwiseCast<T>(Traits::kSignBit | Traits::kExponentBits);
}
/**
* Computes the bit pattern for an infinity with the specified sign bit.
*/
template <typename T, int SignBit>
struct InfinityBits {
using Traits = FloatingPoint<T>;
static_assert(SignBit == 0 || SignBit == 1, "bad sign bit");
static constexpr typename Traits::Bits value =
(SignBit * Traits::kSignBit) | Traits::kExponentBits;
};
/**
* Computes the bit pattern for a NaN with the specified sign bit and
* significand bits.