1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2024-11-12 21:09:01 +00:00

fix copysign for clang

This commit is contained in:
bolero-MURAKAMI 2014-03-19 19:50:00 +09:00
parent 5527449e26
commit 01efe1e793
9 changed files with 45 additions and 13 deletions

View file

@ -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
//

View file

@ -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

View file

@ -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

View file

@ -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
//

View file

@ -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.

View file

@ -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
;

View file

@ -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) )
//

View file

@ -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
;
}

View file

@ -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) )
//