mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2025-10-05 13:00:00 +00:00
add SPROUT_ASSERT
This commit is contained in:
parent
a5e14e71e1
commit
07f052fb6e
32 changed files with 386 additions and 284 deletions
|
@ -2,10 +2,10 @@
|
|||
#define SPROUT_MATH_BERNOULLI_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <stdexcept>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/array/array.hpp>
|
||||
#include <sprout/assert.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace math {
|
||||
|
@ -233,11 +233,10 @@ namespace sprout {
|
|||
template<typename T, typename = typename std::enable_if<std::is_floating_point<T>::value>::type>
|
||||
inline SPROUT_CONSTEXPR T bernoulli_number(std::size_t x) {
|
||||
typedef typename std::remove_cv<T>::type type;
|
||||
return x <= sprout::math::bernoulli_number_limit<type>()
|
||||
? x == 1 ? type(-1) / 2
|
||||
return SPROUT_ASSERT(x <= sprout::math::bernoulli_number_limit<type>()),
|
||||
x == 1 ? type(-1) / 2
|
||||
: x % 2 ? type(0)
|
||||
: sprout::math::detail::bernoulli_numbers<type>::table[x / 2]
|
||||
: throw std::invalid_argument("bernoulli_number(): argument limit exceeded")
|
||||
;
|
||||
}
|
||||
} // namespace math
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace sprout {
|
|||
: x == std::numeric_limits<FloatType>::infinity() ? std::numeric_limits<FloatType>::infinity()
|
||||
: x == -std::numeric_limits<FloatType>::infinity() ? -std::numeric_limits<FloatType>::infinity()
|
||||
: std::numeric_limits<std::uintmax_t>::max() < x || std::numeric_limits<std::uintmax_t>::max() < -x
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::domain_error("ceil: large float rounding."), x)
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::runtime_error("ceil: large float rounding."), x)
|
||||
: x < 0 ? -static_cast<FloatType>(static_cast<std::uintmax_t>(-x))
|
||||
: sprout::math::detail::ceil_impl(x, static_cast<FloatType>(static_cast<std::uintmax_t>(x)))
|
||||
;
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
#define SPROUT_MATH_FACTORIAL_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <stdexcept>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/array/array.hpp>
|
||||
#include <sprout/type_traits/is_int.hpp>
|
||||
#include <sprout/type_traits/is_uint.hpp>
|
||||
#include <sprout/assert.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace math {
|
||||
|
@ -767,9 +767,8 @@ namespace sprout {
|
|||
template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value>::type>
|
||||
inline SPROUT_CONSTEXPR T factorial(std::size_t x) {
|
||||
typedef typename std::remove_cv<T>::type type;
|
||||
return x <= sprout::math::factorial_limit<type>()
|
||||
? sprout::math::detail::factorials<type>::table[x]
|
||||
: throw std::invalid_argument("factorial(): argument limit exceeded")
|
||||
return SPROUT_ASSERT(x <= sprout::math::factorial_limit<type>()),
|
||||
sprout::math::detail::factorials<type>::table[x]
|
||||
;
|
||||
}
|
||||
} // namespace math
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace sprout {
|
|||
: x == std::numeric_limits<FloatType>::infinity() ? std::numeric_limits<FloatType>::infinity()
|
||||
: x == -std::numeric_limits<FloatType>::infinity() ? -std::numeric_limits<FloatType>::infinity()
|
||||
: std::numeric_limits<std::uintmax_t>::max() < x || std::numeric_limits<std::uintmax_t>::max() < -x
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::domain_error("floor: large float rounding."), x)
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::runtime_error("floor: large float rounding."), x)
|
||||
: x < 0 ? sprout::math::detail::floor_impl(x, -static_cast<FloatType>(static_cast<std::uintmax_t>(-x)))
|
||||
: static_cast<FloatType>(static_cast<std::uintmax_t>(x))
|
||||
;
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace sprout {
|
|||
inline SPROUT_CONSTEXPR To
|
||||
iceil_impl(FloatType x) {
|
||||
return std::numeric_limits<To>::max() < x || std::numeric_limits<To>::min() > x
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::domain_error("iceil: large float rounding."), static_cast<To>(x))
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::runtime_error("iceil: large float rounding."), static_cast<To>(x))
|
||||
: static_cast<To>(x)
|
||||
;
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ namespace sprout {
|
|||
iceil(FloatType x) {
|
||||
return x == 0 ? To(0)
|
||||
: std::numeric_limits<To>::max() < x || std::numeric_limits<To>::min() > x
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::domain_error("iceil: large float rounding."), static_cast<To>(x))
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::runtime_error("iceil: large float rounding."), static_cast<To>(x))
|
||||
: sprout::math::detail::iceil_impl(x, static_cast<To>(x))
|
||||
;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace sprout {
|
|||
inline SPROUT_CONSTEXPR To
|
||||
ifloor_impl(FloatType x) {
|
||||
return std::numeric_limits<To>::max() < x || std::numeric_limits<To>::min() > x
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::domain_error("ifloor: large float rounding."), static_cast<To>(x))
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::runtime_error("ifloor: large float rounding."), static_cast<To>(x))
|
||||
: static_cast<To>(x)
|
||||
;
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ namespace sprout {
|
|||
ifloor(FloatType x) {
|
||||
return x == 0 ? To(0)
|
||||
: std::numeric_limits<To>::max() < x || std::numeric_limits<To>::min() > x
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::domain_error("ifloor: large float rounding."), static_cast<To>(x))
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::runtime_error("ifloor: large float rounding."), static_cast<To>(x))
|
||||
: sprout::math::detail::ifloor_impl(x, static_cast<To>(x))
|
||||
;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace sprout {
|
|||
inline SPROUT_CONSTEXPR To
|
||||
iround_impl(FloatType x) {
|
||||
return std::numeric_limits<To>::max() < x || std::numeric_limits<To>::min() > x
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::domain_error("iround: large float rounding."), static_cast<To>(x))
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::runtime_error("iround: large float rounding."), static_cast<To>(x))
|
||||
: static_cast<To>(x)
|
||||
;
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ namespace sprout {
|
|||
iround(FloatType x) {
|
||||
return x == 0 ? To(0)
|
||||
: std::numeric_limits<To>::max() < x || std::numeric_limits<To>::min() > x
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::domain_error("iround: large float irounding."), x)
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::runtime_error("iround: large float irounding."), x)
|
||||
: x < 0 ? sprout::math::detail::iround_impl_nagative(x, static_cast<To>(x))
|
||||
: sprout::math::detail::iround_impl_positive(x, static_cast<To>(x))
|
||||
;
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace sprout {
|
|||
inline SPROUT_CONSTEXPR To
|
||||
itrunc_impl(FloatType x) {
|
||||
return std::numeric_limits<To>::max() < x || std::numeric_limits<To>::min() > x
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::domain_error("itrunc: large float rounding."), static_cast<To>(x))
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::runtime_error("itrunc: large float rounding."), static_cast<To>(x))
|
||||
: static_cast<To>(x)
|
||||
;
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ namespace sprout {
|
|||
itrunc(FloatType x) {
|
||||
return x == 0 ? To(0)
|
||||
: std::numeric_limits<To>::max() < x || std::numeric_limits<To>::min() > x
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::domain_error("itrunc: large float rounding."), static_cast<To>(x))
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::runtime_error("itrunc: large float rounding."), static_cast<To>(x))
|
||||
: static_cast<To>(x)
|
||||
;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace sprout {
|
|||
: x == std::numeric_limits<FloatType>::infinity() ? std::numeric_limits<FloatType>::infinity()
|
||||
: x == -std::numeric_limits<FloatType>::infinity() ? -std::numeric_limits<FloatType>::infinity()
|
||||
: std::numeric_limits<std::uintmax_t>::max() < x || std::numeric_limits<std::uintmax_t>::max() < -x
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::domain_error("round: large float rounding."), x)
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::runtime_error("round: large float rounding."), x)
|
||||
: x < 0 ? sprout::math::detail::round_impl_nagative(x, -static_cast<FloatType>(static_cast<std::uintmax_t>(-x)))
|
||||
: sprout::math::detail::round_impl_positive(x, static_cast<FloatType>(static_cast<std::uintmax_t>(x)))
|
||||
;
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace sprout {
|
|||
: x == std::numeric_limits<FloatType>::infinity() ? std::numeric_limits<FloatType>::infinity()
|
||||
: x == -std::numeric_limits<FloatType>::infinity() ? -std::numeric_limits<FloatType>::infinity()
|
||||
: std::numeric_limits<std::uintmax_t>::max() < x || std::numeric_limits<std::uintmax_t>::max() < -x
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::domain_error("trunc: large float rounding."), x)
|
||||
? SPROUT_MATH_THROW_LARGE_FLOAT_ROUNDING(std::runtime_error("trunc: large float rounding."), x)
|
||||
: x < 0 ? -static_cast<FloatType>(static_cast<std::uintmax_t>(-x))
|
||||
: static_cast<FloatType>(static_cast<std::uintmax_t>(x))
|
||||
;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue