23#ifndef ELEMENTSKERNEL_ELEMENTSKERNEL_REAL_IMPL_
24#error "This file should not be included directly! Use ElementsKernel/Real.h instead"
32template <
typename RawType>
47template <
typename RawType>
52template <
typename RawType>
56 return fp.m_u.m_value;
59template <
typename RawType>
61 return ReinterpretBits(s_exponent_bitmask);
64template <
typename RawType>
69template <
typename RawType>
71 return s_exponent_bitmask & m_u.m_bits;
74template <
typename RawType>
76 return s_fraction_bitmask & m_u.m_bits;
79template <
typename RawType>
81 return s_sign_bitmask & m_u.m_bits;
84template <
typename RawType>
88 return (exponentBits() == s_exponent_bitmask) && (fractionBits() != 0);
91template <
typename RawType>
95 if (
isNan() || rhs.isNan()) {
98 return distanceBetweenSignAndMagnitudeNumbers(m_u.m_bits, rhs.m_u.m_bits) <= m_max_ulps;
101template <
typename RawType>
103 if (s_sign_bitmask & sam) {
108 return s_sign_bitmask | sam;
112template <
typename RawType>
115 const Bits biased1 = signAndMagnitudeToBiased(sam1);
116 const Bits biased2 = signAndMagnitudeToBiased(sam2);
117 return (biased1 >= biased2) ? (biased1 - biased2) : (biased2 - biased1);
120template <
typename FloatType>
126template <
typename RawType>
127bool isNan(
const RawType& x) {
129 using Bits =
typename TypeWithSize<
sizeof(RawType)>::UInt;
139template <
typename RawType, std::
size_t max_ulps>
140bool isEqual(
const RawType& left,
const RawType& right) {
142 bool is_equal{
false};
145 using Bits =
typename TypeWithSize<
sizeof(RawType)>::UInt;
156template <std::
size_t max_ulps>
157inline bool isEqual(
const float& left,
const float& right) {
161template <std::
size_t max_ulps>
162inline bool isEqual(
const double& left,
const double& right) {
166template <
typename RawType, std::
size_t max_ulps>
167inline bool isNotEqual(
const RawType& left,
const RawType& right) {
171template <std::
size_t max_ulps>
172inline bool isNotEqual(
const float& left,
const float& right) {
176template <std::
size_t max_ulps>
177inline bool isNotEqual(
const double& left,
const double& right) {
181template <
typename RawType, std::
size_t max_ulps>
182bool isLess(
const RawType& left,
const RawType& right) {
192template <std::
size_t max_ulps>
193inline bool isLess(
const float& left,
const float& right) {
197template <std::
size_t max_ulps>
198inline bool isLess(
const double& left,
const double& right) {
202template <
typename RawType, std::
size_t max_ulps>
203bool isGreater(
const RawType& left,
const RawType& right) {
204 bool is_greater{
false};
213template <std::
size_t max_ulps>
214inline bool isGreater(
const float& left,
const float& right) {
218template <std::
size_t max_ulps>
219inline bool isGreater(
const double& left,
const double& right) {
223template <
typename RawType, std::
size_t max_ulps>
224bool isLessOrEqual(
const RawType& left,
const RawType& right) {
234template <std::
size_t max_ulps>
235inline bool isLessOrEqual(
const float& left,
const float& right) {
239template <std::
size_t max_ulps>
240inline bool isLessOrEqual(
const double& left,
const double& right) {
244template <
typename RawType, std::
size_t max_ulps>
255template <std::
size_t max_ulps>
260template <std::
size_t max_ulps>
265template <
typename RawType>
267#pragma GCC diagnostic push
268#pragma GCC diagnostic ignored "-Wfloat-equal"
269 return (left == right);
270#pragma GCC diagnostic pop
Macro to silence unused variables warnings from the compiler.
Bits fractionBits() const
static const Bits s_fraction_bitmask
typename TypeWithSize< sizeof(RawType)>::UInt Bits
static RawType ReinterpretBits(const Bits &bits)
FloatingPoint(const RawType &x)
static Bits distanceBetweenSignAndMagnitudeNumbers(const Bits &sam1, const Bits &sam2)
static const Bits s_exponent_bitmask
static Bits signAndMagnitudeToBiased(const Bits &sam)
static RawType Infinity()
bool AlmostEquals(const FloatingPoint &rhs) const
Bits exponentBits() const
const Bits & bits() const
ELEMENTS_API bool isLess(const RawType &left, const RawType &right)
ELEMENTS_API bool isNotEqual(const RawType &left, const RawType &right)
ELEMENTS_API bool isGreater(const RawType &left, const RawType &right)
constexpr std::size_t FLT_DEFAULT_MAX_ULPS
Single precision float default maximum unit in the last place.
ELEMENTS_API bool isNan(const RawType &x)
ELEMENTS_API bool isEqual(const RawType &left, const RawType &right)
ELEMENTS_API bool isLessOrEqual(const RawType &left, const RawType &right)
constexpr std::size_t DBL_DEFAULT_MAX_ULPS
Double precision float default maximum unit in the last place.
ELEMENTS_API bool realBitWiseEqual(const RawType &left, const RawType &right)
This function compares 2 floating point numbers bitwise. These are the strict equivalent of the "=="....
ELEMENTS_API constexpr std::size_t defaultMaxUlps< double >()
ELEMENTS_API constexpr std::size_t defaultMaxUlps< float >()
ELEMENTS_API bool almostEqual2sComplement(ELEMENTS_UNUSED const FloatType &a, ELEMENTS_UNUSED const FloatType &b, ELEMENTS_UNUSED const std::size_t &max_ulps=0)
ELEMENTS_API bool isGreaterOrEqual(const RawType &left, const RawType &right)
ELEMENTS_API constexpr std::size_t defaultMaxUlps()