diff --git a/include/xo/unit/bpu2.hpp b/include/xo/unit/bpu.hpp similarity index 88% rename from include/xo/unit/bpu2.hpp rename to include/xo/unit/bpu.hpp index 4ec163a7..494ce473 100644 --- a/include/xo/unit/bpu2.hpp +++ b/include/xo/unit/bpu.hpp @@ -58,26 +58,26 @@ namespace xo { * native_bpu, ratio<-1,2>> represents unit of 1/sqrt(t) **/ template - struct bpu2 : basis_unit { + struct bpu : basis_unit { public: using ratio_int_type = Int; public: - constexpr bpu2() = default; - constexpr bpu2(const basis_unit & bu, - const power_ratio_type & power) + constexpr bpu() = default; + constexpr bpu(const basis_unit & bu, + const power_ratio_type & power) : basis_unit{bu}, power_{power} {} - constexpr bpu2(dim native_dim, + constexpr bpu(dim native_dim, const scalefactor_ratio_type & scalefactor, const power_ratio_type & power) : basis_unit(native_dim, scalefactor), power_{power} {} - static constexpr bpu2 unit_power(const basis_unit & bu) { - return bpu2(bu, power_ratio_type(1,1)); + static constexpr bpu unit_power(const basis_unit & bu) { + return bpu(bu, power_ratio_type(1,1)); } constexpr const power_ratio_type & power() const { return power_; } @@ -98,8 +98,8 @@ namespace xo { } /* for bpu x, x.reciprocal() represents dimension of 1/x */ - constexpr bpu2 reciprocal() const { - return bpu2(native_dim(), scalefactor(), power_.negate()); + constexpr bpu reciprocal() const { + return bpu(native_dim(), scalefactor(), power_.negate()); } /** @brief this unit represents native dimension taken to this power **/ @@ -108,7 +108,7 @@ namespace xo { template constexpr auto make_unit_power(const basis_unit & bu) { - return bpu2::unit_power(bu); + return bpu::unit_power(bu); } #ifdef NOT_USING diff --git a/include/xo/unit/bpu2_iostream.hpp b/include/xo/unit/bpu2_iostream.hpp index 75249b9d..be5d6bd9 100644 --- a/include/xo/unit/bpu2_iostream.hpp +++ b/include/xo/unit/bpu2_iostream.hpp @@ -6,14 +6,14 @@ #pragma once #include "xo/ratio/ratio_iostream.hpp" -#include "bpu2.hpp" +#include "bpu.hpp" #include namespace xo { namespace qty { template inline std::ostream & - operator<<(std::ostream & os, const bpu2 & x) { + operator<<(std::ostream & os, const bpu & x) { os << " #include @@ -30,22 +30,22 @@ namespace xo { constexpr natural_unit() : n_bpu_{0} {} constexpr std::size_t n_bpu() const { return n_bpu_; } - constexpr bpu2 * bpu_v() const { return bpu_v_; } + constexpr bpu * bpu_v() const { return bpu_v_; } - constexpr void push_back(const bpu2 & bpu) { + constexpr void push_back(const bpu & bpu) { if (n_bpu_ < n_dim) bpu_v_[n_bpu_++] = bpu; } - constexpr bpu2 & operator[](std::size_t i) { return bpu_v_[i]; } - constexpr const bpu2 & operator[](std::size_t i) const { return bpu_v_[i]; } + constexpr bpu & operator[](std::size_t i) { return bpu_v_[i]; } + constexpr const bpu & operator[](std::size_t i) const { return bpu_v_[i]; } private: /** @brief the number of occupied slots in @c bpu_v_ **/ std::size_t n_bpu_; /** @brief storage for basis power units **/ - bpu2 bpu_v_[n_dim]; + bpu bpu_v_[n_dim]; }; namespace detail { @@ -116,7 +116,7 @@ namespace xo { template struct bpu2_rescale_result { - constexpr bpu2_rescale_result(const bpu2 & bpu_rescaled, + constexpr bpu2_rescale_result(const bpu & bpu_rescaled, const ratio::ratio & outer_scale_exact, double outer_scale_sq) : bpu_rescaled_{bpu_rescaled}, @@ -125,7 +125,7 @@ namespace xo { {} /* (b'.u)^p */ - bpu2 bpu_rescaled_; + bpu bpu_rescaled_; /* (b/b')^p0 */ ratio::ratio outer_scale_exact_; /* [(b/b')^q]^2 -- until c++26 only allow q=0 or q=1/2 */ @@ -135,7 +135,7 @@ namespace xo { template constexpr bpu2_rescale_result - bpu2_rescale(const bpu2 & orig, + bpu2_rescale(const bpu & orig, const scalefactor_ratio_type & new_scalefactor) { ratio::ratio mult = (orig.scalefactor() / new_scalefactor); @@ -154,7 +154,7 @@ namespace xo { // remaining possibilities not supported until c++26 } - return bpu2_rescale_result(bpu2(orig.native_dim(), + return bpu2_rescale_result(bpu(orig.native_dim(), new_scalefactor, orig.power()), mult.power(orig.power().floor()), @@ -164,15 +164,15 @@ namespace xo { template constexpr outer_scalefactor_result - bpu_product_inplace(bpu2 * p_target_bpu, - const bpu2 & rhs_bpu_orig) + bpu_product_inplace(bpu * p_target_bpu, + const bpu & rhs_bpu_orig) { assert(rhs_bpu_orig.native_dim() == p_target_bpu->native_dim()); bpu2_rescale_result rhs_bpu_rr = bpu2_rescale(rhs_bpu_orig, p_target_bpu->scalefactor()); - *p_target_bpu = bpu2(p_target_bpu->native_dim(), + *p_target_bpu = bpu(p_target_bpu->native_dim(), p_target_bpu->scalefactor(), p_target_bpu->power() + rhs_bpu_orig.power()); @@ -184,7 +184,7 @@ namespace xo { constexpr outer_scalefactor_result bpu_array_product_inplace(natural_unit * p_target, - const bpu2 & bpu) + const bpu & bpu) { std::size_t i = 0; for (; i < p_target->n_bpu(); ++i) { diff --git a/include/xo/unit/scaled_unit2.hpp b/include/xo/unit/scaled_unit2.hpp index d8c11bdd..72b0c2d5 100644 --- a/include/xo/unit/scaled_unit2.hpp +++ b/include/xo/unit/scaled_unit2.hpp @@ -52,12 +52,12 @@ namespace xo { template constexpr detail::bpu2_rescale_result - bpu2_product(const bpu2 & lhs_bpu, - const bpu2 & rhs_bpu) + bpu2_product(const bpu & lhs_bpu, + const bpu & rhs_bpu) { assert(lhs_bpu.native_dim() == rhs_bpu.native_dim()); - bpu2 prod_bpu = lhs_bpu; + bpu prod_bpu = lhs_bpu; auto rr = bpu_product_inplace(&prod_bpu, rhs_bpu); return bpu2_rescale_result(prod_bpu, rr.outer_scale_exact_, rr.outer_scale_sq_); @@ -67,7 +67,7 @@ namespace xo { constexpr scaled_unit2 nu_product(const natural_unit & lhs_bpu_array, - const bpu2 & rhs_bpu) + const bpu & rhs_bpu) { natural_unit prod = lhs_bpu_array; auto rr = bpu_array_product_inplace(&prod, rhs_bpu); diff --git a/utest/unit.test.cpp b/utest/unit.test.cpp index 715e1a8a..fc6e1aae 100644 --- a/utest/unit.test.cpp +++ b/utest/unit.test.cpp @@ -7,7 +7,7 @@ #include "xo/unit/natural_unit.hpp" #include "xo/unit/natural_unit_iostream.hpp" #include "xo/unit/bpu_store.hpp" -#include "xo/unit/bpu2.hpp" +#include "xo/unit/bpu.hpp" #include "xo/unit/bpu2_iostream.hpp" #include "xo/unit/basis_unit.hpp" #include "xo/unit/native_unit.hpp" @@ -40,7 +40,7 @@ namespace xo { using xo::qty::basis_unit2_store; using xo::qty::power_ratio_type; using xo::qty::abbrev::flatstring_from_exponent; - using xo::qty::bpu2; + using xo::qty::bpu; using xo::qty::detail::bpu2_rescale; using xo::qty::detail::bpu2_product; using xo::qty::natural_unit; @@ -311,24 +311,24 @@ namespace xo { log && log(xtag("kg", bpu2_abbrev(dim::mass, scalefactor_ratio_type(1000, 1), power_ratio_type(1, 1)))); log && log(xtag("kg*kg", bpu2_abbrev(dim::mass, scalefactor_ratio_type(1000, 1), power_ratio_type(2, 1)))); - static_assert(bpu2(dim::mass, scalefactor_ratio_type(1, 1), power_ratio_type(1, 1)).abbrev() + static_assert(bpu(dim::mass, scalefactor_ratio_type(1, 1), power_ratio_type(1, 1)).abbrev() == bpu2_abbrev_type::from_chars("g")); - static_assert(bpu2(dim::mass, scalefactor_ratio_type(1000, 1), power_ratio_type(1, 1)).abbrev() + static_assert(bpu(dim::mass, scalefactor_ratio_type(1000, 1), power_ratio_type(1, 1)).abbrev() == bpu2_abbrev_type::from_chars("kg")); - static_assert(bpu2(dim::mass, scalefactor_ratio_type(1000, 1), power_ratio_type(-1, 1)).abbrev() + static_assert(bpu(dim::mass, scalefactor_ratio_type(1000, 1), power_ratio_type(-1, 1)).abbrev() == bpu2_abbrev_type::from_chars("kg^-1")); - static_assert(bpu2(dim::mass, scalefactor_ratio_type(1000, 1), power_ratio_type(-2, 1)).abbrev() + static_assert(bpu(dim::mass, scalefactor_ratio_type(1000, 1), power_ratio_type(-2, 1)).abbrev() == bpu2_abbrev_type::from_chars("kg^-2")); - static_assert(bpu2(dim::time, scalefactor_ratio_type(60, 1), power_ratio_type(-2, 1)).abbrev() + static_assert(bpu(dim::time, scalefactor_ratio_type(60, 1), power_ratio_type(-2, 1)).abbrev() == bpu2_abbrev_type::from_chars("min^-2")); - static_assert(bpu2(dim::time, scalefactor_ratio_type(3600, 1), power_ratio_type(-1, 1)).abbrev() + static_assert(bpu(dim::time, scalefactor_ratio_type(3600, 1), power_ratio_type(-1, 1)).abbrev() == bpu2_abbrev_type::from_chars("hr^-1")); - static_assert(bpu2(dim::time, scalefactor_ratio_type(24*3600, 1), power_ratio_type(-1, 1)).abbrev() + static_assert(bpu(dim::time, scalefactor_ratio_type(24*3600, 1), power_ratio_type(-1, 1)).abbrev() == bpu2_abbrev_type::from_chars("dy^-1")); - static_assert(bpu2(dim::time, scalefactor_ratio_type(360*24*3600, 1), power_ratio_type(-1, 1)).abbrev() + static_assert(bpu(dim::time, scalefactor_ratio_type(360*24*3600, 1), power_ratio_type(-1, 1)).abbrev() == bpu2_abbrev_type::from_chars("yr360^-1")); - static_assert(bpu2(dim::time, scalefactor_ratio_type(360*24*3600, 1), power_ratio_type(-1, 2)).abbrev() + static_assert(bpu(dim::time, scalefactor_ratio_type(360*24*3600, 1), power_ratio_type(-1, 2)).abbrev() == bpu2_abbrev_type::from_chars("yr360^(-1/2)")); } /*TEST_CASE(bpu2_abbrev)*/ @@ -349,7 +349,7 @@ namespace xo { { constexpr auto p = power_ratio_type(1, 1); - constexpr auto orig_bpu = bpu2(dim::mass, + constexpr auto orig_bpu = bpu(dim::mass, scalefactor_ratio_type(1000, 1), power_ratio_type(1, 1)); static_assert(orig_bpu.native_dim() == dim::mass); @@ -384,7 +384,7 @@ namespace xo { { constexpr auto p = power_ratio_type(-1, 2); - constexpr auto orig_bpu = bpu2(dim::time, + constexpr auto orig_bpu = bpu(dim::time, scalefactor_ratio_type(360*24*3600, 1), power_ratio_type(-1, 2)); static_assert(orig_bpu.native_dim() == dim::time); @@ -423,7 +423,7 @@ namespace xo { { constexpr auto p = power_ratio_type(-3, 2); - constexpr auto orig_bpu = bpu2(dim::time, + constexpr auto orig_bpu = bpu(dim::time, scalefactor_ratio_type(360*24*3600, 1), power_ratio_type(-3, 2)); static_assert(orig_bpu.native_dim() == dim::time); @@ -472,12 +472,12 @@ namespace xo { //log && log("(A)", xtag("foo", foo)); { - constexpr auto bpu_x = bpu2(dim::time, + constexpr auto bpu_x = bpu(dim::time, scalefactor_ratio_type(360*24*3600, 1), power_ratio_type(-3,2)); static_assert(bpu_x.native_dim() == dim::time); - constexpr auto bpu_y = bpu2(dim::time, + constexpr auto bpu_y = bpu(dim::time, scalefactor_ratio_type(360*24*3600, 1), power_ratio_type(1,2)); static_assert(bpu_y.native_dim() == dim::time); @@ -509,12 +509,12 @@ namespace xo { //log && log("(A)", xtag("foo", foo)); { - constexpr auto bpu_x = bpu2(dim::time, + constexpr auto bpu_x = bpu(dim::time, scalefactor_ratio_type(360*24*3600, 1), power_ratio_type(-3,2)); static_assert(bpu_x.native_dim() == dim::time); - constexpr auto bpu_y = bpu2(dim::time, + constexpr auto bpu_y = bpu(dim::time, scalefactor_ratio_type(30*24*3600, 1), power_ratio_type(1,2)); static_assert(bpu_y.native_dim() == dim::time); @@ -554,7 +554,7 @@ namespace xo { { constexpr natural_unit v = (bpu_array_maker::make_bpu_array - (bpu2(dim::mass, scalefactor_ratio_type(1000, 1), power_ratio_type(1, 1)))); + (bpu(dim::mass, scalefactor_ratio_type(1000, 1), power_ratio_type(1, 1)))); static_assert(v.n_bpu() == 1); } @@ -562,8 +562,8 @@ namespace xo { { constexpr natural_unit v = (bpu_array_maker::make_bpu_array - (bpu2(dim::distance, scalefactor_ratio_type(1, 1000), power_ratio_type(2, 1)), - bpu2(dim::mass, scalefactor_ratio_type(1, 1000), power_ratio_type(-1, 1)))); + (bpu(dim::distance, scalefactor_ratio_type(1, 1000), power_ratio_type(2, 1)), + bpu(dim::mass, scalefactor_ratio_type(1, 1000), power_ratio_type(-1, 1)))); static_assert(v.n_bpu() == 2); } @@ -584,12 +584,12 @@ namespace xo { { constexpr natural_unit v = (bpu_array_maker::make_bpu_array - (bpu2(dim::distance, scalefactor_ratio_type(1, 1000), power_ratio_type(2, 1)), - bpu2(dim::mass, scalefactor_ratio_type(1, 1000), power_ratio_type(-1, 1)))); + (bpu(dim::distance, scalefactor_ratio_type(1, 1000), power_ratio_type(2, 1)), + bpu(dim::mass, scalefactor_ratio_type(1, 1000), power_ratio_type(-1, 1)))); static_assert(v.n_bpu() == 2); - constexpr bpu2 bpu(dim::time, + constexpr bpu bpu(dim::time, scalefactor_ratio_type(250*24*3600, 1), power_ratio_type(-1, 2)); @@ -631,12 +631,12 @@ namespace xo { { constexpr natural_unit v = (bpu_array_maker::make_bpu_array - (bpu2(dim::distance, scalefactor_ratio_type(1, 1000), power_ratio_type(2, 1)), - bpu2(dim::time, scalefactor_ratio_type(30*24*3600, 1), power_ratio_type(-1, 2)))); + (bpu(dim::distance, scalefactor_ratio_type(1, 1000), power_ratio_type(2, 1)), + bpu(dim::time, scalefactor_ratio_type(30*24*3600, 1), power_ratio_type(-1, 2)))); static_assert(v.n_bpu() == 2); - constexpr bpu2 bpu(dim::time, + constexpr bpu bpu(dim::time, scalefactor_ratio_type(360*24*3600, 1), power_ratio_type(-1, 2)); @@ -675,12 +675,12 @@ namespace xo { { constexpr natural_unit v = (bpu_array_maker::make_bpu_array - (bpu2(dim::distance, scalefactor_ratio_type(1, 1000), power_ratio_type(2, 1)), - bpu2(dim::mass, scalefactor_ratio_type(1, 1000), power_ratio_type(-1, 1)))); + (bpu(dim::distance, scalefactor_ratio_type(1, 1000), power_ratio_type(2, 1)), + bpu(dim::mass, scalefactor_ratio_type(1, 1000), power_ratio_type(-1, 1)))); static_assert(v.n_bpu() == 2); - constexpr bpu2 bpu(dim::distance, + constexpr bpu bpu(dim::distance, scalefactor_ratio_type(1, 1000), power_ratio_type(-1, 1)); @@ -719,14 +719,14 @@ namespace xo { { constexpr natural_unit v = (bpu_array_maker::make_bpu_array - (bpu2(dim::distance, scalefactor_ratio_type(1, 1000), power_ratio_type(2, 1)), - bpu2(dim::mass, scalefactor_ratio_type(1, 1000), power_ratio_type(-1, 1)))); + (bpu(dim::distance, scalefactor_ratio_type(1, 1000), power_ratio_type(2, 1)), + bpu(dim::mass, scalefactor_ratio_type(1, 1000), power_ratio_type(-1, 1)))); static_assert(v.n_bpu() == 2); constexpr natural_unit w = (bpu_array_maker::make_bpu_array - (bpu2(dim::time, scalefactor_ratio_type(30*24*3600, 1), power_ratio_type(-1, 2)))); + (bpu(dim::time, scalefactor_ratio_type(30*24*3600, 1), power_ratio_type(-1, 2)))); static_assert(w.n_bpu() == 1);