xo-unit: tidy: nu_ratio -> su_ratio

This commit is contained in:
Roland Conybeare 2024-04-27 08:07:45 -04:00
commit 80a439e0a8
4 changed files with 15 additions and 14 deletions

View file

@ -53,10 +53,14 @@ namespace xo {
constexpr
auto rescale(const natural_unit<Int> & unit2) const {
/* conversion factor from .unit -> unit2*/
auto rr = detail::nu_ratio<ratio_int_type,
auto rr = detail::su_ratio<ratio_int_type,
ratio_int2x_type>(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<repr_type>()
* this->scale_);
@ -115,9 +119,9 @@ namespace xo {
using r_int2x_type = std::common_type_t<typename Quantity::ratio_int2x_type,
typename Quantity2::ratio_int2x_type>;
auto rr = detail::nu_ratio<r_int_type, r_int2x_type>(x.unit(), y.unit());
auto rr = detail::su_ratio<r_int_type, r_int2x_type>(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<r_int_type, r_int2x_type>(y.unit(), x.unit());
auto rr = detail::su_ratio<r_int_type, r_int2x_type>(y.unit(), x.unit());
if (rr.natural_unit_.is_dimensionless()) {
r_repr_type r_scale = (static_cast<r_repr_type>(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<r_int_type, r_int2x_type>(y.unit(), x.unit());
auto rr = detail::su_ratio<r_int_type, r_int2x_type>(y.unit(), x.unit());
if (rr.natural_unit_.is_dimensionless()) {
r_repr_type r_scale = (static_cast<r_repr_type>(x.scale())

View file

@ -128,14 +128,11 @@ namespace xo {
}
/* use Int2x to accumulate scalefactor
*
* TODO: rename to su_ratio()
*
*/
template <typename Int, typename Int2x = width2x<Int>>
constexpr
scaled_unit<Int>
nu_ratio(const natural_unit<Int> & nu_lhs,
su_ratio(const natural_unit<Int> & nu_lhs,
const natural_unit<Int> & nu_rhs)
{
natural_unit<Int2x> ratio = nu_lhs.template to_repr<Int2x>();
@ -187,7 +184,7 @@ namespace xo {
operator/ (const scaled_unit<Int> & x_unit,
const scaled_unit<Int> & y_unit)
{
auto rr = detail::nu_ratio<Int, Int2x>(x_unit.natural_unit_,
auto rr = detail::su_ratio<Int, Int2x>(x_unit.natural_unit_,
y_unit.natural_unit_);
return (scaled_unit<Int>

View file

@ -294,7 +294,7 @@ namespace xo {
/* q1/q2, with exact representation (given no fractional dimensions)
*
*/
auto su = xo::qty::detail::nu_ratio<decltype(q1)::ratio_int_type,
auto su = xo::qty::detail::su_ratio<decltype(q1)::ratio_int_type,
decltype(q1)::ratio_int2x_type>(q1.unit(), q2.unit());
INFO(xtag("su.natural_unit", su.natural_unit_));

View file

@ -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<int64_t, __int128_t>(v, w);
constexpr auto rr = su_ratio<int64_t, __int128_t>(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<int64_t, __int128_t>(v, w);
constexpr auto rr = su_ratio<int64_t, __int128_t>(v, w);
log && log(xtag("rr", rr));