xo-unit: refactor: su.outer_scale_exact -> outer_scale_factor

This commit is contained in:
Roland Conybeare 2024-04-27 08:40:12 -04:00
commit b52ab13495
5 changed files with 31 additions and 30 deletions

View file

@ -62,7 +62,7 @@ namespace xo {
*/
repr_type r_scale = (::sqrt(rr.outer_scale_sq_)
* rr.outer_scale_exact_.template to<repr_type>()
* rr.outer_scale_factor_.template to<repr_type>()
* this->scale_);
return Quantity(r_scale, unit2);
} else {
@ -101,7 +101,7 @@ namespace xo {
auto rr = detail::su_product<r_int_type, r_int2x_type>(x.unit(), y.unit());
r_repr_type r_scale = (::sqrt(rr.outer_scale_sq_)
* rr.outer_scale_exact_.template to<r_repr_type>()
* rr.outer_scale_factor_.template to<r_repr_type>()
* static_cast<r_repr_type>(x.scale())
* static_cast<r_repr_type>(y.scale()));
@ -125,7 +125,7 @@ namespace xo {
* so multiply is correct here
*/
r_repr_type r_scale = (::sqrt(rr.outer_scale_sq_)
* rr.outer_scale_exact_.template to<r_repr_type>()
* rr.outer_scale_factor_.template to<r_repr_type>()
* static_cast<r_repr_type>(x.scale())
/ static_cast<r_repr_type>(y.scale()));
@ -149,7 +149,7 @@ namespace xo {
if (rr.natural_unit_.is_dimensionless()) {
r_repr_type r_scale = (static_cast<r_repr_type>(x.scale())
+ (::sqrt(rr.outer_scale_sq_)
* rr.outer_scale_exact_.template to<r_repr_type>()
* rr.outer_scale_factor_.template to<r_repr_type>()
* static_cast<r_repr_type>(y.scale())));
return Quantity<r_repr_type, r_int_type>(r_scale, x.unit_.template to_repr<r_int_type>());
@ -176,7 +176,7 @@ namespace xo {
if (rr.natural_unit_.is_dimensionless()) {
r_repr_type r_scale = (static_cast<r_repr_type>(x.scale())
- (::sqrt(rr.outer_scale_sq_)
* rr.outer_scale_exact_.template to<r_repr_type>()
* rr.outer_scale_factor_.template to<r_repr_type>()
* static_cast<r_repr_type>(y.scale())));
return Quantity<r_repr_type, r_int_type>(r_scale, x.unit_.template to_repr<r_int_type>());
@ -223,7 +223,7 @@ namespace xo {
inline constexpr Quantity<Repr, Int>
unit_qty(const scaled_unit<Int> & u) {
return Quantity<Repr, Int>
(u.outer_scale_exact_.template to<double>() * ::sqrt(u.outer_scale_sq_),
(u.outer_scale_factor_.template to<double>() * ::sqrt(u.outer_scale_sq_),
u.natural_unit_);
}

View file

@ -9,27 +9,28 @@
namespace xo {
namespace qty {
/** @class bpu2_array_rescale_result
/** @class scaled_unit
* @brief Represents the product sqrt(outer_scale_sq) * outer_scale_exact * nat_unit
**/
template <typename Int>
template < typename Int,
typename OuterScale = ratio::ratio<Int> >
struct scaled_unit {
constexpr scaled_unit(const natural_unit<Int> & nat_unit,
ratio::ratio<Int> outer_scale_exact,
double outer_scale_sq)
OuterScale outer_scale_factor,
double outer_scale_sq)
: natural_unit_{nat_unit},
outer_scale_exact_{outer_scale_exact},
outer_scale_factor_{outer_scale_factor},
outer_scale_sq_{outer_scale_sq}
{}
constexpr scaled_unit reciprocal() const {
return scaled_unit(nu_reciprocal(natural_unit_,
outer_scale_exact_.reciprocal(),
1 / outer_scale_factor_,
1.0 / outer_scale_sq_));
}
natural_unit<Int> natural_unit_;
ratio::ratio<Int> outer_scale_exact_;
OuterScale outer_scale_factor_;
double outer_scale_sq_;
};
@ -172,9 +173,9 @@ namespace xo {
return (scaled_unit<Int>
(rr.natural_unit_,
(ratio::ratio<Int2x>(rr.outer_scale_exact_)
* ratio::ratio<Int2x>(x_unit.outer_scale_exact_)
* ratio::ratio<Int2x>(y_unit.outer_scale_exact_)),
(ratio::ratio<Int2x>(rr.outer_scale_factor_)
* ratio::ratio<Int2x>(x_unit.outer_scale_factor_)
* ratio::ratio<Int2x>(y_unit.outer_scale_factor_)),
rr.outer_scale_sq_ * x_unit.outer_scale_sq_ * y_unit.outer_scale_sq_));
}
@ -189,9 +190,9 @@ namespace xo {
return (scaled_unit<Int>
(rr.natural_unit_,
(ratio::ratio<Int2x>(rr.outer_scale_exact_)
* ratio::ratio<Int2x>(x_unit.outer_scale_exact_)
* ratio::ratio<Int2x>(y_unit.outer_scale_exact_)),
(ratio::ratio<Int2x>(rr.outer_scale_factor_)
* ratio::ratio<Int2x>(x_unit.outer_scale_factor_)
* ratio::ratio<Int2x>(y_unit.outer_scale_factor_)),
rr.outer_scale_sq_ * x_unit.outer_scale_sq_ * y_unit.outer_scale_sq_));
}
} /*namespace qty*/

View file

@ -14,9 +14,9 @@ namespace xo {
inline std::ostream &
operator<<(std::ostream & os, const scaled_unit<Int> & x) {
os << "<scaled-unit"
<< xtag("bpuv", x.natural_unit_)
<< xtag("outer_scale_exact", x.outer_scale_exact_)
<< xtag("outer_scale_factor", x.outer_scale_factor_)
<< xtag("outer_scale_sq", x.outer_scale_sq_)
<< xtag("bpuv", x.natural_unit_)
<< ">";
return os;