mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2024-11-12 21:09:01 +00:00
fix math::float_promote
This commit is contained in:
parent
c2a401326c
commit
635145eda5
3 changed files with 44 additions and 26 deletions
|
@ -8,5 +8,6 @@
|
|||
#include <sprout/functional/divides.hpp>
|
||||
#include <sprout/functional/modulus.hpp>
|
||||
#include <sprout/functional/negate.hpp>
|
||||
#include <sprout/functional/posite.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_ARITHMETIC_HPP
|
||||
|
|
22
sprout/functional/posite.hpp
Normal file
22
sprout/functional/posite.hpp
Normal file
|
@ -0,0 +1,22 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_POSITE_HPP
|
||||
#define SPROUT_FUNCTIONAL_POSITE_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
|
||||
namespace sprout {
|
||||
// Copyright (C) 2011 RiSK (sscrisk)
|
||||
|
||||
// 20.8.4 Arithmetic operations
|
||||
template<typename T>
|
||||
struct posite {
|
||||
public:
|
||||
typedef T argument_type;
|
||||
typedef T result_type;
|
||||
public:
|
||||
SPROUT_CONSTEXPR T operator()(T const& x) const {
|
||||
return +x;
|
||||
}
|
||||
};
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_POSITE_HPP
|
|
@ -7,36 +7,31 @@
|
|||
namespace sprout {
|
||||
namespace math {
|
||||
namespace detail {
|
||||
template<bool IsArithmetic, typename Current, typename Head, typename... Tail>
|
||||
struct float_promote_impl {};
|
||||
template<typename Current, typename Head>
|
||||
struct float_promote_impl<true, Current, Head>
|
||||
template<typename T, typename U>
|
||||
struct float_promote2
|
||||
: public std::conditional<
|
||||
(std::is_same<Current, long double>::value || std::is_same<Head, long double>::value),
|
||||
long double,
|
||||
(std::is_same<T, long double>::value || std::is_same<U, long double>::value),
|
||||
std::common_type<long double>,
|
||||
typename std::conditional<
|
||||
(std::is_same<T, float>::value && std::is_same<U, float>::value),
|
||||
float,
|
||||
double
|
||||
>
|
||||
{};
|
||||
>::type
|
||||
{
|
||||
static_assert(std::is_arithmetic<U>::value, "float_promote requires arithmetic type.");
|
||||
};
|
||||
|
||||
template<typename Current, typename Head, typename... Tail>
|
||||
struct float_promote_impl<true, Current, Head, Tail...>
|
||||
struct float_promote_impl
|
||||
: public sprout::math::detail::float_promote_impl<
|
||||
std::is_arithmetic<Head>::value,
|
||||
typename std::conditional<
|
||||
(std::is_same<Current, long double>::value || std::is_same<Head, long double>::value),
|
||||
long double,
|
||||
double
|
||||
>::type,
|
||||
typename sprout::math::detail::float_promote2<Current, Head>::type,
|
||||
Tail...
|
||||
>
|
||||
{};
|
||||
|
||||
template<typename Head, typename... Tail>
|
||||
struct float_promote
|
||||
: public sprout::math::detail::float_promote_impl<
|
||||
std::is_arithmetic<Head>::value,
|
||||
double,
|
||||
Head, Tail...
|
||||
>
|
||||
template<typename Current, typename Head>
|
||||
struct float_promote_impl<Current, Head>
|
||||
: public sprout::math::detail::float_promote2<Current, Head>
|
||||
{};
|
||||
} // namespace detail
|
||||
|
||||
|
@ -45,8 +40,8 @@ namespace sprout {
|
|||
//
|
||||
template<typename... Types>
|
||||
struct float_promote
|
||||
: public sprout::math::detail::float_promote<
|
||||
typename std::remove_cv<Types>::type...
|
||||
: public sprout::math::detail::float_promote_impl<
|
||||
float, typename std::remove_cv<Types>::type...
|
||||
>
|
||||
{};
|
||||
} // namespace math
|
||||
|
|
Loading…
Reference in a new issue