mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-07-16 15:14:13 +00:00
workaround for no c++11 numeric_limits
This commit is contained in:
parent
ce16e24637
commit
7a1974742a
110 changed files with 727 additions and 436 deletions
|
@ -2,10 +2,10 @@
|
|||
#define SPROUT_MATH_TRUNC_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
#include <stdexcept>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/limits.hpp>
|
||||
#include <sprout/math/detail/config.hpp>
|
||||
#include <sprout/math/isnan.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
|
@ -20,13 +20,13 @@ namespace sprout {
|
|||
inline SPROUT_CONSTEXPR FloatType
|
||||
trunc(FloatType x) {
|
||||
return sprout::math::isnan(x) ? x
|
||||
: x == std::numeric_limits<FloatType>::infinity() ? std::numeric_limits<FloatType>::infinity()
|
||||
: x == -std::numeric_limits<FloatType>::infinity() ? -std::numeric_limits<FloatType>::infinity()
|
||||
: x == sprout::numeric_limits<FloatType>::infinity() ? sprout::numeric_limits<FloatType>::infinity()
|
||||
: x == -sprout::numeric_limits<FloatType>::infinity() ? -sprout::numeric_limits<FloatType>::infinity()
|
||||
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
|
||||
: std::trunc(x)
|
||||
#else
|
||||
: x == 0 ? x
|
||||
: std::numeric_limits<std::uintmax_t>::max() < x || std::numeric_limits<std::uintmax_t>::max() < -x
|
||||
: sprout::numeric_limits<std::uintmax_t>::max() < x || sprout::numeric_limits<std::uintmax_t>::max() < -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