mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-07-16 15:14:13 +00:00
fix math functions
This commit is contained in:
parent
dad3acceea
commit
2e2b6c96ab
30 changed files with 121 additions and 84 deletions
|
@ -1,12 +1,14 @@
|
|||
#ifndef SPROUT_MATH_FLOAT2_SIG_EXP_HPP
|
||||
#define SPROUT_MATH_FLOAT2_SIG_EXP_HPP
|
||||
|
||||
#include <climits>
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/math/detail/config.hpp>
|
||||
#include <sprout/detail/pow.hpp>
|
||||
#include <sprout/math/float2_exponent.hpp>
|
||||
#include <sprout/math/detail/config.hpp>
|
||||
#include <sprout/math/isnan.hpp>
|
||||
#include <sprout/math/ilogb2.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
#include <sprout/utility/pair/pair.hpp>
|
||||
|
||||
|
@ -17,12 +19,7 @@ namespace sprout {
|
|||
inline SPROUT_CONSTEXPR sprout::pair<T, int>
|
||||
float2_sig_exp_impl(T x, int exp) {
|
||||
typedef sprout::pair<T, int> type;
|
||||
return x == 0 ? type(T(0), exp)
|
||||
: x == std::numeric_limits<T>::infinity() ? type(std::numeric_limits<T>::infinity(), exp)
|
||||
: x == -std::numeric_limits<T>::infinity() ? type(-std::numeric_limits<T>::infinity(), exp)
|
||||
: x == std::numeric_limits<T>::quiet_NaN() ? type(std::numeric_limits<T>::quiet_NaN(), exp)
|
||||
: type(x / sprout::detail::pow_n(T(2), exp), exp)
|
||||
;
|
||||
return type(x / sprout::detail::pow_n(T(2), exp), exp);
|
||||
}
|
||||
|
||||
template<
|
||||
|
@ -31,9 +28,14 @@ namespace sprout {
|
|||
>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<FloatType, int>
|
||||
float2_sig_exp(FloatType x) {
|
||||
return sprout::math::detail::float2_sig_exp_impl(x, sprout::math::float2_exponent(x));
|
||||
typedef sprout::pair<FloatType, int> type;
|
||||
return x == std::numeric_limits<FloatType>::infinity() ? type(std::numeric_limits<FloatType>::infinity(), 0)
|
||||
: x == -std::numeric_limits<FloatType>::infinity() ? type(-std::numeric_limits<FloatType>::infinity(), 0)
|
||||
: sprout::math::isnan(x) ? type(std::numeric_limits<FloatType>::quiet_NaN(), FP_ILOGBNAN)
|
||||
: x == 0 ? type(x, 0)
|
||||
: sprout::math::detail::float2_sig_exp_impl(x, sprout::math::ilogb2(x) + 1)
|
||||
;
|
||||
}
|
||||
|
||||
template<
|
||||
typename IntType,
|
||||
typename sprout::enabler_if<std::is_integral<IntType>::value>::type = sprout::enabler
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue