mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-23 21:25:49 +00:00
fix copysign for clang
This commit is contained in:
parent
5527449e26
commit
01efe1e793
9 changed files with 45 additions and 13 deletions
|
@ -123,6 +123,15 @@
|
|||
# endif // #ifdef SPROUT_HAS_CONSTEXPR_CMATH_FUNCTION
|
||||
#endif // #ifndef SPROUT_CONFIG_DISABLE_BUILTIN_CMATH_FUNCTION
|
||||
|
||||
//
|
||||
// SPROUT_CONFIG_DISABLE_BUILTIN_COPYSIGN_FUNCTION
|
||||
//
|
||||
#ifndef SPROUT_CONFIG_DISABLE_BUILTIN_COPYSIGN_FUNCTION
|
||||
# ifndef SPROUT_HAS_CONSTEXPR_COPYSIGN_FUNCTION
|
||||
# define SPROUT_CONFIG_DISABLE_BUILTIN_COPYSIGN_FUNCTION
|
||||
# endif // #ifdef SPROUT_HAS_CONSTEXPR_COPYSIGN_FUNCTION
|
||||
#endif // #ifndef SPROUT_CONFIG_DISABLE_BUILTIN_COPYSIGN_FUNCTION
|
||||
|
||||
//
|
||||
// SPROUT_CONFIG_DISABLE_BUILTIN_BIT_OPERATION
|
||||
//
|
||||
|
|
|
@ -56,6 +56,10 @@
|
|||
# define SPROUT_NO_CXX14_VARIABLE_TEMPLATES
|
||||
#endif
|
||||
|
||||
#if (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 0))
|
||||
# define SPROUT_HAS_CONSTEXPR_COPYSIGN_FUNCTION
|
||||
#endif
|
||||
|
||||
#if !defined(SPROUT_NO_CXX11_CONSTEXPR)
|
||||
# define SPROUT_WORKAROUND_NOT_TERMINATE_RECURSIVE_CONSTEXPR_FUNCTION_TEMPLATE
|
||||
#endif
|
||||
|
|
|
@ -52,6 +52,10 @@
|
|||
# define SPROUT_HAS_CONSTEXPR_CMATH_FUNCTION
|
||||
#endif
|
||||
|
||||
#if ((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && defined(__GXX_EXPERIMENTAL_CXX0X__))
|
||||
# define SPROUT_HAS_CONSTEXPR_COPYSIGN_FUNCTION
|
||||
#endif
|
||||
|
||||
#if ((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && defined(__GXX_EXPERIMENTAL_CXX0X__))
|
||||
# define SPROUT_HAS_CONSTEXPR_BIT_OPERATION
|
||||
#endif
|
||||
|
|
|
@ -167,6 +167,15 @@
|
|||
# define SPROUT_USE_BUILTIN_CMATH_FUNCTION 0
|
||||
#endif // #ifndef SPROUT_CONFIG_DISABLE_BUILTIN_CMATH_FUNCTION
|
||||
|
||||
//
|
||||
// SPROUT_USE_BUILTIN_COPYSIGN_FUNCTION
|
||||
//
|
||||
#ifndef SPROUT_CONFIG_DISABLE_BUILTIN_COPYSIGN_FUNCTION
|
||||
# define SPROUT_USE_BUILTIN_COPYSIGN_FUNCTION 1
|
||||
#else // #ifndef SPROUT_CONFIG_DISABLE_BUILTIN_COPYSIGN_FUNCTION
|
||||
# define SPROUT_USE_BUILTIN_COPYSIGN_FUNCTION 0
|
||||
#endif // #ifndef SPROUT_CONFIG_DISABLE_BUILTIN_COPYSIGN_FUNCTION
|
||||
|
||||
//
|
||||
// SPROUT_USE_BUILTIN_BIT_OPERATION
|
||||
//
|
||||
|
|
|
@ -55,7 +55,7 @@ namespace sprout {
|
|||
// atan2
|
||||
//
|
||||
// issue:
|
||||
// [ !SPROUT_USE_BUILTIN_CMATH_FUNCTION ]
|
||||
// [ !(SPROUT_USE_BUILTIN_CMATH_FUNCTION || SPROUT_USE_BUILTIN_COPYSIGN_FUNCTION) ]
|
||||
// atan2(<28>}0, -0) returns <20>}ƒÎ .
|
||||
// # returns <20>}0 . ( same as atan2(<28>}0, +0) )
|
||||
// atan2(-0, x) returns -ƒÎ for x < 0.
|
||||
|
|
|
@ -13,14 +13,13 @@
|
|||
#include <sprout/limits.hpp>
|
||||
#include <sprout/math/detail/config.hpp>
|
||||
#include <sprout/math/isnan.hpp>
|
||||
#include <sprout/math/signbit.hpp>
|
||||
#include <sprout/type_traits/float_promote.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace math {
|
||||
namespace detail {
|
||||
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
|
||||
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION || SPROUT_USE_BUILTIN_COPYSIGN_FUNCTION
|
||||
inline SPROUT_CONSTEXPR float
|
||||
builtin_copysign(float x, float y) {
|
||||
return __builtin_copysignf(x, y);
|
||||
|
@ -34,12 +33,17 @@ namespace sprout {
|
|||
return __builtin_copysignl(x, y);
|
||||
}
|
||||
#endif
|
||||
template<typename FloatType>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
broken_signbit(FloatType x) {
|
||||
return !sprout::math::isnan(x) && x < 0;
|
||||
}
|
||||
} // namespace detail
|
||||
//
|
||||
// copysign
|
||||
//
|
||||
// issue:
|
||||
// [ !SPROUT_USE_BUILTIN_CMATH_FUNCTION ]
|
||||
// [ !(SPROUT_USE_BUILTIN_CMATH_FUNCTION || SPROUT_USE_BUILTIN_COPYSIGN_FUNCTION) ]
|
||||
// copysign(<28>}x, -0) returns -x for |x| is not 0 .
|
||||
// # returns +x . ( same as copysign(<28>}x, +0) )
|
||||
// copysign(<28>}x, -NaN) returns -x for |x| is not NaN .
|
||||
|
@ -52,18 +56,18 @@ namespace sprout {
|
|||
inline SPROUT_CONSTEXPR FloatType
|
||||
copysign(FloatType x, FloatType y) {
|
||||
return
|
||||
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
|
||||
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION || SPROUT_USE_BUILTIN_COPYSIGN_FUNCTION
|
||||
sprout::math::detail::builtin_copysign(x, y)
|
||||
#else
|
||||
x == 0
|
||||
? y == 0 ? y
|
||||
: sprout::math::signbit(y) ? -FloatType(0)
|
||||
: sprout::math::detail::broken_signbit(y) ? -FloatType(0)
|
||||
: FloatType(0)
|
||||
: sprout::math::isnan(x)
|
||||
? sprout::math::isnan(y) ? y
|
||||
: sprout::math::signbit(y) ? -sprout::numeric_limits<FloatType>::quiet_NaN()
|
||||
: sprout::math::detail::broken_signbit(y) ? -sprout::numeric_limits<FloatType>::quiet_NaN()
|
||||
: sprout::numeric_limits<FloatType>::quiet_NaN()
|
||||
: sprout::math::signbit(y) != sprout::math::signbit(x) ? -x
|
||||
: sprout::math::detail::broken_signbit(y) != sprout::math::detail::broken_signbit(x) ? -x
|
||||
: x
|
||||
#endif
|
||||
;
|
||||
|
|
|
@ -51,7 +51,7 @@ namespace sprout {
|
|||
// pow
|
||||
//
|
||||
// issue:
|
||||
// [ !SPROUT_USE_BUILTIN_CMATH_FUNCTION ]
|
||||
// [ !(SPROUT_USE_BUILTIN_CMATH_FUNCTION || SPROUT_USE_BUILTIN_COPYSIGN_FUNCTION) ]
|
||||
// pow(-0, y) returns -<2D>‡ for y an odd integer < 0.
|
||||
// # returns +<2B>‡ . ( same as pow(+0, y) )
|
||||
//
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/math/detail/config.hpp>
|
||||
#include <sprout/math/isnan.hpp>
|
||||
#include <sprout/math/copysign.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
|
||||
namespace sprout {
|
||||
|
@ -29,7 +29,7 @@ namespace sprout {
|
|||
// signbit
|
||||
//
|
||||
// issue:
|
||||
// [ !SPROUT_USE_BUILTIN_CMATH_FUNCTION ]
|
||||
// [ !(SPROUT_USE_BUILTIN_CMATH_FUNCTION || SPROUT_USE_BUILTIN_COPYSIGN_FUNCTION) ]
|
||||
// signbit(-0) returns false .
|
||||
// # returns true . ( same as signbit(+0) )
|
||||
// signbit(-NaN) returns false .
|
||||
|
@ -44,8 +44,10 @@ namespace sprout {
|
|||
return
|
||||
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
|
||||
sprout::math::detail::builtin_signbit(x)
|
||||
#elif SPROUT_USE_BUILTIN_COPYSIGN_FUNCTION
|
||||
sprout::math::copysign(FloatType(1), x) < FloatType(0)
|
||||
#else
|
||||
!sprout::math::isnan(x) && x < 0
|
||||
sprout::math::detail::broken_signbit(x)
|
||||
#endif
|
||||
;
|
||||
}
|
||||
|
|
|
@ -127,7 +127,7 @@ namespace sprout {
|
|||
// tgamma
|
||||
//
|
||||
// issue:
|
||||
// [ !SPROUT_USE_BUILTIN_CMATH_FUNCTION ]
|
||||
// [ !(SPROUT_USE_BUILTIN_CMATH_FUNCTION || SPROUT_USE_BUILTIN_COPYSIGN_FUNCTION) ]
|
||||
// tgamma(-0) returns -<2D>‡ .
|
||||
// # returns +<2B>‡ . ( same as tgamma(+0) )
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue