mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-23 21:25:49 +00:00
replace implementation <cmath> functions to Sprout.Math.Functions
This commit is contained in:
parent
6ccd6e1cf4
commit
6bb2d0fb87
21 changed files with 212 additions and 106 deletions
|
@ -1,11 +1,20 @@
|
|||
#ifndef SPROUT_COMPLEX_HPP
|
||||
#define SPROUT_COMPLEX_HPP
|
||||
|
||||
#include <cmath>
|
||||
#include <iosfwd>
|
||||
#include <ios>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/math/constants.hpp>
|
||||
#include <sprout/math/abs.hpp>
|
||||
#include <sprout/math/sin.hpp>
|
||||
#include <sprout/math/cos.hpp>
|
||||
#include <sprout/math/atan2.hpp>
|
||||
#include <sprout/math/sinh.hpp>
|
||||
#include <sprout/math/cosh.hpp>
|
||||
#include <sprout/math/exp.hpp>
|
||||
#include <sprout/math/log.hpp>
|
||||
#include <sprout/math/pow.hpp>
|
||||
#include <sprout/math/sqrt.hpp>
|
||||
|
||||
namespace sprout {
|
||||
template<typename T>
|
||||
|
@ -281,12 +290,12 @@ namespace sprout {
|
|||
}
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR T abs(sprout::complex<T> const& x) {
|
||||
using std::sqrt;
|
||||
using sprout::sqrt;
|
||||
return sqrt(sprout::norm(x));
|
||||
}
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR T arg(sprout::complex<T> const& x) {
|
||||
using std::atan2;
|
||||
using sprout::atan2;
|
||||
return atan2(x.imag(), x.real());
|
||||
}
|
||||
template<typename T>
|
||||
|
@ -315,8 +324,8 @@ namespace sprout {
|
|||
}
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR sprout::complex<T> polar(T const& rho, T const& theta = 0) {
|
||||
using std::cos;
|
||||
using std::sin;
|
||||
using sprout::cos;
|
||||
using sprout::sin;
|
||||
return sprout::complex<T>(rho * cos(theta), rho * sin(theta));
|
||||
}
|
||||
// 26.4.8, transcendentals:
|
||||
|
@ -388,8 +397,8 @@ namespace sprout {
|
|||
T const& den
|
||||
)
|
||||
{
|
||||
using std::atan2;
|
||||
using std::log;
|
||||
using sprout::atan2;
|
||||
using sprout::log;
|
||||
return sprout::complex<T>(
|
||||
T(0.5) * atan2(T(2) * x.real(), z),
|
||||
T(0.25) * log((r2 + num * num) / (r2 + den * den))
|
||||
|
@ -440,8 +449,8 @@ namespace sprout {
|
|||
T const& den
|
||||
)
|
||||
{
|
||||
using std::atan2;
|
||||
using std::log;
|
||||
using sprout::atan2;
|
||||
using sprout::log;
|
||||
return sprout::complex<T>(
|
||||
T(0.25) * (log(i2 + num * num) - log(i2 + den * den)),
|
||||
T(0.5) * atan2(T(2) * x.imag(), z)
|
||||
|
@ -468,10 +477,10 @@ namespace sprout {
|
|||
}
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR sprout::complex<T> cos(sprout::complex<T> const& x) {
|
||||
using std::cos;
|
||||
using std::sin;
|
||||
using std::cosh;
|
||||
using std::sinh;
|
||||
using sprout::cos;
|
||||
using sprout::sin;
|
||||
using sprout::cosh;
|
||||
using sprout::sinh;
|
||||
return sprout::complex<T>(
|
||||
cos(x.real()) * cosh(x.imag()),
|
||||
-(sin(x.real()) * sinh(x.imag()))
|
||||
|
@ -479,10 +488,10 @@ namespace sprout {
|
|||
}
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR sprout::complex<T> cosh(sprout::complex<T> const& x) {
|
||||
using std::cos;
|
||||
using std::sin;
|
||||
using std::cosh;
|
||||
using std::sinh;
|
||||
using sprout::cos;
|
||||
using sprout::sin;
|
||||
using sprout::cosh;
|
||||
using sprout::sinh;
|
||||
return sprout::complex<T>(
|
||||
cosh(x.real()) * cos(x.imag()),
|
||||
sinh(x.real()) * sin(x.imag())
|
||||
|
@ -490,7 +499,7 @@ namespace sprout {
|
|||
}
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR sprout::complex<T> exp(sprout::complex<T> const& x) {
|
||||
using std::exp;
|
||||
using sprout::exp;
|
||||
return sprout::polar(exp(x.real()), x.imag());
|
||||
}
|
||||
template<typename T>
|
||||
|
@ -499,19 +508,19 @@ namespace sprout {
|
|||
}
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR sprout::complex<T> log10(sprout::complex<T> const& x) {
|
||||
using std::log;
|
||||
using sprout::log;
|
||||
return sprout::log(x) / log(T(10));
|
||||
}
|
||||
namespace detail {
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR sprout::complex<T> pow_impl(sprout::complex<T> const& t, T const& y) {
|
||||
using std::exp;
|
||||
using sprout::exp;
|
||||
return sprout::polar(exp(y * t.real()), y * t.imag());
|
||||
}
|
||||
} // namespace detail
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR sprout::complex<T> pow(sprout::complex<T> const& x, T const& y) {
|
||||
using std::pow;
|
||||
using sprout::pow;
|
||||
return x == T() ? T()
|
||||
: x.imag() == T() && x.real() > T() ? pow(x.real(), y)
|
||||
: sprout::detail::pow_impl(sprout::log(x), y)
|
||||
|
@ -525,17 +534,17 @@ namespace sprout {
|
|||
}
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR sprout::complex<T> pow(T const& x, sprout::complex<T> const& y) {
|
||||
using std::log;
|
||||
using sprout::log;
|
||||
return x > T() ? sprout::polar(sprout::pow(x, y.real()), y.imag() * log(x))
|
||||
: sprout::pow(sprout::complex<T>(x), y)
|
||||
;
|
||||
}
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR sprout::complex<T> sin(sprout::complex<T> const& x) {
|
||||
using std::cos;
|
||||
using std::sin;
|
||||
using std::cosh;
|
||||
using std::sinh;
|
||||
using sprout::cos;
|
||||
using sprout::sin;
|
||||
using sprout::cosh;
|
||||
using sprout::sinh;
|
||||
return sprout::complex<T>(
|
||||
sin(x.real()) * cosh(x.imag()),
|
||||
cos(x.real()) * sinh(x.imag())
|
||||
|
@ -543,10 +552,10 @@ namespace sprout {
|
|||
}
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR sprout::complex<T> sinh(sprout::complex<T> const& x) {
|
||||
using std::cos;
|
||||
using std::sin;
|
||||
using std::cosh;
|
||||
using std::sinh;
|
||||
using sprout::cos;
|
||||
using sprout::sin;
|
||||
using sprout::cosh;
|
||||
using sprout::sinh;
|
||||
return sprout::complex<T>(
|
||||
sinh(x.real()) * cos(x.imag()),
|
||||
cosh(x.real()) * sin(x.imag())
|
||||
|
@ -559,7 +568,7 @@ namespace sprout {
|
|||
}
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR sprout::complex<T> sqrt_impl_2_1(sprout::complex<T> const& x, T const& t, T const& u) {
|
||||
using std::abs;
|
||||
using sprout::abs;
|
||||
return x.real() > T() ? sprout::complex<T>(u, x.imag() / t)
|
||||
: sprout::complex<T>(abs(x.imag()) / t, x.imag() < T() ? -u : u)
|
||||
;
|
||||
|
@ -571,8 +580,8 @@ namespace sprout {
|
|||
} // namespace detail
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR sprout::complex<T> sqrt(sprout::complex<T> const& x) {
|
||||
using std::sqrt;
|
||||
using std::abs;
|
||||
using sprout::sqrt;
|
||||
using sprout::abs;
|
||||
return x.real() == T() ? sprout::detail::sqrt_impl_1(x, sqrt(abs(x.imag()) / 2))
|
||||
: sprout::detail::sqrt_impl_2(x, sqrt(2 * (sprout::abs(x) + abs(x.real()))))
|
||||
;
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cinttypes>
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
|
@ -83,9 +84,11 @@ namespace sprout {
|
|||
return !endptr ? sprout::detail::str_to_int<IntType>(str, base)
|
||||
: std::is_signed<IntType>::value
|
||||
? sizeof(IntType) <= sizeof(long) ? static_cast<IntType>(std::strtol(&*str, endptr, base))
|
||||
: static_cast<IntType>(std::strtoll(&*str, endptr, base))
|
||||
: sizeof(IntType) <= sizeof(long long) ? static_cast<IntType>(std::strtoll(&*str, endptr, base))
|
||||
: static_cast<IntType>(std::strtoimax(&*str, endptr, base))
|
||||
: sizeof(IntType) <= sizeof(unsigned long) ? static_cast<IntType>(std::strtoul(&*str, endptr, base))
|
||||
: static_cast<IntType>(std::strtoull(&*str, endptr, base))
|
||||
: sizeof(IntType) <= sizeof(unsigned long long) ? static_cast<IntType>(std::strtoull(&*str, endptr, base))
|
||||
: static_cast<IntType>(std::strtoumax(&*str, endptr, base))
|
||||
;
|
||||
}
|
||||
} // namespace detail
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
#ifndef SPROUT_DARKROOM_CAMERAS_SIMPLE_CAMERA_HPP
|
||||
#define SPROUT_DARKROOM_CAMERAS_SIMPLE_CAMERA_HPP
|
||||
|
||||
#include <cmath>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/tuple/tuple.hpp>
|
||||
#include <sprout/math/sin.hpp>
|
||||
#include <sprout/math/cos.hpp>
|
||||
#include <sprout/math/sqrt.hpp>
|
||||
#include <sprout/darkroom/coords/vector.hpp>
|
||||
#include <sprout/darkroom/cameras/angle_of_view.hpp>
|
||||
|
||||
|
@ -49,9 +51,9 @@ namespace sprout {
|
|||
unit_type const& v
|
||||
) const
|
||||
{
|
||||
using std::sqrt;
|
||||
using std::sin;
|
||||
using std::cos;
|
||||
using sprout::sqrt;
|
||||
using sprout::sin;
|
||||
using sprout::cos;
|
||||
return transform_1(
|
||||
c,
|
||||
u * cos(rotate_) - v * sin(rotate_),
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#ifndef SPROUT_DARKROOM_COORDS_VECTOR_HPP
|
||||
#define SPROUT_DARKROOM_COORDS_VECTOR_HPP
|
||||
|
||||
#include <cmath>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/tuple/tuple.hpp>
|
||||
#include <sprout/tuple/functions.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/math/sqrt.hpp>
|
||||
#include <sprout/darkroom/access/access.hpp>
|
||||
|
||||
namespace sprout {
|
||||
|
@ -63,7 +63,7 @@ namespace sprout {
|
|||
template<typename Vector>
|
||||
inline SPROUT_CONSTEXPR typename sprout::darkroom::access::unit<Vector>::type
|
||||
length(Vector const& vec) {
|
||||
using std::sqrt;
|
||||
using sprout::sqrt;
|
||||
return sqrt(sprout::darkroom::coords::length_sq(vec));
|
||||
}
|
||||
//
|
||||
|
|
|
@ -2,12 +2,13 @@
|
|||
#define SPROUT_DARKROOM_OBJECTS_SPHERE_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/tuple/tuple.hpp>
|
||||
#include <sprout/tuple/functions.hpp>
|
||||
#include <sprout/math/constants.hpp>
|
||||
#include <sprout/math/atan2.hpp>
|
||||
#include <sprout/math/sqrt.hpp>
|
||||
#include <sprout/darkroom/access/access.hpp>
|
||||
#include <sprout/darkroom/coords/vector.hpp>
|
||||
#include <sprout/darkroom/rays/ray.hpp>
|
||||
|
@ -142,8 +143,8 @@ namespace sprout {
|
|||
Vec const& normal
|
||||
) const
|
||||
{
|
||||
using std::atan2;
|
||||
using std::sqrt;
|
||||
using sprout::atan2;
|
||||
using sprout::sqrt;
|
||||
return typename intersection<Ray>::type(
|
||||
sprout::tuples::get<zw::does_intersect>(zwo),
|
||||
sprout::tuples::get<zw::distance>(zwo),
|
||||
|
@ -205,7 +206,7 @@ namespace sprout {
|
|||
unit_type const& det_sq
|
||||
) const
|
||||
{
|
||||
using std::sqrt;
|
||||
using sprout::sqrt;
|
||||
return intersect_4(
|
||||
ray,
|
||||
zweitens(
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define SPROUT_ITERATOR_SINUSOID_ITERATOR_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <cmath>
|
||||
#include <iterator>
|
||||
#include <utility>
|
||||
#include <type_traits>
|
||||
|
@ -11,6 +10,7 @@
|
|||
#include <sprout/iterator/prev.hpp>
|
||||
#include <sprout/iterator/distance.hpp>
|
||||
#include <sprout/math/constants.hpp>
|
||||
#include <sprout/math/sin.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
|
@ -94,7 +94,7 @@ namespace sprout {
|
|||
return phase_;
|
||||
}
|
||||
SPROUT_CONSTEXPR reference operator*() const {
|
||||
using std::sin;
|
||||
using sprout::sin;
|
||||
return amplitude_ * sin(d_ * value_type(index_) + phase_);
|
||||
}
|
||||
SPROUT_CONSTEXPR pointer operator->() const {
|
||||
|
@ -135,7 +135,7 @@ namespace sprout {
|
|||
return *this;
|
||||
}
|
||||
SPROUT_CONSTEXPR reference operator[](difference_type n) const {
|
||||
using std::sin;
|
||||
using sprout::sin;
|
||||
return amplitude_ * sin(d_ * value_type(index_ + n) + phase_);
|
||||
}
|
||||
SPROUT_CONSTEXPR sinusoid_iterator next() const {
|
||||
|
|
42
sprout/math/abs.hpp
Normal file
42
sprout/math/abs.hpp
Normal file
|
@ -0,0 +1,42 @@
|
|||
#ifndef SPROUT_MATH_ABS_HPP
|
||||
#define SPROUT_MATH_ABS_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/utility/enabler_if.hpp>
|
||||
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
|
||||
# include <cmath>
|
||||
#endif
|
||||
|
||||
namespace sprout {
|
||||
namespace math {
|
||||
namespace detail {
|
||||
template<
|
||||
typename FloatType,
|
||||
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR FloatType
|
||||
abs(FloatType x) {
|
||||
return x < 0 ? -x : x;
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
template<
|
||||
typename FloatType,
|
||||
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR FloatType
|
||||
abs(FloatType x) {
|
||||
# if SPROUT_USE_BUILTIN_CMATH_FUNCTION
|
||||
using std::abs;
|
||||
# else
|
||||
using sprout::math::detail::abs;
|
||||
# endif
|
||||
return abs(x);
|
||||
}
|
||||
} // namespace math
|
||||
|
||||
using sprout::math::abs;
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_MATH_ABS_HPP
|
|
@ -21,6 +21,7 @@ namespace sprout {
|
|||
inline SPROUT_CONSTEXPR FloatType
|
||||
acosh(FloatType x) {
|
||||
return x < 1 ? std::numeric_limits<FloatType>::quiet_NaN()
|
||||
: x == std::numeric_limits<FloatType>::infinity() ? std::numeric_limits<FloatType>::infinity()
|
||||
: sprout::math::detail::log(x + sprout::math::detail::sqrt(x * x - 1))
|
||||
;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef SPROUT_MATH_ASINH_HPP
|
||||
#define SPROUT_MATH_ASINH_HPP
|
||||
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/math/log.hpp>
|
||||
|
@ -19,7 +20,9 @@ namespace sprout {
|
|||
>
|
||||
inline SPROUT_CONSTEXPR FloatType
|
||||
asinh(FloatType x) {
|
||||
return sprout::math::detail::log(x + sprout::math::detail::sqrt(x * x + 1))
|
||||
return x == std::numeric_limits<FloatType>::infinity() ? std::numeric_limits<FloatType>::infinity()
|
||||
: x == -std::numeric_limits<FloatType>::infinity() ? -std::numeric_limits<FloatType>::infinity()
|
||||
: sprout::math::detail::log(x + sprout::math::detail::sqrt(x * x + 1))
|
||||
;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define SPROUT_MATH_COS_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/math/factorial.hpp>
|
||||
|
@ -33,12 +34,16 @@ namespace sprout {
|
|||
inline SPROUT_CONSTEXPR FloatType
|
||||
cos(FloatType x) {
|
||||
typedef double type;
|
||||
return static_cast<FloatType>(sprout::math::detail::cos_impl(
|
||||
static_cast<type>(x),
|
||||
type(1),
|
||||
1,
|
||||
static_cast<type>(x) * static_cast<type>(x)
|
||||
));
|
||||
return x == std::numeric_limits<FloatType>::infinity()
|
||||
|| x == -std::numeric_limits<FloatType>::infinity()
|
||||
? std::numeric_limits<FloatType>::quiet_NaN()
|
||||
: static_cast<FloatType>(sprout::math::detail::cos_impl(
|
||||
static_cast<type>(x),
|
||||
type(1),
|
||||
1,
|
||||
static_cast<type>(x) * static_cast<type>(x)
|
||||
))
|
||||
;
|
||||
}
|
||||
|
||||
template<
|
||||
|
|
|
@ -11,15 +11,6 @@
|
|||
namespace sprout {
|
||||
namespace math {
|
||||
namespace detail {
|
||||
template<
|
||||
typename FloatType,
|
||||
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR FloatType
|
||||
abs(FloatType x) {
|
||||
return x < 0 ? -x : x;
|
||||
}
|
||||
|
||||
template<
|
||||
typename FloatType,
|
||||
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
|
||||
|
@ -39,20 +30,6 @@ namespace sprout {
|
|||
}
|
||||
} // namespace detail
|
||||
|
||||
template<
|
||||
typename FloatType,
|
||||
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR FloatType
|
||||
abs(FloatType x) {
|
||||
# if SPROUT_USE_BUILTIN_CMATH_FUNCTION
|
||||
using std::abs;
|
||||
# else
|
||||
using sprout::math::detail::abs;
|
||||
# endif
|
||||
return abs(x);
|
||||
}
|
||||
|
||||
# if SPROUT_USE_BUILTIN_CMATH_FUNCTION
|
||||
using std::fabs;
|
||||
# else
|
||||
|
@ -60,7 +37,6 @@ namespace sprout {
|
|||
# endif
|
||||
} // namespace math
|
||||
|
||||
using sprout::math::abs;
|
||||
using sprout::math::fabs;
|
||||
} // namespace sprout
|
||||
|
||||
|
|
55
sprout/math/fma.hpp
Normal file
55
sprout/math/fma.hpp
Normal file
|
@ -0,0 +1,55 @@
|
|||
#ifndef SPROUT_MATH_FMA_HPP
|
||||
#define SPROUT_MATH_FMA_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/math/float_promote.hpp>
|
||||
#include <sprout/utility/enabler_if.hpp>
|
||||
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
|
||||
# include <cmath>
|
||||
#endif
|
||||
|
||||
namespace sprout {
|
||||
namespace math {
|
||||
namespace detail {
|
||||
template<
|
||||
typename FloatType,
|
||||
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR FloatType
|
||||
fma(FloatType x, FloatType y, FloatType z) {
|
||||
return x * y + z;
|
||||
}
|
||||
|
||||
template<
|
||||
typename ArithmeticType1,
|
||||
typename ArithmeticType2,
|
||||
typename ArithmeticType3,
|
||||
typename sprout::enabler_if<
|
||||
std::is_arithmetic<ArithmeticType1>::value
|
||||
&& std::is_arithmetic<ArithmeticType2>::value
|
||||
&& std::is_arithmetic<ArithmeticType3>::value
|
||||
>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR typename sprout::math::float_promote<
|
||||
ArithmeticType1, ArithmeticType2, ArithmeticType3
|
||||
>::type
|
||||
fma(ArithmeticType1 x, ArithmeticType2 y, ArithmeticType3 z) {
|
||||
typedef typename sprout::math::float_promote<
|
||||
ArithmeticType1, ArithmeticType2, ArithmeticType3
|
||||
>::type type;
|
||||
return sprout::math::detail::fma(static_cast<type>(x), static_cast<type>(y), static_cast<type>(z));
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
# if SPROUT_USE_BUILTIN_CMATH_FUNCTION
|
||||
using std::fma;
|
||||
# else
|
||||
using sprout::math::detail::fma;
|
||||
# endif
|
||||
} // namespace math
|
||||
|
||||
using sprout::math::fma;
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_MATH_FMA_HPP
|
|
@ -1,7 +1,9 @@
|
|||
#ifndef SPROUT_MATH_OPERATIONS_HPP
|
||||
#define SPROUT_MATH_OPERATIONS_HPP
|
||||
|
||||
#include <sprout/math/abs.hpp>
|
||||
#include <sprout/math/fabs.hpp>
|
||||
#include <sprout/math/fma.hpp>
|
||||
#include <sprout/math/fmax.hpp>
|
||||
#include <sprout/math/fmin.hpp>
|
||||
#include <sprout/math/fdim.hpp>
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
#ifndef SPROUT_NUMERIC_DFT_DETAIL_DFT_ELEMENT_GEN_HPP
|
||||
#define SPROUT_NUMERIC_DFT_DETAIL_DFT_ELEMENT_GEN_HPP
|
||||
|
||||
#include <cmath>
|
||||
#include <iterator>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/math/sin.hpp>
|
||||
#include <sprout/math/cos.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
|
@ -20,8 +21,8 @@ namespace sprout {
|
|||
)
|
||||
{
|
||||
typedef typename std::iterator_traits<InputIterator>::value_type value_type;
|
||||
using std::cos;
|
||||
using std::sin;
|
||||
using sprout::cos;
|
||||
using sprout::sin;
|
||||
return first != last
|
||||
? value + sprout::detail::dft_element_gen(
|
||||
sprout::next(first),
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef SPROUT_NUMERIC_DFT_FIXED_SINUSOID_HPP
|
||||
#define SPROUT_NUMERIC_DFT_FIXED_SINUSOID_HPP
|
||||
|
||||
#include <cmath>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/index_tuple.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
|
@ -9,6 +8,7 @@
|
|||
#include <sprout/container/indexes.hpp>
|
||||
#include <sprout/algorithm/fixed/result_of.hpp>
|
||||
#include <sprout/math/constants.hpp>
|
||||
#include <sprout/math/sin.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace fixed {
|
||||
|
@ -26,7 +26,7 @@ namespace sprout {
|
|||
)
|
||||
{
|
||||
typedef typename sprout::container_traits<Container>::value_type value_type;
|
||||
using std::sin;
|
||||
using sprout::sin;
|
||||
return sprout::remake<Container>(
|
||||
cont,
|
||||
size,
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
#ifndef SPROUT_NUMERIC_DFT_FIXED_SPECTRUM_HPP
|
||||
#define SPROUT_NUMERIC_DFT_FIXED_SPECTRUM_HPP
|
||||
|
||||
#include <cmath>
|
||||
#include <complex>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/index_tuple.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/algorithm/fixed/result_of.hpp>
|
||||
#include <sprout/complex.hpp>
|
||||
#include <sprout/math/sqrt.hpp>
|
||||
#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT
|
||||
|
||||
namespace sprout {
|
||||
|
@ -26,9 +26,9 @@ namespace sprout {
|
|||
typename sprout::container_traits<Result>::size_type input_size
|
||||
)
|
||||
{
|
||||
using std::sqrt;
|
||||
using std::real;
|
||||
using std::imag;
|
||||
using sprout::sqrt;
|
||||
using sprout::real;
|
||||
using sprout::imag;
|
||||
return sprout::remake<Result>(
|
||||
result,
|
||||
size,
|
||||
|
|
|
@ -7,6 +7,10 @@
|
|||
#include <stdexcept>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
#include <sprout/math/abs.hpp>
|
||||
#include <sprout/math/log.hpp>
|
||||
#include <sprout/math/pow.hpp>
|
||||
#include <sprout/math/sqrt.hpp>
|
||||
#include <sprout/random/random_result.hpp>
|
||||
#include <sprout/random/uniform_01.hpp>
|
||||
|
||||
|
@ -155,7 +159,7 @@ namespace sprout {
|
|||
return init_btrd_5(t, p, r, nr, npq, sqrt_npq, RealType(1.15) + RealType(2.53) * sqrt_npq);
|
||||
}
|
||||
static SPROUT_CONSTEXPR btrd_type init_btrd_3(IntType t, RealType p, RealType r, RealType nr, RealType npq) {
|
||||
using std::sqrt;
|
||||
using sprout::sqrt;
|
||||
return init_btrd_4(t, p, r, nr, npq, sqrt(npq));
|
||||
}
|
||||
static SPROUT_CONSTEXPR btrd_type init_btrd_2(IntType t, RealType p, RealType r) {
|
||||
|
@ -168,7 +172,7 @@ namespace sprout {
|
|||
return init_btrd_1(init_t(t), init_p(p));
|
||||
}
|
||||
static SPROUT_CONSTEXPR RealType init_q_n(IntType t, RealType p) {
|
||||
using std::pow;
|
||||
using sprout::pow;
|
||||
return pow(1 - init_p(p), static_cast<RealType>(init_t(t)));
|
||||
}
|
||||
static SPROUT_CONSTEXPR bool init_use_inversion(IntType t, RealType p) {
|
||||
|
@ -230,7 +234,7 @@ namespace sprout {
|
|||
}
|
||||
template<typename Engine>
|
||||
SPROUT_CONSTEXPR sprout::random::random_result<Engine, binomial_distribution> generate_10(Engine const& eng, RealType v, IntType k, IntType nm, RealType h, IntType nk) const {
|
||||
using std::log;
|
||||
using sprout::log;
|
||||
return v <= h + (t_ + 1) * log(static_cast<RealType>(nm) / nk) + (k + RealType(0.5)) * log(nk * btrd_.r / (k + 1))- fc(k)- fc(t_ - k)
|
||||
? sprout::random::random_result<Engine, binomial_distribution>(k, eng, *this)
|
||||
: generate(eng)
|
||||
|
@ -238,7 +242,7 @@ namespace sprout {
|
|||
}
|
||||
template<typename Engine>
|
||||
SPROUT_CONSTEXPR sprout::random::random_result<Engine, binomial_distribution> generate_9(Engine const& eng, RealType v, IntType k, IntType nm) const {
|
||||
using std::log;
|
||||
using sprout::log;
|
||||
return generate_10(eng, v, k, nm, (m_ + RealType(0.5)) * log((m_ + 1) / (btrd_.r * nm)) + fc(m_) + fc(t_ - m_), t_ - k + 1);
|
||||
}
|
||||
template<typename Engine>
|
||||
|
@ -278,7 +282,7 @@ namespace sprout {
|
|||
}
|
||||
template<typename Engine>
|
||||
SPROUT_CONSTEXPR sprout::random::random_result<Engine, binomial_distribution> generate_6(Engine const& eng, RealType v, IntType k, RealType km) const {
|
||||
using std::log;
|
||||
using sprout::log;
|
||||
return km <= 15
|
||||
? generate_7(eng, v, k)
|
||||
: generate_8(eng, log(v), k, (km / btrd_.npq) * (((km / RealType(3.0) + RealType(0.625)) * km + RealType(1.0) / 6) / btrd_.npq + RealType(0.5)), -km * km / (2 * btrd_.npq))
|
||||
|
@ -286,7 +290,7 @@ namespace sprout {
|
|||
}
|
||||
template<typename Engine>
|
||||
SPROUT_CONSTEXPR sprout::random::random_result<Engine, binomial_distribution> generate_5(Engine const& eng, RealType v, RealType u, RealType us, IntType k) const {
|
||||
using std::abs;
|
||||
using sprout::abs;
|
||||
return k < 0 || k > t_
|
||||
? generate(eng)
|
||||
: generate_6(eng, v * btrd_.alpha / (btrd_.a / (us * us) + btrd_.b), k, abs(k - m_))
|
||||
|
@ -299,7 +303,7 @@ namespace sprout {
|
|||
}
|
||||
template<typename Engine>
|
||||
SPROUT_CONSTEXPR sprout::random::random_result<Engine, binomial_distribution> generate_3(Engine const& eng, RealType v, RealType u) const {
|
||||
using std::abs;
|
||||
using sprout::abs;
|
||||
return generate_4(eng, v, u, 0.5 - abs(u));
|
||||
}
|
||||
template<typename Engine, typename Random>
|
||||
|
@ -320,7 +324,7 @@ namespace sprout {
|
|||
template<typename Engine>
|
||||
SPROUT_CONSTEXPR sprout::random::random_result<Engine, binomial_distribution> generate_1_1(Engine const& eng, RealType u) const {
|
||||
using std::floor;
|
||||
using std::abs;
|
||||
using sprout::abs;
|
||||
return sprout::random::random_result<Engine, binomial_distribution>(
|
||||
static_cast<IntType>(floor((2 * btrd_.a / (RealType(0.5) - abs(u)) + btrd_.b) * u + btrd_.c)),
|
||||
eng,
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <limits>
|
||||
#include <stdexcept>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/math/log.hpp>
|
||||
#include <sprout/random/random_result.hpp>
|
||||
#include <sprout/random/uniform_01.hpp>
|
||||
|
||||
|
@ -96,7 +97,7 @@ namespace sprout {
|
|||
private:
|
||||
public:
|
||||
static SPROUT_CONSTEXPR RealType init_log_1mp(RealType p) {
|
||||
using std::log;
|
||||
using sprout::log;
|
||||
return log(1 - p);
|
||||
}
|
||||
private:
|
||||
|
@ -106,7 +107,7 @@ namespace sprout {
|
|||
private:
|
||||
template<typename Engine, typename Random>
|
||||
SPROUT_CONSTEXPR sprout::random::random_result<Engine, geometric_distribution> generate_1(Random const& rnd) const {
|
||||
using std::log;
|
||||
using sprout::log;
|
||||
using std::floor;
|
||||
return sprout::random::random_result<Engine, geometric_distribution>(
|
||||
static_cast<IntType>(floor(log(RealType(1) - rnd.result()) / log_1mp_)),
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
#ifndef SPROUT_RANDOM_NORMAL_DISTRIBUTION_HPP
|
||||
#define SPROUT_RANDOM_NORMAL_DISTRIBUTION_HPP
|
||||
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
#include <ios>
|
||||
#include <istream>
|
||||
#include <stdexcept>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/math/constants.hpp>
|
||||
#include <sprout/math/sin.hpp>
|
||||
#include <sprout/math/cos.hpp>
|
||||
#include <sprout/math/log.hpp>
|
||||
#include <sprout/math/sqrt.hpp>
|
||||
#include <sprout/random/uniform_01.hpp>
|
||||
#include <sprout/random/random_result.hpp>
|
||||
|
||||
|
@ -121,8 +124,8 @@ namespace sprout {
|
|||
{}
|
||||
template<typename Engine>
|
||||
SPROUT_CONSTEXPR sprout::random::random_result<Engine, normal_distribution> generate_2(Engine const& eng, RealType r1, RealType r2, RealType cached_rho, bool valid) const {
|
||||
using std::sin;
|
||||
using std::cos;
|
||||
using sprout::sin;
|
||||
using sprout::cos;
|
||||
return sprout::random::random_result<Engine, normal_distribution>(
|
||||
cached_rho
|
||||
* (valid
|
||||
|
@ -144,8 +147,8 @@ namespace sprout {
|
|||
}
|
||||
template<typename Engine, typename Random>
|
||||
SPROUT_CONSTEXPR sprout::random::random_result<Engine, normal_distribution> generate_1_1(RealType r1, Random const& rnd) const {
|
||||
using std::sqrt;
|
||||
using std::log;
|
||||
using sprout::sqrt;
|
||||
using sprout::log;
|
||||
return generate_2(rnd.engine(), r1, rnd.result(), sqrt(-result_type(2) * log(result_type(1) - rnd.result())), true);
|
||||
}
|
||||
template<typename Engine, typename Random>
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define SPROUT_STRING_FLOAT_TO_STRING_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
|
|
Loading…
Reference in a new issue