Small refactoring of new ratio (resolves #14)
This commit is contained in:
1 parent
23d44c1b4a
commit
17e6b0d75d
6 files changed
+31
-19
No files matched your search
@@ -31,12 +31,14 @@ constexpr auto ratio_text()
|
||||
{
|
||||
if constexpr(Ratio::num != 1 || Ratio::den != 1 || Ratio::exp != 0) {
|
||||
auto txt = basic_fixed_string("[") + regular<Ratio::num>();
|
||||
if constexpr(Ratio::den == 1 && Ratio::exp == 0) {
|
||||
return txt + basic_fixed_string("]");
|
||||
}
|
||||
else if constexpr (Ratio::den == 1) {
|
||||
return txt + basic_fixed_string(" \u00D7 10") + superscript<Ratio::exp>() +
|
||||
basic_fixed_string("]");
|
||||
if constexpr(Ratio::den == 1) {
|
||||
if constexpr(Ratio::exp == 0) {
|
||||
return txt + basic_fixed_string("]");
|
||||
}
|
||||
else {
|
||||
return txt + basic_fixed_string(" \u00D7 10") + superscript<Ratio::exp>() +
|
||||
basic_fixed_string("]");
|
||||
}
|
||||
}
|
||||
else {
|
||||
return txt + basic_fixed_string("/") + regular<Ratio::den>() +
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <units/prefix.h>
|
||||
#include <ratio>
|
||||
|
||||
namespace units::data {
|
||||
|
||||
|
||||
@@ -40,7 +40,8 @@ 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;
|
||||
den = detail::abs(den) / gcd;
|
||||
|
||||
Reference in new issue
Block a user