Skip to content

Commit

Permalink
Remove MSVC fallback that was inconsistent with every other impl
Browse files Browse the repository at this point in the history
  • Loading branch information
Rinzii committed Mar 9, 2024
1 parent 79bc35c commit fc0d38f
Showing 1 changed file with 1 addition and 25 deletions.
26 changes: 1 addition & 25 deletions include/ccmath/detail/compare/signbit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,6 @@
#endif
#endif

// This is are last resort for MSVC. This is constexpr, but it is not static_assert-able.
// TODO: Decide if it is improper to allow this inconsistent behavior for MSVC 19.26 and earlier against how every other approach behaves.
#if defined(_MSVC_VER) && !defined(CCMATH_HAS_CONSTEXPR_BUILTIN_BIT_CAST) && !defined(CCMATH_HAS_CONSTEXPR_SIGNBIT) && \
!defined(CCMATH_HAS_CONSTEXPR_BUILTIN_COPYSIGN)
#define CCMATH_MSVC_DOES_NOT_HAVE_ASSERTABLE_CONSTEXPR_SIGNBIT
#include <cfloat> // for _fpclass and _FPCLASS_NZ
#endif

namespace ccm
{
/**
Expand All @@ -61,13 +53,7 @@ namespace ccm
*
* @note This function has multiple implementations based on the compiler and the version of
* the the compiler used. With nearly all implementations, this function is fully constexpr and will return
* the same values as std::signbit along with being static_assert-able. The only exception is MSVC 19.26 and earlier
* and unknown compilers that support none of possible implementations.
*
* @note ccm::signbit by default will use std::signbit if using C++23 or later.
*
* @warning ccm::signbit will not work with static_assert on MSVC 19.26 and earlier. This is due to the fact that
* MSVC does not provide a constexpr signbit until 19.27. This is a limitation of MSVC and not ccmath.
* the same values as std::signbit along with being static_assert-able.
*
* @warning ccm::signbit currently is only ensured to work on little-endian systems. There is currently no guarantee this it will work on big-endian
* systems.
Expand Down Expand Up @@ -107,12 +93,6 @@ namespace ccm
}

return x < static_cast<T>(0);
#elif defined(CCMATH_MSVC_DOES_NOT_HAVE_ASSERTABLE_CONSTEXPR_SIGNBIT)
// If we don't have access to MSVC 19.27 or later, we can use _fpclass and _FPCLASS_NZ to
// check for the sign of zero. This is is constexpr, but it is not static_assert-able.
// TODO: Decide if it is improper to allow this inconsistent behavior for MSVC 19.26 and earlier against how every other approach behaves with
// ccm::signbit.
return ((x == static_cast<T>(0)) ? (_fpclass(x) == _FPCLASS_NZ) : (x < T(0))); // This won't work in static assertions
#else
static_assert(false, "ccm::signbit is not implemented for this compiler. Please report this issue to the dev!");
return false;
Expand Down Expand Up @@ -167,7 +147,3 @@ namespace ccm
#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_COPYSIGN
#undef CCMATH_HAS_CONSTEXPR_BUILTIN_COPYSIGN
#endif

#ifdef CCMATH_MSVC_DOES_NOT_HAVE_ASSERTABLE_CONSTEXPR_SIGNBIT
#undef CCMATH_MSVC_DOES_NOT_HAVE_ASSERTABLE_CONSTEXPR_SIGNBIT
#endif

0 comments on commit fc0d38f

Please sign in to comment.