xo-unit: refactor: su.outer_scale_exact -> outer_scale_factor
This commit is contained in:
parent
09f05f648f
commit
b52ab13495
5 changed files with 31 additions and 30 deletions
|
|
@ -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_);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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*/
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -298,7 +298,7 @@ namespace xo {
|
|||
decltype(q1)::ratio_int2x_type>(q1.unit(), q2.unit());
|
||||
|
||||
INFO(xtag("su.natural_unit", su.natural_unit_));
|
||||
INFO(xtag("su.outer_scale_exact", su.outer_scale_exact_));
|
||||
INFO(xtag("su.outer_scale_exact", su.outer_scale_factor_));
|
||||
INFO(xtag("su.outer_scale_sq", su.outer_scale_sq_));
|
||||
|
||||
REQUIRE(q1 == q1);
|
||||
|
|
|
|||
|
|
@ -597,7 +597,7 @@ namespace xo {
|
|||
constexpr auto prod_rr = su_bpu_product(v, bpu);
|
||||
|
||||
log && log(xtag("prod_rr.bpu_array", prod_rr.natural_unit_));
|
||||
log && log(xtag("prod_rr.outer_scale_exact", prod_rr.outer_scale_exact_));
|
||||
log && log(xtag("prod_rr.outer_scale_exact", prod_rr.outer_scale_factor_));
|
||||
log && log(xtag("prod_rr.outer_scale_sq", prod_rr.outer_scale_sq_));
|
||||
|
||||
static_assert(prod_rr.natural_unit_.n_bpu() == 3);
|
||||
|
|
@ -610,7 +610,7 @@ namespace xo {
|
|||
static_assert(prod_rr.natural_unit_[2].native_dim() == dim::time);
|
||||
static_assert(prod_rr.natural_unit_[2].scalefactor() == scalefactor_ratio_type(250*24*3600, 1));
|
||||
static_assert(prod_rr.natural_unit_[2].power() == power_ratio_type(-1, 2));
|
||||
static_assert(prod_rr.outer_scale_exact_ == scalefactor_ratio_type(1, 1));
|
||||
static_assert(prod_rr.outer_scale_factor_ == scalefactor_ratio_type(1, 1));
|
||||
static_assert(prod_rr.outer_scale_sq_ == 1.0);
|
||||
}
|
||||
} /*TEST_CASE(bpu_array_product0)*/
|
||||
|
|
@ -644,7 +644,7 @@ namespace xo {
|
|||
constexpr auto prod_rr = su_bpu_product(v, bpu);
|
||||
|
||||
log && log(xtag("prod_rr.bpu_array", prod_rr.natural_unit_));
|
||||
log && log(xtag("prod_rr.outer_scale_exact", prod_rr.outer_scale_exact_));
|
||||
log && log(xtag("prod_rr.outer_scale_exact", prod_rr.outer_scale_factor_));
|
||||
log && log(xtag("prod_rr.outer_scale_sq", prod_rr.outer_scale_sq_));
|
||||
|
||||
static_assert(prod_rr.natural_unit_.n_bpu() == 2);
|
||||
|
|
@ -654,7 +654,7 @@ namespace xo {
|
|||
static_assert(prod_rr.natural_unit_[1].native_dim() == dim::time);
|
||||
static_assert(prod_rr.natural_unit_[1].scalefactor() == scalefactor_ratio_type(30*24*3600, 1));
|
||||
static_assert(prod_rr.natural_unit_[1].power() == power_ratio_type(-1, 1));
|
||||
static_assert(prod_rr.outer_scale_exact_ == scalefactor_ratio_type(1, 1));
|
||||
static_assert(prod_rr.outer_scale_factor_ == scalefactor_ratio_type(1, 1));
|
||||
static_assert(prod_rr.outer_scale_sq_ == 12.0);
|
||||
}
|
||||
} /*TEST_CASE(bpu_array_product1)*/
|
||||
|
|
@ -688,7 +688,7 @@ namespace xo {
|
|||
constexpr auto prod_rr = su_bpu_product(v, bpu);
|
||||
|
||||
log && log(xtag("prod_rr.bpu_array", prod_rr.natural_unit_));
|
||||
log && log(xtag("prod_rr.outer_scale_exact", prod_rr.outer_scale_exact_));
|
||||
log && log(xtag("prod_rr.outer_scale_exact", prod_rr.outer_scale_factor_));
|
||||
log && log(xtag("prod_rr.outer_scale_sq", prod_rr.outer_scale_sq_));
|
||||
|
||||
static_assert(prod_rr.natural_unit_.n_bpu() == 2);
|
||||
|
|
@ -698,7 +698,7 @@ namespace xo {
|
|||
static_assert(prod_rr.natural_unit_[1].native_dim() == dim::mass);
|
||||
static_assert(prod_rr.natural_unit_[1].scalefactor() == scalefactor_ratio_type(1, 1000));
|
||||
static_assert(prod_rr.natural_unit_[1].power() == power_ratio_type(-1, 1));
|
||||
static_assert(prod_rr.outer_scale_exact_ == scalefactor_ratio_type(1, 1));
|
||||
static_assert(prod_rr.outer_scale_factor_ == scalefactor_ratio_type(1, 1));
|
||||
static_assert(prod_rr.outer_scale_sq_ == 1.0);
|
||||
}
|
||||
} /*TEST_CASE(bpu_array_product2)*/
|
||||
|
|
@ -732,7 +732,7 @@ namespace xo {
|
|||
constexpr auto prod_rr = su_product<int64_t, __int128_t>(v, w);
|
||||
|
||||
log && log(xtag("prod_rr.bpu_array", prod_rr.natural_unit_));
|
||||
log && log(xtag("prod_rr.outer_scale_exact", prod_rr.outer_scale_exact_));
|
||||
log && log(xtag("prod_rr.outer_scale_exact", prod_rr.outer_scale_factor_));
|
||||
log && log(xtag("prod_rr.outer_scale_sq", prod_rr.outer_scale_sq_));
|
||||
|
||||
static_assert(prod_rr.natural_unit_.n_bpu() == 3);
|
||||
|
|
@ -745,7 +745,7 @@ namespace xo {
|
|||
static_assert(prod_rr.natural_unit_[2].native_dim() == dim::time);
|
||||
static_assert(prod_rr.natural_unit_[2].scalefactor() == scalefactor_ratio_type(30*24*3600, 1));
|
||||
static_assert(prod_rr.natural_unit_[2].power() == power_ratio_type(-1, 2));
|
||||
static_assert(prod_rr.outer_scale_exact_ == scalefactor_ratio_type(1, 1));
|
||||
static_assert(prod_rr.outer_scale_factor_ == scalefactor_ratio_type(1, 1));
|
||||
static_assert(prod_rr.outer_scale_sq_ == 1.0);
|
||||
}
|
||||
} /*TEST_CASE(bpu_array_product3)*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue