Small refactoring of new ratio (resolves #14)

This commit is contained in:
Mateusz Pusz committed 2019-12-28 18:59:53 +01:00
1 parent 23d44c1b4a
commit 17e6b0d75d
6 files changed
+31 -19

No files matched your search

+8 -6
View File
@@ -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>() +
-1
View File
@@ -23,7 +23,6 @@
#pragma once
#include <units/prefix.h>
#include <ratio>
namespace units::data {
+2 -1
View File
@@ -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;