clang-format + TODOs added to ratio

This commit is contained in:
Mateusz Pusz
2019-12-11 09:28:40 +01:00
parent 4304747406
commit c1e4e57d84

View File

@@ -23,19 +23,22 @@
#pragma once
#include <units/bits/external/hacks.h>
#include <type_traits>
#include <numeric>
#include <cstdint>
#include <numeric>
#include <type_traits>
namespace units {
namespace detail {
template<typename T>
[[nodiscard]] constexpr T abs(T v) noexcept { return v < 0 ? -v : v; }
[[nodiscard]] constexpr T abs(T v) noexcept
{
return v < 0 ? -v : v;
}
} // namespace detail
template<std::intmax_t Num, std::intmax_t Den = 1>
requires(Den != 0)
struct ratio {
@@ -63,6 +66,17 @@ namespace units {
template<typename T>
concept Ratio = detail::is_ratio<T>;
// ratio_add
// TODO implement ratio_add
// template<Ratio R1, Ratio R2>
// using ratio_add = detail::ratio_add_impl<R1, R2>::type;
// ratio_subtract
// TODO implement ratio_subtract
// template<Ratio R1, Ratio R2>
// using ratio_subtract = detail::ratio_subtract_impl<R1, R2>::type;
// ratio_multiply
namespace detail {
@@ -96,7 +110,7 @@ namespace units {
static constexpr std::intmax_t den = type::den;
};
}
} // namespace detail
template<Ratio R1, Ratio R2>
using ratio_multiply = detail::ratio_multiply_impl<R1, R2>::type;
@@ -113,7 +127,7 @@ namespace units {
static constexpr std::intmax_t den = type::den;
};
}
} // namespace detail
template<Ratio R1, Ratio R2>
using ratio_divide = detail::ratio_divide_impl<R1, R2>::type;
@@ -137,7 +151,7 @@ namespace units {
using type = ratio<1>;
};
}
} // namespace detail
template<Ratio R, std::size_t N>
using ratio_pow = detail::ratio_pow_impl<R, N>::type;
@@ -148,8 +162,7 @@ namespace units {
constexpr std::intmax_t sqrt_impl(std::intmax_t v, std::intmax_t l, std::intmax_t r)
{
if(l == r)
return r;
if (l == r) return r;
const auto mid = (r + l) / 2;
if (mid * mid >= v)
@@ -158,10 +171,7 @@ namespace units {
return sqrt_impl(v, mid + 1, r);
}
static constexpr std::intmax_t sqrt_impl(std::intmax_t v)
{
return sqrt_impl(v, 1, v);
}
static constexpr std::intmax_t sqrt_impl(std::intmax_t v) { return sqrt_impl(v, 1, v); }
template<typename R>
struct ratio_sqrt_impl {
@@ -173,12 +183,11 @@ namespace units {
using type = ratio<0>;
};
}
} // namespace detail
template<Ratio R>
using ratio_sqrt = detail::ratio_sqrt_impl<R>::type;
// common_ratio
namespace detail {
@@ -191,7 +200,7 @@ namespace units {
using type = ratio<gcd_num, (R1::den / gcd_den) * R2::den>;
};
}
} // namespace detail
template<Ratio R1, Ratio R2>
using common_ratio = detail::common_ratio_impl<R1, R2>::type;