Sprout/sprout/math/asin.hpp

109 lines
3.4 KiB
C++
Raw Normal View History

2012-05-04 14:23:39 +00:00
#ifndef SPROUT_MATH_ASIN_HPP
#define SPROUT_MATH_ASIN_HPP
#include <cstddef>
#include <type_traits>
#include <sprout/config.hpp>
2013-08-06 15:15:09 +00:00
#include <sprout/limits.hpp>
2012-12-08 04:45:09 +00:00
#include <sprout/detail/pow.hpp>
2012-06-23 04:22:50 +00:00
#include <sprout/math/detail/config.hpp>
2013-02-14 09:02:43 +00:00
#include <sprout/math/detail/float_compute.hpp>
2012-05-04 14:23:39 +00:00
#include <sprout/math/constants.hpp>
2013-04-29 01:56:46 +00:00
#include <sprout/math/isnan.hpp>
#include <sprout/math/fabs.hpp>
2012-05-04 14:23:39 +00:00
#include <sprout/math/sqrt.hpp>
2012-05-26 15:43:38 +00:00
#include <sprout/type_traits/enabler_if.hpp>
2012-05-04 14:23:39 +00:00
namespace sprout {
namespace math {
namespace detail {
template<typename T>
inline SPROUT_CONSTEXPR T
2013-05-04 15:06:30 +00:00
asin_impl_center_1(T x, T x2) {
return ((((((((((((
+ 0.0316658385792867081040808) * x2
+ -0.0158620440988475212803145) * x2
+ 0.0192942786775238654913582) * x2
+ 0.0066153165197009078340075) * x2
+ 0.0121483892822292648695383) * x2
+ 0.0138885410156894774969889) * x2
+ 0.0173593516996479249428647) * x2
+ 0.0223717830666671020710108) * x2
+ 0.0303819580081956423799529) * x2
+ 0.0446428568582815922683933) * x2
+ 0.0750000000029696112392353) * x2
+ 0.1666666666666558995379880) * x2
* x + x
;
}
template<typename T>
inline SPROUT_CONSTEXPR T
asin_impl_center(T x) {
return sprout::math::detail::asin_impl_center_1(x, x * x);
}
template<typename T>
inline SPROUT_CONSTEXPR T
asin_impl_tail(T x) {
return sprout::math::half_pi<T>() + sprout::math::sqrt(T(1) - x)
* (((((((((((((
+ -0.0000121189820098929624806) * x
+ 0.0001307564187657962919394) * x
+ -0.0006702485124770180942917) * x
+ 0.0021912255981979442677477) * x
+ -0.0052049731575223952626203) * x
+ 0.0097868293573384001221447) * x
+ -0.0156746038587246716524035) * x
+ 0.0229883479552557203133368) * x
+ -0.0331919619444009606270380) * x
+ 0.0506659694457588602631748) * x
+ -0.0890259194305537131666744) * x
+ 0.2145993335526539017488949) * x
+ -1.5707961988153774692344105)
2012-05-04 14:23:39 +00:00
;
}
template<typename T>
inline SPROUT_CONSTEXPR T
asin_impl(T x) {
2013-05-04 15:06:30 +00:00
return x < T(-0.5) ? -sprout::math::detail::asin_impl_tail(-x)
: x > T(0.5) ? sprout::math::detail::asin_impl_tail(x)
: sprout::math::detail::asin_impl_center(x)
2012-05-04 14:23:39 +00:00
;
}
template<
typename FloatType,
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR FloatType
asin(FloatType x) {
2013-04-29 01:56:46 +00:00
return sprout::math::isnan(x) ? x
2013-08-06 15:15:09 +00:00
: sprout::math::fabs(x) > 1 ? sprout::numeric_limits<FloatType>::quiet_NaN()
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
: std::asin(x)
#else
2013-04-25 15:25:35 +00:00
: x == 0 ? x
: static_cast<FloatType>(
x < 0 ? -sprout::math::detail::asin_impl(static_cast<typename sprout::math::detail::float_compute<FloatType>::type>(-x))
: sprout::math::detail::asin_impl(static_cast<typename sprout::math::detail::float_compute<FloatType>::type>(x))
)
#endif
2012-05-04 14:23:39 +00:00
;
}
template<
typename IntType,
typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR double
asin(IntType x) {
return sprout::math::detail::asin(static_cast<double>(x));
}
} // namespace detail
2013-04-25 06:36:19 +00:00
using sprout::math::detail::asin;
2012-05-04 14:23:39 +00:00
} // namespace math
using sprout::math::asin;
} // namespace sprout
#endif // #ifndef SPROUT_MATH_ASIN_HPP