mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2025-08-03 12:49:50 +00:00
add lround, llround
This commit is contained in:
parent
77f058a34c
commit
36fe60bec3
7 changed files with 140 additions and 28 deletions
|
@ -7,6 +7,7 @@
|
|||
#include <stdexcept>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/math/detail/config.hpp>
|
||||
#include <sprout/math/isinf.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
|
||||
namespace sprout {
|
||||
|
@ -15,16 +16,14 @@ namespace sprout {
|
|||
template<typename FloatType>
|
||||
inline SPROUT_CONSTEXPR FloatType
|
||||
round_impl_positive(FloatType x, FloatType x0) {
|
||||
return x - x0 < FloatType(0.5)
|
||||
? x0
|
||||
return x - x0 < FloatType(0.5) ? x0
|
||||
: x0 + 1
|
||||
;
|
||||
}
|
||||
template<typename FloatType>
|
||||
inline SPROUT_CONSTEXPR FloatType
|
||||
round_impl_nagative(FloatType x, FloatType x0) {
|
||||
return x0 - x < FloatType(0.5)
|
||||
? x0
|
||||
return x0 - x < FloatType(0.5) ? x0
|
||||
: x0 - 1
|
||||
;
|
||||
}
|
||||
|
@ -34,11 +33,11 @@ namespace sprout {
|
|||
>
|
||||
inline SPROUT_CONSTEXPR FloatType
|
||||
round(FloatType x) {
|
||||
return std::numeric_limits<std::uintmax_t>::max() < x || std::numeric_limits<std::uintmax_t>::max() < -x
|
||||
? throw std::domain_error("round: Sorry, not implemented.")
|
||||
: 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)))
|
||||
return sprout::math::isinf(x) ? x
|
||||
: std::numeric_limits<std::uintmax_t>::max() < x || std::numeric_limits<std::uintmax_t>::max() < -x
|
||||
? throw std::domain_error("round: Sorry, not implemented.")
|
||||
: 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)))
|
||||
;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue