add sprout/math/comparison.hpp

This commit is contained in:
bolero-MURAKAMI 2012-07-06 23:10:49 +09:00
parent d51bd06eda
commit 1c65d59971
20 changed files with 379 additions and 109 deletions

View file

@ -290,13 +290,11 @@ namespace sprout {
}
template<typename T>
SPROUT_CONSTEXPR T abs(sprout::complex<T> const& x) {
using sprout::sqrt;
return sqrt(sprout::norm(x));
return sprout::sqrt(sprout::norm(x));
}
template<typename T>
SPROUT_CONSTEXPR T arg(sprout::complex<T> const& x) {
using sprout::atan2;
return atan2(x.imag(), x.real());
return sprout::atan2(x.imag(), x.real());
}
template<typename T>
SPROUT_CONSTEXPR T norm(sprout::complex<T> const& x) {
@ -324,9 +322,7 @@ namespace sprout {
}
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> polar(T const& rho, T const& theta = 0) {
using sprout::cos;
using sprout::sin;
return sprout::complex<T>(rho * cos(theta), rho * sin(theta));
return sprout::complex<T>(rho * sprout::cos(theta), rho * sprout::sin(theta));
}
// 26.4.8, transcendentals:
template<typename T>
@ -397,11 +393,9 @@ namespace sprout {
T const& den
)
{
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))
T(0.5) * sprout::atan2(T(2) * x.real(), z),
T(0.25) * sprout::log((r2 + num * num) / (r2 + den * den))
);
}
template<typename T>
@ -449,11 +443,9 @@ namespace sprout {
T const& den
)
{
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)
T(0.25) * (sprout::log(i2 + num * num) - sprout::log(i2 + den * den)),
T(0.5) * sprout::atan2(T(2) * x.imag(), z)
);
}
template<typename T>
@ -477,30 +469,21 @@ namespace sprout {
}
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> cos(sprout::complex<T> const& x) {
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()))
sprout::cos(x.real()) * sprout::cosh(x.imag()),
-(sprout::sin(x.real()) * sprout::sinh(x.imag()))
);
}
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> cosh(sprout::complex<T> const& x) {
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())
sprout::cosh(x.real()) * sprout::cos(x.imag()),
sprout::sinh(x.real()) * sprout::sin(x.imag())
);
}
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> exp(sprout::complex<T> const& x) {
using sprout::exp;
return sprout::polar(exp(x.real()), x.imag());
return sprout::polar(sprout::exp(x.real()), x.imag());
}
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> log(sprout::complex<T> const& x) {
@ -508,21 +491,18 @@ namespace sprout {
}
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> log10(sprout::complex<T> const& x) {
using sprout::log;
return sprout::log(x) / log(T(10));
return sprout::log(x) / sprout::log(T(10));
}
namespace detail {
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> pow_impl(sprout::complex<T> const& t, T const& y) {
using sprout::exp;
return sprout::polar(exp(y * t.real()), y * t.imag());
return sprout::polar(sprout::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 sprout::pow;
return x == T() ? T()
: x.imag() == T() && x.real() > T() ? pow(x.real(), y)
: x.imag() == T() && x.real() > T() ? sprout::pow(x.real(), y)
: sprout::detail::pow_impl(sprout::log(x), y)
;
}
@ -534,31 +514,22 @@ namespace sprout {
}
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> pow(T const& x, sprout::complex<T> const& y) {
using sprout::log;
return x > T() ? sprout::polar(sprout::pow(x, y.real()), y.imag() * log(x))
return x > T() ? sprout::polar(sprout::pow(x, y.real()), y.imag() * sprout::log(x))
: sprout::pow(sprout::complex<T>(x), y)
;
}
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> sin(sprout::complex<T> const& x) {
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())
sprout::sin(x.real()) * sprout::cosh(x.imag()),
sprout::cos(x.real()) * sprout::sinh(x.imag())
);
}
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> sinh(sprout::complex<T> const& x) {
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())
sprout::sinh(x.real()) * sprout::cos(x.imag()),
sprout::cosh(x.real()) * sprout::sin(x.imag())
);
}
namespace detail {
@ -568,9 +539,8 @@ 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 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)
: sprout::complex<T>(sprout::abs(x.imag()) / t, x.imag() < T() ? -u : u)
;
}
template<typename T>
@ -580,10 +550,8 @@ namespace sprout {
} // namespace detail
template<typename T>
SPROUT_CONSTEXPR sprout::complex<T> sqrt(sprout::complex<T> const& x) {
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()))))
return x.real() == T() ? sprout::detail::sqrt_impl_1(x, sprout::sqrt(abs(x.imag()) / 2))
: sprout::detail::sqrt_impl_2(x, sprout::sqrt(2 * (sprout::abs(x) + sprout::abs(x.real()))))
;
}
template<typename T>

View file

@ -51,14 +51,11 @@ namespace sprout {
unit_type const& v
) const
{
using sprout::sqrt;
using sprout::sin;
using sprout::cos;
return transform_1(
c,
u * cos(rotate_) - v * sin(rotate_),
u * sin(rotate_) + v * cos(rotate_),
sqrt(
u * sprout::cos(rotate_) - v * sprout::sin(rotate_),
u * sprout::sin(rotate_) + v * sprout::cos(rotate_),
sprout::sqrt(
sprout::darkroom::coords::x(c) * sprout::darkroom::coords::x(c)
+ sprout::darkroom::coords::z(c) * sprout::darkroom::coords::z(c)
)

View file

@ -63,8 +63,7 @@ namespace sprout {
template<typename Vector>
inline SPROUT_CONSTEXPR typename sprout::darkroom::access::unit<Vector>::type
length(Vector const& vec) {
using sprout::sqrt;
return sqrt(sprout::darkroom::coords::length_sq(vec));
return sprout::sqrt(sprout::darkroom::coords::length_sq(vec));
}
//
// add

View file

@ -121,8 +121,10 @@ namespace sprout {
}
template<typename Unit>
SPROUT_CONSTEXPR result_type calc_bilinear(Unit const& x, Unit const& y) const {
using sprout::floor;
return calc_bilinear_1(x, floor(x - 0.5), floor(x + 0.5), y, floor(y - 0.5), floor(y + 0.5));
return calc_bilinear_1(
x, sprout::floor(x - 0.5), sprout::floor(x + 0.5),
y, sprout::floor(y - 0.5), sprout::floor(y + 0.5)
);
}
template<typename Unit>
SPROUT_CONSTEXPR result_type calc(Unit const& x, Unit const& y) const {

View file

@ -143,8 +143,6 @@ namespace sprout {
Vec const& normal
) const
{
using sprout::atan2;
using sprout::sqrt;
return typename intersection<Ray>::type(
sprout::tuples::get<zw::does_intersect>(zwo),
sprout::tuples::get<zw::distance>(zwo),
@ -152,15 +150,15 @@ namespace sprout {
sprout::tuples::get<dr::normal>(drei),
sprout::darkroom::materials::calc_material( // ! Spherical
mat_,
atan2(
sprout::atan2(
sprout::darkroom::coords::z(normal),
sprout::darkroom::coords::x(normal)
)
/ sprout::math::pi<unit_type>()
,
atan2(
sprout::atan2(
sprout::darkroom::coords::y(normal),
sqrt(
sprout::sqrt(
sprout::darkroom::coords::x(normal) * sprout::darkroom::coords::x(normal)
+ sprout::darkroom::coords::z(normal) * sprout::darkroom::coords::z(normal)
)
@ -206,14 +204,13 @@ namespace sprout {
unit_type const& det_sq
) const
{
using sprout::sqrt;
return intersect_4(
ray,
zweitens(
ray,
det_sq > 0,
b,
sqrt(det_sq)
sprout::sqrt(det_sq)
)
);
}

View file

@ -91,8 +91,7 @@ namespace sprout {
template<typename FloatType, typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler>
inline SPROUT_CONSTEXPR int
float_digit_of_impl(FloatType val) {
using sprout::floor;
return static_cast<int>((val - floor(val)) * 10);
return static_cast<int>((val - sprout::floor(val)) * 10);
}
template<typename FloatType>
inline SPROUT_CONSTEXPR int
@ -106,8 +105,7 @@ namespace sprout {
template<typename FloatType, typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler>
inline SPROUT_CONSTEXPR FloatType
float_round_impl(FloatType val, FloatType p10) {
using sprout::round;
return round(val * p10) / p10;
return sprout::round(val * p10) / p10;
}
template<typename FloatType>
inline SPROUT_CONSTEXPR FloatType

View file

@ -8,6 +8,7 @@
#include <sprout/config.hpp>
#include <sprout/math/detail/config.hpp>
#include <sprout/math/isinf.hpp>
#include <sprout/math/equal_to.hpp>
#include <sprout/type_traits/enabler_if.hpp>
namespace sprout {
@ -16,7 +17,7 @@ namespace sprout {
template<typename FloatType>
inline SPROUT_CONSTEXPR FloatType
ceil_impl(FloatType x, FloatType x0) {
return x - x0 < std::numeric_limits<FloatType>::epsilon() ? x0
return sprout::math::equal_to(x, x0) ? x0
: x0 + 1
;
}

38
sprout/math/compare.hpp Normal file
View file

@ -0,0 +1,38 @@
#ifndef SPROUT_MATH_COMPARE_HPP
#define SPROUT_MATH_COMPARE_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/math/equal_to.hpp>
#include <sprout/math/float_promote.hpp>
#include <sprout/type_traits/enabler_if.hpp>
namespace sprout {
namespace math {
namespace detail {
template<typename T>
inline SPROUT_CONSTEXPR int
compare_impl(T x, T y) {
return sprout::math::equal_to(x, y) ? 0
: x < y ? -1
: 1
;
}
} // namespace detail
//
// compare
//
template<
typename T1,
typename T2,
typename sprout::enabler_if<std::is_arithmetic<T1>::value && std::is_arithmetic<T2>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR int
compare(T1 x, T2 y) {
typedef typename sprout::math::float_promote<T1, T2>::type promoted;
return sprout::math::detail::compare_impl<promoted>(x, y);
}
} // namespace math
} // namespace sprout
#endif // #ifndef SPROUT_MATH_COMPARE_HPP

View file

@ -0,0 +1,13 @@
#ifndef SPROUT_MATH_COMPARISON_HPP
#define SPROUT_MATH_COMPARISON_HPP
#include <sprout/config.hpp>
#include <sprout/math/equal_to.hpp>
#include <sprout/math/not_equal_to.hpp>
#include <sprout/math/greater.hpp>
#include <sprout/math/less.hpp>
#include <sprout/math/greater_equal.hpp>
#include <sprout/math/less_equal.hpp>
#include <sprout/math/compare.hpp>
#endif // #ifndef SPROUT_MATH_COMPARISON_HPP

58
sprout/math/equal_to.hpp Normal file
View file

@ -0,0 +1,58 @@
#ifndef SPROUT_MATH_EQUAL_TO_HPP
#define SPROUT_MATH_EQUAL_TO_HPP
#include <limits>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/algorithm/max.hpp>
#include <sprout/math/abs.hpp>
#include <sprout/math/float_promote.hpp>
#include <sprout/type_traits/enabler_if.hpp>
namespace sprout {
namespace math {
namespace detail {
template<typename T>
inline SPROUT_CONSTEXPR T
max3(T x, T y, T z) {
return sprout::max(sprout::max(x, y), z);
}
template<
typename FloatType,
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR bool
equal_to(FloatType x, FloatType y) {
return x == y
|| sprout::abs(x - y)
<= std::numeric_limits<FloatType>::epsilon() * sprout::math::detail::max3(std::abs(x), std::abs(y), FloatType(1.0))
;
}
template<
typename IntType,
typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR bool
equal_to(IntType x, IntType y) {
return x == y;
}
} // namespace detail
//
// equal_to
//
template<
typename T1,
typename T2,
typename sprout::enabler_if<std::is_arithmetic<T1>::value && std::is_arithmetic<T2>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR bool
equal_to(T1 x, T2 y) {
typedef typename sprout::math::float_promote<T1, T2>::type promoted;
return sprout::math::detail::equal_to<promoted>(x, y);
}
} // namespace math
} // namespace sprout
#endif // #ifndef SPROUT_MATH_EQUAL_TO_HPP

View file

@ -8,6 +8,7 @@
#include <sprout/config.hpp>
#include <sprout/math/detail/config.hpp>
#include <sprout/math/isinf.hpp>
#include <sprout/math/equal_to.hpp>
#include <sprout/type_traits/enabler_if.hpp>
namespace sprout {
@ -16,7 +17,7 @@ namespace sprout {
template<typename FloatType>
inline SPROUT_CONSTEXPR FloatType
floor_impl(FloatType x, FloatType x0) {
return x0 - x < std::numeric_limits<FloatType>::epsilon() ? x0
return sprout::math::equal_to(x, x0) ? x0
: x0 - 1
;
}

View file

@ -12,5 +12,6 @@
#include <sprout/math/common_factor.hpp>
#include <sprout/math/factorial.hpp>
#include <sprout/math/bernoulli.hpp>
#include <sprout/math/comparison.hpp>
#endif // #ifndef SPROUT_MATH_FUNCTIONS_HPP

47
sprout/math/greater.hpp Normal file
View file

@ -0,0 +1,47 @@
#ifndef SPROUT_MATH_GREATER_HPP
#define SPROUT_MATH_GREATER_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/math/not_equal_to.hpp>
#include <sprout/math/float_promote.hpp>
#include <sprout/type_traits/enabler_if.hpp>
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 bool
greater(FloatType x, FloatType y) {
return sprout::math::not_equal_to(x, y) && x > y;
}
template<
typename IntType,
typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR bool
greater(IntType x, IntType y) {
return x > y;
}
} // namespace detail
//
// greater
//
template<
typename T1,
typename T2,
typename sprout::enabler_if<std::is_arithmetic<T1>::value && std::is_arithmetic<T2>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR bool
greater(T1 x, T2 y) {
typedef typename sprout::math::float_promote<T1, T2>::type promoted;
return sprout::math::detail::greater<promoted>(x, y);
}
} // namespace math
} // namespace sprout
#endif // #ifndef SPROUT_MATH_GREATER_HPP

View file

@ -0,0 +1,47 @@
#ifndef SPROUT_MATH_GREATER_EQUAL_HPP
#define SPROUT_MATH_GREATER_EQUAL_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/math/equal_to.hpp>
#include <sprout/math/float_promote.hpp>
#include <sprout/type_traits/enabler_if.hpp>
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 bool
greater_equal(FloatType x, FloatType y) {
return sprout::math::equal_to(x, y) || x > y;
}
template<
typename IntType,
typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR bool
greater_equal(IntType x, IntType y) {
return x >= y;
}
} // namespace detail
//
// greater_equal
//
template<
typename T1,
typename T2,
typename sprout::enabler_if<std::is_arithmetic<T1>::value && std::is_arithmetic<T2>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR bool
greater_equal(T1 x, T2 y) {
typedef typename sprout::math::float_promote<T1, T2>::type promoted;
return sprout::math::detail::greater_equal<promoted>(x, y);
}
} // namespace math
} // namespace sprout
#endif // #ifndef SPROUT_MATH_GREATER_EQUAL_HPP

47
sprout/math/less.hpp Normal file
View file

@ -0,0 +1,47 @@
#ifndef SPROUT_MATH_LESS_HPP
#define SPROUT_MATH_LESS_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/math/not_equal_to.hpp>
#include <sprout/math/float_promote.hpp>
#include <sprout/type_traits/enabler_if.hpp>
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 bool
less(FloatType x, FloatType y) {
return sprout::math::not_equal_to(x, y) && x < y;
}
template<
typename IntType,
typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR bool
less(IntType x, IntType y) {
return x < y;
}
} // namespace detail
//
// less
//
template<
typename T1,
typename T2,
typename sprout::enabler_if<std::is_arithmetic<T1>::value && std::is_arithmetic<T2>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR bool
less(T1 x, T2 y) {
typedef typename sprout::math::float_promote<T1, T2>::type promoted;
return sprout::math::detail::less<promoted>(x, y);
}
} // namespace math
} // namespace sprout
#endif // #ifndef SPROUT_MATH_LESS_HPP

View file

@ -0,0 +1,47 @@
#ifndef SPROUT_MATH_LESS_EQUAL_HPP
#define SPROUT_MATH_LESS_EQUAL_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/math/equal_to.hpp>
#include <sprout/math/float_promote.hpp>
#include <sprout/type_traits/enabler_if.hpp>
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 bool
less_equal(FloatType x, FloatType y) {
return sprout::math::equal_to(x, y) || x < y;
}
template<
typename IntType,
typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR bool
less_equal(IntType x, IntType y) {
return x <= y;
}
} // namespace detail
//
// less_equal
//
template<
typename T1,
typename T2,
typename sprout::enabler_if<std::is_arithmetic<T1>::value && std::is_arithmetic<T2>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR bool
less_equal(T1 x, T2 y) {
typedef typename sprout::math::float_promote<T1, T2>::type promoted;
return sprout::math::detail::less_equal<promoted>(x, y);
}
} // namespace math
} // namespace sprout
#endif // #ifndef SPROUT_MATH_LESS_EQUAL_HPP

View file

@ -0,0 +1,26 @@
#ifndef SPROUT_MATH_NOT_EQUAL_TO_HPP
#define SPROUT_MATH_NOT_EQUAL_TO_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/math/equal_to.hpp>
#include <sprout/type_traits/enabler_if.hpp>
namespace sprout {
namespace math {
//
// not_equal_to
//
template<
typename T1,
typename T2,
typename sprout::enabler_if<std::is_arithmetic<T1>::value && std::is_arithmetic<T2>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR bool
not_equal_to(T1 x, T2 y) {
return !sprout::math::equal_to(x, y);
}
} // namespace math
} // namespace sprout
#endif // #ifndef SPROUT_MATH_NOT_EQUAL_TO_HPP

View file

@ -168,8 +168,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 sprout::sqrt;
return init_btrd_4(t, p, r, nr, npq, sqrt(npq));
return init_btrd_4(t, p, r, nr, npq, sprout::sqrt(npq));
}
static SPROUT_CONSTEXPR btrd_type init_btrd_2(IntType t, RealType p, RealType r) {
return init_btrd_3(t, p, r, (t + 1) * r, t * p * (1 - p));
@ -181,8 +180,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 sprout::pow;
return pow(1 - init_p(p), static_cast<RealType>(init_t(t)));
return sprout::pow(1 - init_p(p), static_cast<RealType>(init_t(t)));
}
static SPROUT_CONSTEXPR bool init_use_inversion(IntType t, RealType p) {
return init_m(t, p) < 11;
@ -243,16 +241,14 @@ 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 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)
return v <= h + (t_ + 1) * sprout::log(static_cast<RealType>(nm) / nk) + (k + RealType(0.5)) * sprout::log(nk * btrd_.r / (k + 1)) - fc(k) - fc(t_ - k)
? sprout::random::random_result<Engine, binomial_distribution>(k, eng, *this)
: generate(eng)
;
}
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 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);
return generate_10(eng, v, k, nm, (m_ + RealType(0.5)) * sprout::log((m_ + 1) / (btrd_.r * nm)) + fc(m_) + fc(t_ - m_), t_ - k + 1);
}
template<typename Engine>
SPROUT_CONSTEXPR sprout::random::random_result<Engine, binomial_distribution> generate_8(Engine const& eng, RealType v, IntType k, RealType rho, RealType t) const {
@ -291,29 +287,25 @@ 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 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))
: generate_8(eng, sprout::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))
;
}
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 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_))
: generate_6(eng, v * btrd_.alpha / (btrd_.a / (us * us) + btrd_.b), k, sprout::abs(k - m_))
;
}
template<typename Engine>
SPROUT_CONSTEXPR sprout::random::random_result<Engine, binomial_distribution> generate_4(Engine const& eng, RealType v, RealType u, RealType us) const {
using sprout::floor;
return generate_5(eng, v, u, us, static_cast<IntType>(floor((2 * btrd_.a / us + btrd_.b) * u + btrd_.c)));
return generate_5(eng, v, u, us, static_cast<IntType>(sprout::floor((2 * btrd_.a / us + btrd_.b) * u + btrd_.c)));
}
template<typename Engine>
SPROUT_CONSTEXPR sprout::random::random_result<Engine, binomial_distribution> generate_3(Engine const& eng, RealType v, RealType u) const {
using sprout::abs;
return generate_4(eng, v, u, 0.5 - abs(u));
return generate_4(eng, v, u, 0.5 - sprout::abs(u));
}
template<typename Engine, typename Random>
SPROUT_CONSTEXPR sprout::random::random_result<Engine, binomial_distribution> generate_2(Random const& rnd, RealType v) const {
@ -332,10 +324,8 @@ namespace sprout {
}
template<typename Engine>
SPROUT_CONSTEXPR sprout::random::random_result<Engine, binomial_distribution> generate_1_1(Engine const& eng, RealType u) const {
using sprout::floor;
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)),
static_cast<IntType>(sprout::floor((2 * btrd_.a / (RealType(0.5) - sprout::abs(u)) + btrd_.b) * u + btrd_.c)),
eng,
*this
);

View file

@ -87,8 +87,7 @@ namespace sprout {
private:
public:
static SPROUT_CONSTEXPR RealType init_log_1mp(RealType p) {
using sprout::log;
return log(1 - p);
return sprout::log(1 - p);
}
private:
public:
@ -97,10 +96,8 @@ namespace sprout {
private:
template<typename Engine, typename Random>
SPROUT_CONSTEXPR sprout::random::random_result<Engine, geometric_distribution> generate_1(Random const& rnd) const {
using sprout::log;
using sprout::floor;
return sprout::random::random_result<Engine, geometric_distribution>(
static_cast<IntType>(floor(log(RealType(1) - rnd.result()) / log_1mp_)),
static_cast<IntType>(sprout::floor(sprout::log(RealType(1) - rnd.result()) / log_1mp_)),
rnd.engine(),
*this
);

View file

@ -124,13 +124,11 @@ 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 sprout::sin;
using sprout::cos;
return sprout::random::random_result<Engine, normal_distribution>(
cached_rho
* (valid
? cos(result_type(2) * sprout::math::pi<result_type>() * r1)
: sin(result_type(2) * sprout::math::pi<result_type>() * r1)
? sprout::cos(result_type(2) * sprout::math::pi<result_type>() * r1)
: sprout::sin(result_type(2) * sprout::math::pi<result_type>() * r1)
)
* sigma_ + mean_,
eng,
@ -147,9 +145,7 @@ 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 sprout::sqrt;
using sprout::log;
return generate_2(rnd.engine(), r1, rnd.result(), sqrt(-result_type(2) * log(result_type(1) - rnd.result())), true);
return generate_2(rnd.engine(), r1, rnd.result(), sprout::sqrt(-result_type(2) * sprout::log(result_type(1) - rnd.result())), true);
}
template<typename Engine, typename Random>
SPROUT_CONSTEXPR sprout::random::random_result<Engine, normal_distribution> generate_1(Random const& rnd) const {