forked from mpusz/mp-units
Library updated to the latest cmake common tools
This commit is contained in:
@@ -33,7 +33,7 @@ template<Exponent E>
|
||||
struct exp_ratio {
|
||||
using base_ratio = E::dimension::base_unit::ratio;
|
||||
using positive_ratio = conditional<E::num * E::den < 0, ratio<base_ratio::den, base_ratio::num, -base_ratio::exp>, base_ratio>;
|
||||
static constexpr std::int64_t N = E::num * E::den < 0 ? -E::num : E::num;
|
||||
static constexpr std::intmax_t N = E::num * E::den < 0 ? -E::num : E::num;
|
||||
using pow = ratio_pow<positive_ratio, N>;
|
||||
using type = conditional<E::den == 2, ratio_sqrt<pow>, pow>;
|
||||
};
|
||||
|
||||
@@ -54,7 +54,7 @@ struct dim_consolidate<exp_list<E1, ERest...>> {
|
||||
using type = type_list_push_front<typename dim_consolidate<exp_list<ERest...>>::type, E1>;
|
||||
};
|
||||
|
||||
template<BaseDimension Dim, int Num1, int Den1, int Num2, int Den2, typename... ERest>
|
||||
template<BaseDimension Dim, std::intmax_t Num1, std::intmax_t Den1, std::intmax_t Num2, std::intmax_t Den2, typename... ERest>
|
||||
struct dim_consolidate<exp_list<exp<Dim, Num1, Den1>, exp<Dim, Num2, Den2>, ERest...>> {
|
||||
// TODO: provide custom implementation for ratio_add
|
||||
using r1 = std::ratio<Num1, Den1>;
|
||||
|
||||
@@ -41,17 +41,17 @@ struct dim_unpack<> {
|
||||
using type = exp_list<>;
|
||||
};
|
||||
|
||||
template<BaseDimension Dim, int Num, int Den, Exponent... ERest>
|
||||
template<BaseDimension Dim, std::intmax_t Num, std::intmax_t Den, Exponent... ERest>
|
||||
struct dim_unpack<exp<Dim, Num, Den>, ERest...> {
|
||||
using type = type_list_push_front<typename dim_unpack<ERest...>::type, exp<Dim, Num, Den>>;
|
||||
};
|
||||
|
||||
template<DerivedDimension Dim, int Num, int Den, Exponent... ERest>
|
||||
template<DerivedDimension Dim, std::intmax_t Num, std::intmax_t Den, Exponent... ERest>
|
||||
struct dim_unpack<exp<Dim, Num, Den>, ERest...> {
|
||||
using type = dim_unpack<exp<downcast_base_t<Dim>, Num, Den>, ERest...>::type;
|
||||
};
|
||||
|
||||
template<Exponent... Es, int Num, int Den, Exponent... ERest>
|
||||
template<Exponent... Es, std::intmax_t Num, std::intmax_t Den, Exponent... ERest>
|
||||
struct dim_unpack<exp<derived_dimension_base<Es...>, Num, Den>, ERest...> {
|
||||
using type = type_list_push_front<typename dim_unpack<ERest...>::type, exp_multiply<Es, Num, Den>...>;
|
||||
};
|
||||
|
||||
@@ -43,7 +43,7 @@ struct equivalent_dim_impl<D1, D2> : std::disjunction<std::is_same<D1, D2>, equi
|
||||
template<Exponent E1, Exponent E2>
|
||||
struct equivalent_exp : std::false_type {};
|
||||
|
||||
template<BaseDimension Dim1, int Num, int Den, BaseDimension Dim2>
|
||||
template<BaseDimension Dim1, std::intmax_t Num, std::intmax_t Den, BaseDimension Dim2>
|
||||
struct equivalent_exp<exp<Dim1, Num, Den>, exp<Dim2, Num, Den>> : equivalent_dim_impl<Dim1, Dim2> {};
|
||||
|
||||
template<DerivedDimension D1, DerivedDimension D2>
|
||||
@@ -230,10 +230,10 @@ using dimension_sqrt = detail::dimension_sqrt_impl<D>::type;
|
||||
// dimension_pow
|
||||
namespace detail {
|
||||
|
||||
template<Dimension D, std::size_t N>
|
||||
template<Dimension D, std::intmax_t N>
|
||||
struct dimension_pow_impl;
|
||||
|
||||
template<BaseDimension D, std::size_t N>
|
||||
template<BaseDimension D, std::intmax_t N>
|
||||
struct dimension_pow_impl<D, N> {
|
||||
using type = downcast_dimension<derived_dimension_base<exp<D, N>>>;
|
||||
};
|
||||
@@ -243,24 +243,24 @@ struct dimension_pow_impl<D, 1> {
|
||||
using type = D;
|
||||
};
|
||||
|
||||
template<BaseDimension D, std::size_t N>
|
||||
template<BaseDimension D, std::intmax_t N>
|
||||
struct dimension_pow_impl<derived_dimension_base<exp<D, 1, N>>, N> {
|
||||
using type = D;
|
||||
};
|
||||
|
||||
template<DerivedDimension D, std::size_t N>
|
||||
template<DerivedDimension D, std::intmax_t N>
|
||||
struct dimension_pow_impl<D, N> {
|
||||
using type = dimension_pow_impl<downcast_base_t<D>, N>::type;
|
||||
};
|
||||
|
||||
template<typename... Es, std::size_t N>
|
||||
template<typename... Es, std::intmax_t N>
|
||||
struct dimension_pow_impl<derived_dimension_base<Es...>, N> {
|
||||
using type = downcast_dimension<derived_dimension_base<exp_multiply<Es, N, 1>...>>;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<Dimension D, std::size_t N>
|
||||
template<Dimension D, std::intmax_t N>
|
||||
using dimension_pow = detail::dimension_pow_impl<D, N>::type;
|
||||
|
||||
} // namespace units
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace units {
|
||||
* @tparam Num numinator of the factor
|
||||
* @tparam Den denominator of the factor
|
||||
*/
|
||||
template<Dimension Dim, int Num, int Den = 1>
|
||||
template<Dimension Dim, std::intmax_t Num, std::intmax_t Den = 1>
|
||||
struct exp {
|
||||
using dimension = Dim;
|
||||
static constexpr int num = Num;
|
||||
@@ -44,7 +44,7 @@ struct exp {
|
||||
// is_exp
|
||||
namespace detail {
|
||||
|
||||
template<typename Dim, int Num, int Den>
|
||||
template<typename Dim, std::intmax_t Num, std::intmax_t Den>
|
||||
inline constexpr bool is_exp<exp<Dim, Num, Den>> = true;
|
||||
|
||||
} // namespace detail
|
||||
@@ -57,7 +57,7 @@ struct exp_less : base_dimension_less<typename E1::dimension, typename E2::dimen
|
||||
// exp_invert
|
||||
namespace detail {
|
||||
|
||||
template<typename Dim, int Num, int Den>
|
||||
template<typename Dim, std::intmax_t Num, std::intmax_t Den>
|
||||
constexpr exp<Dim, -Num, Den> exp_invert_impl(exp<Dim, Num, Den>);
|
||||
|
||||
} // namespace detail
|
||||
@@ -68,7 +68,7 @@ using exp_invert = decltype(detail::exp_invert_impl(E()));
|
||||
// exp_multiply
|
||||
namespace detail {
|
||||
|
||||
template<Exponent E, int Num, int Den>
|
||||
template<Exponent E, std::intmax_t Num, std::intmax_t Den>
|
||||
struct exp_multiply_impl {
|
||||
using r1 = ratio<E::num, E::den>;
|
||||
using r2 = ratio<Num, Den>;
|
||||
@@ -78,7 +78,7 @@ struct exp_multiply_impl {
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<Exponent E, int Num, int Den>
|
||||
template<Exponent E, std::intmax_t Num, std::intmax_t Den>
|
||||
using exp_multiply = detail::exp_multiply_impl<E, Num, Den>::type;
|
||||
|
||||
template<Exponent... Es>
|
||||
|
||||
@@ -199,8 +199,8 @@ private:
|
||||
constexpr void on_minus() { f.specs.sign = fmt::sign::minus; }
|
||||
constexpr void on_space() { f.specs.sign = fmt::sign::space; }
|
||||
constexpr void on_align(align_t align) { f.specs.align = align; }
|
||||
constexpr void on_width(unsigned width) { f.specs.width = width; }
|
||||
constexpr void on_precision(unsigned precision) { f.precision = precision; }
|
||||
constexpr void on_width(int width) { f.specs.width = width; }
|
||||
constexpr void on_precision(int precision) { f.precision = precision; }
|
||||
constexpr void end_precision() {}
|
||||
|
||||
template<typename Id>
|
||||
|
||||
@@ -27,14 +27,14 @@
|
||||
|
||||
namespace units {
|
||||
|
||||
template<std::size_t N, typename D, typename U, typename Rep>
|
||||
template<std::intmax_t N, typename D, typename U, typename Rep>
|
||||
requires (N == 0)
|
||||
inline Rep pow(const quantity<D, U, Rep>&) noexcept
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
template<std::size_t N, typename D, typename U, typename Rep>
|
||||
template<std::intmax_t N, typename D, typename U, typename Rep>
|
||||
inline Quantity AUTO pow(const quantity<D, U, Rep>& q) noexcept
|
||||
{
|
||||
using dim = dimension_pow<D, N>;
|
||||
|
||||
@@ -27,7 +27,8 @@
|
||||
|
||||
namespace units {
|
||||
|
||||
constexpr std::intmax_t ipow10(std::intmax_t exp) {
|
||||
constexpr std::intmax_t ipow10(std::intmax_t exp)
|
||||
{
|
||||
// how to assert here?
|
||||
// static_assert(exp >= 0, "Use fpow10() for negative exponents");
|
||||
if (exp == 0) return 1;
|
||||
@@ -40,7 +41,8 @@ constexpr std::intmax_t ipow10(std::intmax_t exp) {
|
||||
}
|
||||
|
||||
|
||||
constexpr long double fpow10(std::intmax_t exp) {
|
||||
constexpr long double fpow10(std::intmax_t exp)
|
||||
{
|
||||
if (exp == 0) return 1.0L;
|
||||
long double result = 1.0L;
|
||||
if (exp < 0) {
|
||||
|
||||
@@ -40,7 +40,7 @@ template<typename T>
|
||||
return v < 0 ? -v : v;
|
||||
}
|
||||
|
||||
constexpr std::tuple<std::intmax_t, std::intmax_t, std::intmax_t> normalize(std::intmax_t num, std::intmax_t den, std::intmax_t exp)
|
||||
constexpr std::tuple<std::intmax_t, std::intmax_t, std::intmax_t> normalize(std::intmax_t num, std::intmax_t den, std::intmax_t exp)
|
||||
{
|
||||
std::intmax_t gcd = std::gcd(num, den);
|
||||
num = num * (den < 0 ? -1 : 1) / gcd;
|
||||
@@ -100,12 +100,12 @@ namespace detail {
|
||||
|
||||
static constexpr std::intmax_t safe_multiply(std::intmax_t lhs, std::intmax_t rhs)
|
||||
{
|
||||
constexpr std::uintmax_t c = std::uintmax_t(1) << (sizeof(std::intmax_t) * 4);
|
||||
constexpr std::intmax_t c = std::uintmax_t(1) << (sizeof(std::intmax_t) * 4);
|
||||
|
||||
const std::uintmax_t a0 = detail::abs(lhs) % c;
|
||||
const std::uintmax_t a1 = detail::abs(lhs) / c;
|
||||
const std::uintmax_t b0 = detail::abs(rhs) % c;
|
||||
const std::uintmax_t b1 = detail::abs(rhs) / c;
|
||||
const std::intmax_t a0 = detail::abs(lhs) % c;
|
||||
const std::intmax_t a1 = detail::abs(lhs) / c;
|
||||
const std::intmax_t b0 = detail::abs(rhs) % c;
|
||||
const std::intmax_t b1 = detail::abs(rhs) / c;
|
||||
|
||||
Expects(a1 == 0 || b1 == 0); // overflow in multiplication
|
||||
Expects(a0 * b1 + b0 * a1 < (c >> 1)); // overflow in multiplication
|
||||
@@ -163,7 +163,7 @@ using ratio_divide = detail::ratio_divide_impl<R1, R2>::type;
|
||||
|
||||
namespace detail {
|
||||
|
||||
template<typename R, std::size_t N>
|
||||
template<typename R, std::intmax_t N>
|
||||
struct ratio_pow_impl {
|
||||
using type = ratio_multiply<typename ratio_pow_impl<R, N - 1>::type, R>;
|
||||
};
|
||||
@@ -180,7 +180,7 @@ struct ratio_pow_impl<R, 0> {
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<Ratio R, std::size_t N>
|
||||
template<Ratio R, std::intmax_t N>
|
||||
using ratio_pow = detail::ratio_pow_impl<R, N>::type;
|
||||
|
||||
// ratio_sqrt
|
||||
|
||||
Reference in New Issue
Block a user