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/divides.hpp>
|
||||||
#include <sprout/functional/modulus.hpp>
|
#include <sprout/functional/modulus.hpp>
|
||||||
#include <sprout/functional/negate.hpp>
|
#include <sprout/functional/negate.hpp>
|
||||||
|
#include <sprout/functional/posite.hpp>
|
||||||
|
|
||||||
#endif // #ifndef SPROUT_FUNCTIONAL_ARITHMETIC_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 sprout {
|
||||||
namespace math {
|
namespace math {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
template<bool IsArithmetic, typename Current, typename Head, typename... Tail>
|
template<typename T, typename U>
|
||||||
struct float_promote_impl {};
|
struct float_promote2
|
||||||
template<typename Current, typename Head>
|
|
||||||
struct float_promote_impl<true, Current, Head>
|
|
||||||
: public std::conditional<
|
: public std::conditional<
|
||||||
(std::is_same<Current, long double>::value || std::is_same<Head, long double>::value),
|
(std::is_same<T, long double>::value || std::is_same<U, long double>::value),
|
||||||
long double,
|
std::common_type<long double>,
|
||||||
|
typename std::conditional<
|
||||||
|
(std::is_same<T, float>::value && std::is_same<U, float>::value),
|
||||||
|
float,
|
||||||
double
|
double
|
||||||
>
|
>
|
||||||
{};
|
>::type
|
||||||
|
{
|
||||||
|
static_assert(std::is_arithmetic<U>::value, "float_promote requires arithmetic type.");
|
||||||
|
};
|
||||||
|
|
||||||
template<typename Current, typename Head, typename... Tail>
|
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<
|
: public sprout::math::detail::float_promote_impl<
|
||||||
std::is_arithmetic<Head>::value,
|
typename sprout::math::detail::float_promote2<Current, Head>::type,
|
||||||
typename std::conditional<
|
|
||||||
(std::is_same<Current, long double>::value || std::is_same<Head, long double>::value),
|
|
||||||
long double,
|
|
||||||
double
|
|
||||||
>::type,
|
|
||||||
Tail...
|
Tail...
|
||||||
>
|
>
|
||||||
{};
|
{};
|
||||||
|
template<typename Current, typename Head>
|
||||||
template<typename Head, typename... Tail>
|
struct float_promote_impl<Current, Head>
|
||||||
struct float_promote
|
: public sprout::math::detail::float_promote2<Current, Head>
|
||||||
: public sprout::math::detail::float_promote_impl<
|
|
||||||
std::is_arithmetic<Head>::value,
|
|
||||||
double,
|
|
||||||
Head, Tail...
|
|
||||||
>
|
|
||||||
{};
|
{};
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
|
@ -45,8 +40,8 @@ namespace sprout {
|
||||||
//
|
//
|
||||||
template<typename... Types>
|
template<typename... Types>
|
||||||
struct float_promote
|
struct float_promote
|
||||||
: public sprout::math::detail::float_promote<
|
: public sprout::math::detail::float_promote_impl<
|
||||||
typename std::remove_cv<Types>::type...
|
float, typename std::remove_cv<Types>::type...
|
||||||
>
|
>
|
||||||
{};
|
{};
|
||||||
} // namespace math
|
} // namespace math
|
||||||
|
|
Loading…
Reference in a new issue