diff --git a/sprout/math/acos.hpp b/sprout/math/acos.hpp index 405564dc..d849c9ed 100644 --- a/sprout/math/acos.hpp +++ b/sprout/math/acos.hpp @@ -19,7 +19,7 @@ namespace sprout { > inline SPROUT_CONSTEXPR FloatType acos(FloatType x) { - return sprout::math::half_pi() - sprout::math::detail::asin(x); + return sprout::math::half_pi() - sprout::math::asin(x); } template< diff --git a/sprout/math/acosh.hpp b/sprout/math/acosh.hpp index 933ba193..bb01ac84 100644 --- a/sprout/math/acosh.hpp +++ b/sprout/math/acosh.hpp @@ -22,7 +22,7 @@ namespace sprout { acosh(FloatType x) { return x < 1 ? std::numeric_limits::quiet_NaN() : x == std::numeric_limits::infinity() ? std::numeric_limits::infinity() - : sprout::math::detail::log(x + sprout::math::detail::sqrt(x * x - 1)) + : sprout::math::log(x + sprout::math::sqrt(x * x - 1)) ; } diff --git a/sprout/math/asin.hpp b/sprout/math/asin.hpp index f97b043f..bb749af0 100644 --- a/sprout/math/asin.hpp +++ b/sprout/math/asin.hpp @@ -47,7 +47,7 @@ namespace sprout { inline SPROUT_CONSTEXPR T asin_impl(T x) { return x > sprout::math::half_root_two() - ? sprout::math::half_pi() - sprout::math::detail::asin_impl_1(sprout::math::detail::sqrt(1 - x * x)) + ? sprout::math::half_pi() - sprout::math::detail::asin_impl_1(sprout::math::sqrt(1 - x * x)) : sprout::math::detail::asin_impl_1(x) ; } diff --git a/sprout/math/asinh.hpp b/sprout/math/asinh.hpp index 228e7823..259fbbdd 100644 --- a/sprout/math/asinh.hpp +++ b/sprout/math/asinh.hpp @@ -22,7 +22,7 @@ namespace sprout { asinh(FloatType x) { return x == std::numeric_limits::infinity() ? std::numeric_limits::infinity() : x == -std::numeric_limits::infinity() ? -std::numeric_limits::infinity() - : sprout::math::detail::log(x + sprout::math::detail::sqrt(x * x + 1)) + : sprout::math::log(x + sprout::math::sqrt(x * x + 1)) ; } diff --git a/sprout/math/atan2.hpp b/sprout/math/atan2.hpp index 9f37e2d5..c09517ef 100644 --- a/sprout/math/atan2.hpp +++ b/sprout/math/atan2.hpp @@ -21,8 +21,8 @@ namespace sprout { inline SPROUT_CONSTEXPR FloatType atan2(FloatType y, FloatType x) { return x < 0 - ? sprout::math::detail::atan(y / x) + (y < 0 ? -1 : 1) * sprout::math::pi() - : sprout::math::detail::atan(y / x) + ? sprout::math::atan(y / x) + (y < 0 ? -1 : 1) * sprout::math::pi() + : sprout::math::atan(y / x) ; } diff --git a/sprout/math/atanh.hpp b/sprout/math/atanh.hpp index 1cc722fc..7aafe518 100644 --- a/sprout/math/atanh.hpp +++ b/sprout/math/atanh.hpp @@ -22,7 +22,7 @@ namespace sprout { return x < -1 || x > 1 ? std::numeric_limits::quiet_NaN() : x == -1 ? -std::numeric_limits::infinity() : x == 1 ? std::numeric_limits::infinity() - : sprout::math::detail::log((1 + x) / (1 - x)) / 2 + : sprout::math::log((1 + x) / (1 - x)) / 2 ; } diff --git a/sprout/math/cbrt.hpp b/sprout/math/cbrt.hpp index 4bcb6a6c..7933f93e 100644 --- a/sprout/math/cbrt.hpp +++ b/sprout/math/cbrt.hpp @@ -19,8 +19,8 @@ namespace sprout { > inline SPROUT_CONSTEXPR FloatType cbrt(FloatType x) { - return x < 0 ? -sprout::math::detail::pow(-x, sprout::math::third()) - : sprout::math::detail::pow(x, sprout::math::third()) + return x < 0 ? -sprout::math::pow(-x, sprout::math::third()) + : sprout::math::pow(x, sprout::math::third()) ; } diff --git a/sprout/math/classifications.hpp b/sprout/math/classifications.hpp new file mode 100644 index 00000000..3d6b4cf8 --- /dev/null +++ b/sprout/math/classifications.hpp @@ -0,0 +1,14 @@ +#ifndef SPROUT_MATH_CLASSIFICATIONS_HPP +#define SPROUT_MATH_CLASSIFICATIONS_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif // #ifndef SPROUT_MATH_CLASSIFICATIONS_HPP diff --git a/sprout/math/exp10.hpp b/sprout/math/exp10.hpp index 350014a8..194ce18f 100644 --- a/sprout/math/exp10.hpp +++ b/sprout/math/exp10.hpp @@ -16,7 +16,7 @@ namespace sprout { > inline SPROUT_CONSTEXPR FloatType exp10(FloatType x) { - return sprout::math::detail::exp(x * sprout::math::ln_ten()); + return sprout::math::exp(x * sprout::math::ln_ten()); } template< diff --git a/sprout/math/exp2.hpp b/sprout/math/exp2.hpp index f2c3f4b2..64991ba3 100644 --- a/sprout/math/exp2.hpp +++ b/sprout/math/exp2.hpp @@ -19,7 +19,7 @@ namespace sprout { > inline SPROUT_CONSTEXPR FloatType exp2(FloatType x) { - return sprout::math::detail::exp(x * sprout::math::ln_two()); + return sprout::math::exp(x * sprout::math::ln_two()); } template< diff --git a/sprout/math/expm1.hpp b/sprout/math/expm1.hpp index 078c392a..a1d83eb7 100644 --- a/sprout/math/expm1.hpp +++ b/sprout/math/expm1.hpp @@ -19,7 +19,7 @@ namespace sprout { > inline SPROUT_CONSTEXPR FloatType expm1(FloatType x) { - return sprout::math::detail::exp(x) - 1; + return sprout::math::exp(x) - 1; } template< diff --git a/sprout/math/exponential.hpp b/sprout/math/exponential.hpp index fc686146..95602a4f 100644 --- a/sprout/math/exponential.hpp +++ b/sprout/math/exponential.hpp @@ -1,6 +1,7 @@ #ifndef SPROUT_MATH_EXPONENTIAL_HPP #define SPROUT_MATH_EXPONENTIAL_HPP +#include #include #include #include diff --git a/sprout/math/fpclassify.hpp b/sprout/math/fpclassify.hpp new file mode 100644 index 00000000..42b5fc2d --- /dev/null +++ b/sprout/math/fpclassify.hpp @@ -0,0 +1,41 @@ +#ifndef SPROUT_MATH_FPCLASSIFY_HPP +#define SPROUT_MATH_FPCLASSIFY_HPP + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace math { + namespace detail { + template< + typename FloatType, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR int + fpclassify(FloatType x) { + return sprout::math::isnan(x) ? FP_NAN + : sprout::math::isinf(x) ? FP_INFINITE + : sprout::math::iszero(x) ? FP_ZERO + : sprout::math::detail::issubnormal_or_zero(x) ? FP_SUBNORMAL + : FP_NORMAL + ; + } + } // namespace detail + +# if SPROUT_USE_BUILTIN_CMATH_FUNCTION + using std::fpclassify; +# else + using sprout::math::detail::fpclassify; +# endif + } // namespace math + + using sprout::math::fpclassify; +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_FPCLASSIFY_HPP diff --git a/sprout/math/functions.hpp b/sprout/math/functions.hpp index 2ded5954..46c84c9f 100644 --- a/sprout/math/functions.hpp +++ b/sprout/math/functions.hpp @@ -7,5 +7,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_MATH_FUNCTIONS_HPP diff --git a/sprout/math/hyperbolic.hpp b/sprout/math/hyperbolic.hpp index 731ea42e..a6d2df9c 100644 --- a/sprout/math/hyperbolic.hpp +++ b/sprout/math/hyperbolic.hpp @@ -1,6 +1,7 @@ #ifndef SPROUT_MATH_HYPERBOLIC_HPP #define SPROUT_MATH_HYPERBOLIC_HPP +#include #include #include #include diff --git a/sprout/math/hypot.hpp b/sprout/math/hypot.hpp index 12967e1a..3839c6b5 100644 --- a/sprout/math/hypot.hpp +++ b/sprout/math/hypot.hpp @@ -19,7 +19,7 @@ namespace sprout { > inline SPROUT_CONSTEXPR FloatType hypot(FloatType x, FloatType y) { - return sprout::math::detail::sqrt(x * x + y * y); + return sprout::math::sqrt(x * x + y * y); } template< diff --git a/sprout/math/isfinite.hpp b/sprout/math/isfinite.hpp new file mode 100644 index 00000000..a0022b58 --- /dev/null +++ b/sprout/math/isfinite.hpp @@ -0,0 +1,38 @@ +#ifndef SPROUT_MATH_ISFINITE_HPP +#define SPROUT_MATH_ISFINITE_HPP + +#include +#include +#include +#include +#include +#if SPROUT_USE_BUILTIN_CMATH_FUNCTION +# include +#endif + +namespace sprout { + namespace math { + namespace detail { + template< + typename FloatType, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR int + isfinite(FloatType x) { + return !sprout::math::isnan(x) + && !sprout::math::isinf(x) + ; + } + } // namespace detail + +# if SPROUT_USE_BUILTIN_CMATH_FUNCTION + using std::isfinite; +# else + using sprout::math::detail::isfinite; +# endif + } // namespace math + + using sprout::math::isfinite; +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_ISFINITE_HPP diff --git a/sprout/math/isinf.hpp b/sprout/math/isinf.hpp new file mode 100644 index 00000000..c83aed22 --- /dev/null +++ b/sprout/math/isinf.hpp @@ -0,0 +1,37 @@ +#ifndef SPROUT_MATH_ISINF_HPP +#define SPROUT_MATH_ISINF_HPP + +#include +#include +#include +#include +#if SPROUT_USE_BUILTIN_CMATH_FUNCTION +# include +#endif + +namespace sprout { + namespace math { + namespace detail { + template< + typename FloatType, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR int + isinf(FloatType x) { + return x == std::numeric_limits::infinity() + || x == -std::numeric_limits::infinity() + ; + } + } // namespace detail + +# if SPROUT_USE_BUILTIN_CMATH_FUNCTION + using std::isinf; +# else + using sprout::math::detail::isinf; +# endif + } // namespace math + + using sprout::math::isinf; +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_ISINF_HPP diff --git a/sprout/math/isnan.hpp b/sprout/math/isnan.hpp new file mode 100644 index 00000000..5dddab37 --- /dev/null +++ b/sprout/math/isnan.hpp @@ -0,0 +1,34 @@ +#ifndef SPROUT_MATH_ISNAN_HPP +#define SPROUT_MATH_ISNAN_HPP + +#include +#include +#include +#if SPROUT_USE_BUILTIN_CMATH_FUNCTION +# include +#endif + +namespace sprout { + namespace math { + namespace detail { + template< + typename FloatType, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR int + isnan(FloatType x) { + return !(x == x); + } + } // namespace detail + +# if SPROUT_USE_BUILTIN_CMATH_FUNCTION + using std::isnan; +# else + using sprout::math::detail::isnan; +# endif + } // namespace math + + using sprout::math::isnan; +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_ISNAN_HPP diff --git a/sprout/math/isnormal.hpp b/sprout/math/isnormal.hpp new file mode 100644 index 00000000..42e75cc3 --- /dev/null +++ b/sprout/math/isnormal.hpp @@ -0,0 +1,40 @@ +#ifndef SPROUT_MATH_ISNORMAL_HPP +#define SPROUT_MATH_ISNORMAL_HPP + +#include +#include +#include +#include +#include +#include +#if SPROUT_USE_BUILTIN_CMATH_FUNCTION +# include +#endif + +namespace sprout { + namespace math { + namespace detail { + template< + typename FloatType, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR int + isnormal(FloatType x) { + return !sprout::math::isnan(x) + && !sprout::math::isinf(x) + && !sprout::math::detail::issubnormal_or_zero(x) + ; + } + } // namespace detail + +# if SPROUT_USE_BUILTIN_CMATH_FUNCTION + using std::isnormal; +# else + using sprout::math::detail::isnormal; +# endif + } // namespace math + + using sprout::math::isnormal; +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_ISNORMAL_HPP diff --git a/sprout/math/issubnormal.hpp b/sprout/math/issubnormal.hpp new file mode 100644 index 00000000..f0e22617 --- /dev/null +++ b/sprout/math/issubnormal.hpp @@ -0,0 +1,43 @@ +#ifndef SPROUT_MATH_ISSUBNORMAL_HPP +#define SPROUT_MATH_ISSUBNORMAL_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace math { + namespace detail { + template< + typename FloatType, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR int + issubnormal_or_zero(FloatType x) { + return x > 0 + ? x < std::numeric_limits::min() + : x > -std::numeric_limits::min() + ; + } + + template< + typename FloatType, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR int + issubnormal(FloatType x) { + return !sprout::math::iszero(x) + && sprout::math::detail::issubnormal_or_zero(x) + ; + } + } // namespace detail + + using sprout::math::detail::issubnormal; + } // namespace math + + using sprout::math::issubnormal; +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_ISSUBNORMAL_HPP diff --git a/sprout/math/iszero.hpp b/sprout/math/iszero.hpp new file mode 100644 index 00000000..1ff270c3 --- /dev/null +++ b/sprout/math/iszero.hpp @@ -0,0 +1,27 @@ +#ifndef SPROUT_MATH_ISZERO_HPP +#define SPROUT_MATH_ISZERO_HPP + +#include +#include +#include + +namespace sprout { + namespace math { + namespace detail { + template< + typename FloatType, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR int + iszero(FloatType x) { + return x == 0; + } + } // namespace detail + + using sprout::math::detail::iszero; + } // namespace math + + using sprout::math::iszero; +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_ISZERO_HPP diff --git a/sprout/math/log.hpp b/sprout/math/log.hpp index 18225cd0..cb3957a9 100644 --- a/sprout/math/log.hpp +++ b/sprout/math/log.hpp @@ -42,7 +42,7 @@ namespace sprout { inline SPROUT_CONSTEXPR T log_impl(T x) { return !(x > sprout::math::root_two()) ? sprout::math::detail::log_impl_1(x - 1) - : 2 * sprout::math::detail::log_impl(sprout::math::detail::sqrt(x)) + : 2 * sprout::math::detail::log_impl(sprout::math::sqrt(x)) ; } diff --git a/sprout/math/log10.hpp b/sprout/math/log10.hpp index ebacff58..05cb73e9 100644 --- a/sprout/math/log10.hpp +++ b/sprout/math/log10.hpp @@ -19,7 +19,7 @@ namespace sprout { > inline SPROUT_CONSTEXPR FloatType log10(FloatType x) { - return sprout::math::detail::log(x) / sprout::math::ln_ten(); + return sprout::math::log(x) / sprout::math::ln_ten(); } template< diff --git a/sprout/math/log1p.hpp b/sprout/math/log1p.hpp index 8e1f4a0b..5c48d86a 100644 --- a/sprout/math/log1p.hpp +++ b/sprout/math/log1p.hpp @@ -18,7 +18,7 @@ namespace sprout { > inline SPROUT_CONSTEXPR FloatType log1p(FloatType x) { - return sprout::math::detail::log(1 + x); + return sprout::math::log(1 + x); } template< diff --git a/sprout/math/log2.hpp b/sprout/math/log2.hpp index 6e8e385f..ccea28a0 100644 --- a/sprout/math/log2.hpp +++ b/sprout/math/log2.hpp @@ -19,7 +19,7 @@ namespace sprout { > inline SPROUT_CONSTEXPR FloatType log2(FloatType x) { - return sprout::math::detail::log(x) / sprout::math::ln_two(); + return sprout::math::log(x) / sprout::math::ln_two(); } template< diff --git a/sprout/math/operations.hpp b/sprout/math/operations.hpp index 209eb73b..88c3616e 100644 --- a/sprout/math/operations.hpp +++ b/sprout/math/operations.hpp @@ -1,6 +1,7 @@ #ifndef SPROUT_MATH_OPERATIONS_HPP #define SPROUT_MATH_OPERATIONS_HPP +#include #include #include #include diff --git a/sprout/math/pow.hpp b/sprout/math/pow.hpp index d762787e..54eca38e 100644 --- a/sprout/math/pow.hpp +++ b/sprout/math/pow.hpp @@ -22,7 +22,7 @@ namespace sprout { inline SPROUT_CONSTEXPR FloatType pow(FloatType x, FloatType y) { return x == 0 && y > 0 ? FloatType(0) - : sprout::math::detail::exp(y * sprout::math::detail::log(x)) + : sprout::math::exp(y * sprout::math::log(x)) ; } diff --git a/sprout/math/power.hpp b/sprout/math/power.hpp index 4ebd1266..2c45a2b5 100644 --- a/sprout/math/power.hpp +++ b/sprout/math/power.hpp @@ -1,6 +1,7 @@ #ifndef SPROUT_MATH_POWER_HPP #define SPROUT_MATH_POWER_HPP +#include #include #include #include diff --git a/sprout/math/signbit.hpp b/sprout/math/signbit.hpp new file mode 100644 index 00000000..b492c191 --- /dev/null +++ b/sprout/math/signbit.hpp @@ -0,0 +1,34 @@ +#ifndef SPROUT_MATH_SIGNBIT_HPP +#define SPROUT_MATH_SIGNBIT_HPP + +#include +#include +#include +#if SPROUT_USE_BUILTIN_CMATH_FUNCTION +# include +#endif + +namespace sprout { + namespace math { + namespace detail { + template< + typename FloatType, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR int + signbit(FloatType x) { + return x < 0; + } + } // namespace detail + +# if SPROUT_USE_BUILTIN_CMATH_FUNCTION + using std::signbit; +# else + using sprout::math::detail::signbit; +# endif + } // namespace math + + using sprout::math::signbit; +} // namespace sprout + +#endif // #ifndef SPROUT_MATH_SIGNBIT_HPP diff --git a/sprout/math/sin.hpp b/sprout/math/sin.hpp index cfc68c65..b7d86961 100644 --- a/sprout/math/sin.hpp +++ b/sprout/math/sin.hpp @@ -19,7 +19,7 @@ namespace sprout { > inline SPROUT_CONSTEXPR FloatType sin(FloatType x) { - return -sprout::math::detail::cos(x + sprout::math::half_pi()); + return -sprout::math::cos(x + sprout::math::half_pi()); } template< diff --git a/sprout/math/tan.hpp b/sprout/math/tan.hpp index e6593917..34154bfc 100644 --- a/sprout/math/tan.hpp +++ b/sprout/math/tan.hpp @@ -19,7 +19,7 @@ namespace sprout { > inline SPROUT_CONSTEXPR FloatType tan(FloatType x) { - return sprout::math::detail::sin(x) / sprout::math::detail::cos(x); + return sprout::math::sin(x) / sprout::math::cos(x); } template< diff --git a/sprout/math/tanh.hpp b/sprout/math/tanh.hpp index fe63a32b..a128d2f2 100644 --- a/sprout/math/tanh.hpp +++ b/sprout/math/tanh.hpp @@ -19,7 +19,7 @@ namespace sprout { > inline SPROUT_CONSTEXPR FloatType tanh(FloatType x) { - return sprout::math::detail::sinh(x) / sprout::math::detail::cosh(x); + return sprout::math::sinh(x) / sprout::math::cosh(x); } template< diff --git a/sprout/math/trigonometric.hpp b/sprout/math/trigonometric.hpp index 70185ef0..e6fa6cac 100644 --- a/sprout/math/trigonometric.hpp +++ b/sprout/math/trigonometric.hpp @@ -1,6 +1,7 @@ #ifndef SPROUT_MATH_TRIGONOMETRIC_HPP #define SPROUT_MATH_TRIGONOMETRIC_HPP +#include #include #include #include diff --git a/sprout/random/geometric_distribution.hpp b/sprout/random/geometric_distribution.hpp index 6efef849..2c79a0ae 100644 --- a/sprout/random/geometric_distribution.hpp +++ b/sprout/random/geometric_distribution.hpp @@ -11,16 +11,6 @@ #include namespace sprout { - namespace detail { - template - SPROUT_CONSTEXPR T floor(T x) { - return x >= T(0) ? std::floor(x) : -std::ceil(-x); - } - template - SPROUT_CONSTEXPR T ceil(T x) { - return x >= T(0) ? std::ceil(x) : -std::floor(-x); - } - } // namespace detail namespace random { // // geometric_distribution