mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-07-14 15:04:09 +00:00
fix fmod
This commit is contained in:
parent
56cb7702ea
commit
3498e9214f
4 changed files with 123 additions and 23 deletions
|
@ -6,6 +6,9 @@
|
|||
#include <stdexcept>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/math/detail/config.hpp>
|
||||
#include <sprout/math/detail/float_compute.hpp>
|
||||
#include <sprout/math/isnan.hpp>
|
||||
#include <sprout/math/signbit.hpp>
|
||||
#include <sprout/math/iround.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
#include <sprout/type_traits/float_promote.hpp>
|
||||
|
@ -13,6 +16,12 @@
|
|||
namespace sprout {
|
||||
namespace math {
|
||||
namespace detail {
|
||||
template<typename R, typename T>
|
||||
inline SPROUT_CONSTEXPR T
|
||||
quotient_impl(T x, T y) {
|
||||
return sprout::math::iround<R>(x / y);
|
||||
}
|
||||
|
||||
template<
|
||||
typename R = int,
|
||||
typename FloatType,
|
||||
|
@ -20,14 +29,17 @@ namespace sprout {
|
|||
>
|
||||
inline SPROUT_CONSTEXPR R
|
||||
quotient(FloatType x, FloatType y) {
|
||||
return x == std::numeric_limits<FloatType>::infinity() || x == -std::numeric_limits<FloatType>::infinity() || y == 0
|
||||
? std::numeric_limits<FloatType>::quiet_NaN()
|
||||
: x == 0 ? FloatType(0)
|
||||
: y == std::numeric_limits<FloatType>::infinity() || y == -std::numeric_limits<FloatType>::infinity() ? FloatType(0)
|
||||
: sprout::math::iround<R>(x / y)
|
||||
return sprout::math::isnan(y) || sprout::math::isnan(x) ? R(0)
|
||||
: x == 0 && y != 0 ? R(0)
|
||||
: x == std::numeric_limits<FloatType>::infinity() || x == -std::numeric_limits<FloatType>::infinity() || y == 0
|
||||
? R(0)
|
||||
: y == std::numeric_limits<FloatType>::infinity() || y == -std::numeric_limits<FloatType>::infinity() ? R(0)
|
||||
: static_cast<FloatType>(sprout::math::detail::quotient_impl<R>(
|
||||
static_cast<typename sprout::math::detail::float_compute<FloatType>::type>(x),
|
||||
static_cast<typename sprout::math::detail::float_compute<FloatType>::type>(y)
|
||||
))
|
||||
;
|
||||
}
|
||||
|
||||
template<
|
||||
typename R = int,
|
||||
typename ArithmeticType1,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue