forked from mpusz/mp-units
Fix formatting
This commit is contained in:
@@ -307,8 +307,9 @@ template<typename T>
|
|||||||
return checked_square(int_power(base, exp / 2));
|
return checked_square(int_power(base, exp / 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
[[nodiscard]] consteval std::optional<T> checked_int_pow(T base, std::uintmax_t exp) {
|
[[nodiscard]] consteval std::optional<T> checked_int_pow(T base, std::uintmax_t exp)
|
||||||
|
{
|
||||||
T result = T{1};
|
T result = T{1};
|
||||||
while (exp > 0u) {
|
while (exp > 0u) {
|
||||||
if (exp % 2u == 1u) {
|
if (exp % 2u == 1u) {
|
||||||
@@ -321,17 +322,16 @@ template <typename T>
|
|||||||
exp /= 2u;
|
exp /= 2u;
|
||||||
|
|
||||||
if (base > std::numeric_limits<T>::max() / base) {
|
if (base > std::numeric_limits<T>::max() / base) {
|
||||||
return (exp == 0u)
|
return (exp == 0u) ? std::make_optional(result) : std::nullopt;
|
||||||
? std::make_optional(result)
|
|
||||||
: std::nullopt;
|
|
||||||
}
|
}
|
||||||
base *= base;
|
base *= base;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
[[nodiscard]] consteval std::optional<T> root(T x, std::uintmax_t n) {
|
[[nodiscard]] consteval std::optional<T> root(T x, std::uintmax_t n)
|
||||||
|
{
|
||||||
// The "zeroth root" would be mathematically undefined.
|
// The "zeroth root" would be mathematically undefined.
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
@@ -444,12 +444,10 @@ template<typename T>
|
|||||||
const auto final_result = (exp.den > 1) ? root(pow_result.value(), static_cast<uintmax_t>(exp.den)) : pow_result;
|
const auto final_result = (exp.den > 1) ? root(pow_result.value(), static_cast<uintmax_t>(exp.den)) : pow_result;
|
||||||
if (final_result.has_value()) {
|
if (final_result.has_value()) {
|
||||||
return final_result.value();
|
return final_result.value();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
std::abort(); // Root computation failed.
|
std::abort(); // Root computation failed.
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
std::abort(); // Power computation failed.
|
std::abort(); // Power computation failed.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -53,8 +53,9 @@ using namespace mp_units::si::unit_symbols;
|
|||||||
// quantity class invariants
|
// quantity class invariants
|
||||||
//////////////////////////////
|
//////////////////////////////
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
constexpr bool within_4_ulps(T a, T b) {
|
constexpr bool within_4_ulps(T a, T b)
|
||||||
|
{
|
||||||
static_assert(std::is_floating_point_v<T>);
|
static_assert(std::is_floating_point_v<T>);
|
||||||
auto walk_ulps = [](T x, int n) {
|
auto walk_ulps = [](T x, int n) {
|
||||||
while (n > 0) {
|
while (n > 0) {
|
||||||
@@ -223,10 +224,8 @@ static_assert(within_4_ulps(sqrt((1.0 * m) * (1.0 * km)).numerical_value_in(m),
|
|||||||
|
|
||||||
// Reproducing issue #494 exactly:
|
// Reproducing issue #494 exactly:
|
||||||
constexpr auto val_issue_494 = 8.0 * si::si2019::boltzmann_constant * 1000.0 * K / (std::numbers::pi * 10 * Da);
|
constexpr auto val_issue_494 = 8.0 * si::si2019::boltzmann_constant * 1000.0 * K / (std::numbers::pi * 10 * Da);
|
||||||
static_assert(
|
static_assert(within_4_ulps(sqrt(val_issue_494).numerical_value_in(m / s),
|
||||||
within_4_ulps(
|
sqrt(val_issue_494.numerical_value_in(m* m / s / s))));
|
||||||
sqrt(val_issue_494).numerical_value_in(m / s),
|
|
||||||
sqrt(val_issue_494.numerical_value_in(m * m / s / s))));
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////////
|
///////////////////////
|
||||||
|
Reference in New Issue
Block a user