add lround, llround

This commit is contained in:
bolero-MURAKAMI 2012-07-05 08:03:32 +09:00
parent 77f058a34c
commit 36fe60bec3
7 changed files with 140 additions and 28 deletions

View file

@ -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,8 +16,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 x - x0 < std::numeric_limits<FloatType>::epsilon() ? x0
: x0 + 1
;
}
@ -26,11 +26,11 @@ namespace sprout {
>
inline SPROUT_CONSTEXPR FloatType
ceil(FloatType x) {
return std::numeric_limits<std::uintmax_t>::max() < x || std::numeric_limits<std::uintmax_t>::max() < -x
? throw std::domain_error("ceil: Sorry, not implemented.")
: 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)))
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("ceil: Sorry, not implemented.")
: 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)))
;
}