diff --git a/include/xo/unit/Quantity.hpp b/include/xo/unit/Quantity.hpp index 2a7f1480..795e2795 100644 --- a/include/xo/unit/Quantity.hpp +++ b/include/xo/unit/Quantity.hpp @@ -53,10 +53,14 @@ namespace xo { constexpr auto rescale(const natural_unit & unit2) const { /* conversion factor from .unit -> unit2*/ - auto rr = detail::nu_ratio(this->unit_, unit2); if (rr.natural_unit_.is_dimensionless()) { + /* FIXME: rr.outer_scale_exact_ can overflow since fixed precision. + * accumulate in scale instead + */ + repr_type r_scale = (::sqrt(rr.outer_scale_sq_) * rr.outer_scale_exact_.template to() * this->scale_); @@ -115,9 +119,9 @@ namespace xo { using r_int2x_type = std::common_type_t; - auto rr = detail::nu_ratio(x.unit(), y.unit()); + auto rr = detail::su_ratio(x.unit(), y.unit()); - /* note: nu_ratio() reports multiplicative outer scaling factors, + /* note: su_ratio() reports multiplicative outer scaling factors, * so multiply is correct here */ r_repr_type r_scale = (::sqrt(rr.outer_scale_sq_) @@ -140,7 +144,7 @@ namespace xo { typename Quantity2::ratio_int2x_type>; /* conversion to get y in same units as x: multiply by y/x */ - auto rr = detail::nu_ratio(y.unit(), x.unit()); + auto rr = detail::su_ratio(y.unit(), x.unit()); if (rr.natural_unit_.is_dimensionless()) { r_repr_type r_scale = (static_cast(x.scale()) @@ -167,7 +171,7 @@ namespace xo { typename Quantity2::ratio_int2x_type>; /* conversion to get y in same units as x: multiply by y/x */ - auto rr = detail::nu_ratio(y.unit(), x.unit()); + auto rr = detail::su_ratio(y.unit(), x.unit()); if (rr.natural_unit_.is_dimensionless()) { r_repr_type r_scale = (static_cast(x.scale()) diff --git a/include/xo/unit/scaled_unit.hpp b/include/xo/unit/scaled_unit.hpp index e529b4ce..41cd4d7e 100644 --- a/include/xo/unit/scaled_unit.hpp +++ b/include/xo/unit/scaled_unit.hpp @@ -128,14 +128,11 @@ namespace xo { } /* use Int2x to accumulate scalefactor - * - * TODO: rename to su_ratio() - * */ template > constexpr scaled_unit - nu_ratio(const natural_unit & nu_lhs, + su_ratio(const natural_unit & nu_lhs, const natural_unit & nu_rhs) { natural_unit ratio = nu_lhs.template to_repr(); @@ -187,7 +184,7 @@ namespace xo { operator/ (const scaled_unit & x_unit, const scaled_unit & y_unit) { - auto rr = detail::nu_ratio(x_unit.natural_unit_, + auto rr = detail::su_ratio(x_unit.natural_unit_, y_unit.natural_unit_); return (scaled_unit diff --git a/utest/Quantity.test.cpp b/utest/Quantity.test.cpp index ef9b9694..aaeb6941 100644 --- a/utest/Quantity.test.cpp +++ b/utest/Quantity.test.cpp @@ -294,7 +294,7 @@ namespace xo { /* q1/q2, with exact representation (given no fractional dimensions) * */ - auto su = xo::qty::detail::nu_ratio(q1.unit(), q2.unit()); INFO(xtag("su.natural_unit", su.natural_unit_)); diff --git a/utest/unit.test.cpp b/utest/unit.test.cpp index 6221b0b5..458a15a2 100644 --- a/utest/unit.test.cpp +++ b/utest/unit.test.cpp @@ -44,7 +44,7 @@ namespace xo { using xo::qty::detail::nu_product; using xo::qty::detail::nu_bpu_product; using xo::qty::detail::nu_ratio_inplace; - using xo::qty::detail::nu_ratio; + using xo::qty::detail::su_ratio; using xo::qty::unit_qty; TEST_CASE("basis_unit", "[basis_unit]") { @@ -878,7 +878,7 @@ namespace xo { log && log(xtag("w.abbrev", w.abbrev())); - constexpr auto rr = nu_ratio(v, w); + constexpr auto rr = su_ratio(v, w); log && log(xtag("rr", rr)); @@ -896,7 +896,7 @@ namespace xo { log && log(xtag("w.abbrev", w.abbrev())); - constexpr auto rr = nu_ratio(v, w); + constexpr auto rr = su_ratio(v, w); log && log(xtag("rr", rr));