mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2025-10-05 13:00:00 +00:00
fix rational: for clang
This commit is contained in:
parent
c22735b212
commit
071217f1d4
13 changed files with 66 additions and 86 deletions
|
|
@ -26,9 +26,8 @@ namespace sprout {
|
|||
template<typename IntType>
|
||||
inline SPROUT_CONSTEXPR sprout::rational<IntType>
|
||||
operator-(rational<IntType> const& r) {
|
||||
return sprout::detail::make_rational<IntType>(
|
||||
-r.numerator(), r.denominator(),
|
||||
sprout::detail::rational_private_constructor_tag()
|
||||
return sprout::detail::rational_construct_access<IntType>::raw_construct(
|
||||
-r.numerator(), r.denominator()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -46,9 +45,8 @@ namespace sprout {
|
|||
IntType g, IntType den, IntType num
|
||||
)
|
||||
{
|
||||
return sprout::detail::make_rational<IntType>(
|
||||
num / g, den * (rhs.denominator() / g),
|
||||
sprout::detail::rational_private_constructor_tag()
|
||||
return sprout::detail::rational_construct_access<IntType>::raw_construct(
|
||||
num / g, den * (rhs.denominator() / g)
|
||||
);
|
||||
}
|
||||
template<typename IntType>
|
||||
|
|
@ -115,9 +113,8 @@ namespace sprout {
|
|||
IntType g, IntType den, IntType num
|
||||
)
|
||||
{
|
||||
return sprout::detail::make_rational<IntType>(
|
||||
num / g, den * (rhs.denominator() / g),
|
||||
sprout::detail::rational_private_constructor_tag()
|
||||
return sprout::detail::rational_construct_access<IntType>::raw_construct(
|
||||
num / g, den * (rhs.denominator() / g)
|
||||
);
|
||||
}
|
||||
template<typename IntType>
|
||||
|
|
@ -184,10 +181,9 @@ namespace sprout {
|
|||
IntType gcd1, IntType gcd2
|
||||
)
|
||||
{
|
||||
return sprout::detail::make_rational<IntType>(
|
||||
return sprout::detail::rational_construct_access<IntType>::raw_construct(
|
||||
(lhs.numerator() / gcd1) * (rhs.numerator() / gcd2),
|
||||
(lhs.denominator() / gcd2) * (rhs.denominator() / gcd1),
|
||||
sprout::detail::rational_private_constructor_tag()
|
||||
(lhs.denominator() / gcd2) * (rhs.denominator() / gcd1)
|
||||
);
|
||||
}
|
||||
} // namespace detail
|
||||
|
|
@ -215,14 +211,8 @@ namespace sprout {
|
|||
template<typename IntType>
|
||||
inline SPROUT_CONSTEXPR sprout::rational<IntType>
|
||||
rational_div_impl_1(IntType num, IntType den) {
|
||||
return den < IntType(0) ? sprout::detail::make_rational<IntType>(
|
||||
-num, -den,
|
||||
sprout::detail::rational_private_constructor_tag()
|
||||
)
|
||||
: sprout::detail::make_rational<IntType>(
|
||||
num, den,
|
||||
sprout::detail::rational_private_constructor_tag()
|
||||
)
|
||||
return den < IntType(0) ? sprout::detail::rational_construct_access<IntType>::raw_construct(-num, -den)
|
||||
: sprout::detail::rational_construct_access<IntType>::raw_construct(num, den)
|
||||
;
|
||||
}
|
||||
template<typename IntType>
|
||||
|
|
|
|||
|
|
@ -21,15 +21,10 @@ namespace sprout {
|
|||
class rational;
|
||||
|
||||
namespace detail {
|
||||
struct rational_private_constructor_tag {};
|
||||
struct rational_private_construct_t {};
|
||||
|
||||
template<typename IntType>
|
||||
inline SPROUT_CONSTEXPR sprout::rational<IntType>
|
||||
make_rational(
|
||||
typename sprout::detail::call_traits<IntType>::param_type n,
|
||||
typename sprout::detail::call_traits<IntType>::param_type d,
|
||||
sprout::detail::rational_private_constructor_tag
|
||||
);
|
||||
class rational_construct_access;
|
||||
} // namespace detail
|
||||
|
||||
namespace detail {
|
||||
|
|
@ -66,11 +61,11 @@ namespace sprout {
|
|||
: private sprout::detail::rational_impl<IntType>
|
||||
{
|
||||
static_assert(sprout::numeric_limits<IntType>::is_specialized, "sprout::numeric_limits<IntType>::is_specialized");
|
||||
friend class sprout::detail::rational_construct_access<IntType>;
|
||||
public:
|
||||
typedef IntType int_type;
|
||||
typedef typename sprout::detail::call_traits<IntType>::param_type param_type;
|
||||
private:
|
||||
struct private_constructor_tag {};
|
||||
typedef sprout::detail::rational_impl<IntType> base_type;
|
||||
private:
|
||||
static SPROUT_CONSTEXPR IntType normalize_g_1(IntType den, IntType g) {
|
||||
|
|
@ -86,7 +81,7 @@ namespace sprout {
|
|||
using base_type::num_;
|
||||
using base_type::den_;
|
||||
private:
|
||||
SPROUT_CONSTEXPR rational(param_type n, param_type d, private_constructor_tag)
|
||||
SPROUT_CONSTEXPR rational(sprout::detail::rational_private_construct_t, param_type n, param_type d)
|
||||
: base_type(n, d)
|
||||
{}
|
||||
public:
|
||||
|
|
@ -198,28 +193,24 @@ namespace sprout {
|
|||
SPROUT_CONSTEXPR operator bool() const SPROUT_NOEXCEPT {
|
||||
return num_ != 0;
|
||||
}
|
||||
public:
|
||||
friend sprout::rational<IntType> sprout::detail::make_rational<IntType>(
|
||||
typename sprout::detail::call_traits<IntType>::param_type n,
|
||||
typename sprout::detail::call_traits<IntType>::param_type d,
|
||||
sprout::detail::rational_private_constructor_tag
|
||||
);
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
template<typename IntType>
|
||||
inline SPROUT_CONSTEXPR sprout::rational<IntType>
|
||||
make_rational(
|
||||
typename sprout::detail::call_traits<IntType>::param_type n,
|
||||
typename sprout::detail::call_traits<IntType>::param_type d,
|
||||
sprout::detail::rational_private_constructor_tag
|
||||
)
|
||||
{
|
||||
return sprout::rational<IntType>(
|
||||
n, d,
|
||||
typename sprout::rational<IntType>::private_constructor_tag()
|
||||
);
|
||||
}
|
||||
class rational_construct_access {
|
||||
public:
|
||||
static SPROUT_CONSTEXPR sprout::rational<IntType>
|
||||
raw_construct(
|
||||
typename sprout::detail::call_traits<IntType>::param_type n,
|
||||
typename sprout::detail::call_traits<IntType>::param_type d
|
||||
)
|
||||
{
|
||||
return sprout::rational<IntType>(
|
||||
sprout::detail::rational_private_construct_t(),
|
||||
n, d
|
||||
);
|
||||
}
|
||||
};
|
||||
} // namespace detail
|
||||
} // namespace sprout
|
||||
|
||||
|
|
|
|||
|
|
@ -20,9 +20,8 @@ namespace sprout {
|
|||
inline SPROUT_CONSTEXPR sprout::rational<IntType>
|
||||
abs(sprout::rational<IntType> const& x) {
|
||||
return x.numerator() >= IntType(0) ? x
|
||||
: sprout::detail::make_rational<IntType>(
|
||||
-x.numerator(), x.denominator(),
|
||||
sprout::detail::rational_private_constructor_tag()
|
||||
: sprout::detail::rational_construct_access<IntType>::raw_construct(
|
||||
-x.numerator(), x.denominator()
|
||||
)
|
||||
;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue