diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index 403cc2af..43df570c 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -7,4 +7,4 @@ xo_docdir_sphinx_config( quantity-reference.rst quantity-class.rst quantity-factoryfunctions.rst quantity-unitvars.rst unit-reference.rst unit-concept.rst unit-quantities.rst ) -xo_utest_coverage_config2() +#xo_utest_coverage_config2() diff --git a/include/xo/unit/quantity2.hpp b/include/xo/unit/quantity2.hpp deleted file mode 100644 index efd2b75f..00000000 --- a/include/xo/unit/quantity2.hpp +++ /dev/null @@ -1,28 +0,0 @@ -/** @file quantity2.hpp - * - * Author: Roland Conybeare - **/ - -#pragma once - -#include "bpu_array.hpp" - -namespace xo { - namespace qty { - /** @class quantity - * @brief represent a scalar quantity with attached units. enforce dimensional consistency. - * - * Constexpr implementation, can compute units at compile time - **/ - template - class quantity2 { - public: - using repr_type = Repr; - - private: - }; - } /*namespace qty*/ -} /*namespace xo*/ - - -/** end quantity2.hpp **/ diff --git a/include/xo/unit/quantity2_old.hpp b/include/xo/unit/quantity2_old.hpp new file mode 100644 index 00000000..8da5a914 --- /dev/null +++ b/include/xo/unit/quantity2_old.hpp @@ -0,0 +1,47 @@ +/** @file quantity.hpp + * + * Author: Roland Conybeare + **/ + +#pragma once + +#include "bpu_array.hpp" + +namespace xo { + namespace qty { + /** @class quantity + * @brief represent a scalar quantity with attached units. enforce dimensional consistency. + * + * Constexpr implementation, can compute units at compile time + **/ + template NaturalUnit> + class quantity { + public: + using repr_type = Repr; + using unit_type = natural_unit; + + public: + constexpr quantity(Repr scale) + : scale_{scale} {} + + constexpr const repr_type & scale() const { return scale_; } + constexpr unit_type unit() const { return NaturalUnit; } + + constexpr bool is_dimensionless() const { return s_unit.is_dimensionless(); } + + constexpr quantity unit_qty() { return quantity(1); } + + private: + /** @brief unit (established at compile time) for this quantity **/ + static NaturalUnit s_unit = NaturalUnit; + + /** @brief quantity represents this multiple of unit amount **/ + Repr scale_ = Repr(); + }; + } /*namespace qty*/ +} /*namespace xo*/ + + +/** end quantity.hpp **/ diff --git a/include/xo/unit/Quantity.hpp b/include/xo/unit/xquantity.hpp similarity index 81% rename from include/xo/unit/Quantity.hpp rename to include/xo/unit/xquantity.hpp index fd91528d..3d2606be 100644 --- a/include/xo/unit/Quantity.hpp +++ b/include/xo/unit/xquantity.hpp @@ -281,6 +281,26 @@ namespace xo { return Quantity::add(x, y); } + /** note: won't have constexpr result until c++26 (when ::sqrt(), ::pow() are constexpr) + **/ + template + requires quantity2_concept + constexpr auto + operator+ (const Quantity & x, double y) + { + return x + Quantity(y, nu::dimensionless); + } + + /** note: won't have constexpr result until c++26 (when ::sqrt(), ::pow() are constexpr) + **/ + template + requires quantity2_concept + constexpr auto + operator+ (double x, const Quantity & y) + { + return Quantity(x, nu::dimensionless) + y; + } + /** note: won't have constexpr result until c++26 (when ::sqrt(), ::pow() are constexpr) **/ template @@ -291,6 +311,56 @@ namespace xo { return Quantity::subtract(x, y); } + /** note: won't have constexpr result until c++26 (when ::sqrt(), ::pow() are constexpr) + **/ + template + requires quantity2_concept + constexpr auto + operator- (const Quantity & x, double y) + { + return x - Quantity(y, nu::dimensionless); + } + + /** note: won't have constexpr result until c++26 (when ::sqrt(), ::pow() are constexpr) + **/ + template + requires quantity2_concept + constexpr auto + operator- (double x, const Quantity & y) + { + return Quantity(x, nu::dimensionless) - y; + } + + /** note: won't have constexpr result until c++26 (when ::sqrt(), ::pow() are constexpr) + **/ + template + requires quantity2_concept && quantity2_concept + constexpr auto + operator== (const Quantity & x, const Quantity2 & y) + { + return (Quantity::compare(x, y) == 0); + } + + /** note: won't have constexpr result until c++26 (when ::sqrt(), ::pow() are constexpr) + **/ + template + requires quantity2_concept + constexpr auto + operator== (const Quantity & x, double y) + { + return (x == Quantity(y, nu::dimensionless)); + } + + /** note: won't have constexpr result until c++26 (when ::sqrt(), ::pow() are constexpr) + **/ + template + requires quantity2_concept + constexpr auto + operator== (double x, const Quantity & y) + { + return (Quantity(x, nu::dimensionless) == y); + } + /** note: won't have constexpr result until c++26 (when ::sqrt(), ::pow() are constexpr) **/ template @@ -301,6 +371,26 @@ namespace xo { return Quantity::compare(x, y); } + /** note: won't have constexpr result until c++26 (when ::sqrt(), ::pow() are constexpr) + **/ + template + requires quantity2_concept + constexpr auto + operator<=> (const Quantity & x, double y) + { + return Quantity::compare(x, Quantity(y, nu::dimensionless)); + } + + /** note: won't have constexpr result until c++26 (when ::sqrt(), ::pow() are constexpr) + **/ + template + requires quantity2_concept + constexpr auto + operator<=> (double x, const Quantity & y) + { + return Quantity::compare(Quantity(x, nu::dimensionless), y); + } + namespace unit { constexpr auto nanogram = natural_unit_qty(nu::nanogram); } diff --git a/include/xo/unit/Quantity_iostream.hpp b/include/xo/unit/xquantity_iostream.hpp similarity index 90% rename from include/xo/unit/Quantity_iostream.hpp rename to include/xo/unit/xquantity_iostream.hpp index 402c77d8..0eb6ce95 100644 --- a/include/xo/unit/Quantity_iostream.hpp +++ b/include/xo/unit/xquantity_iostream.hpp @@ -17,10 +17,14 @@ namespace xo { operator<< (std::ostream & os, const Quantity & x) { + os << x.scale() << x.abbrev(); + +#ifdef NOT_USING os << ""; +#endif return os; } diff --git a/utest/CMakeLists.txt b/utest/CMakeLists.txt index 09cfd8ff..5a063bc0 100644 --- a/utest/CMakeLists.txt +++ b/utest/CMakeLists.txt @@ -3,7 +3,7 @@ set(SELF_EXE utest.unit) set(SELF_SRCS unit_utest_main.cpp #mpl_unit.test.cpp - Quantity.test.cpp + xquantity.test.cpp quantity.test.cpp bpu.test.cpp basis_unit.test.cpp diff --git a/utest/scaled_unit.test.cpp b/utest/scaled_unit.test.cpp index d9b1d3d6..74c29918 100644 --- a/utest/scaled_unit.test.cpp +++ b/utest/scaled_unit.test.cpp @@ -20,14 +20,14 @@ namespace xo { constexpr su64_type su_reciprocal = su.reciprocal(); TEST_CASE("scaled_unit", "[scaled_unit]") { - static_assert(su_reciprocal.natural_unit_ == nu::gram.reciprocal()); - REQUIRE(su_reciprocal.natural_unit_ == nu::gram.reciprocal()); + static_assert(su_reciprocal.natural_unit_ == nu::gram.reciprocal()); + REQUIRE(su_reciprocal.natural_unit_ == nu::gram.reciprocal()); - static_assert(su_reciprocal.outer_scale_factor_ == 1); - REQUIRE(su_reciprocal.outer_scale_factor_ == 1); + static_assert(su_reciprocal.outer_scale_factor_ == 1); + REQUIRE(su_reciprocal.outer_scale_factor_ == 1); - static_assert(su_reciprocal.outer_scale_sq_ == 1.0); - REQUIRE(su_reciprocal.outer_scale_sq_ == 1.0); + static_assert(su_reciprocal.outer_scale_sq_ == 1.0); + REQUIRE(su_reciprocal.outer_scale_sq_ == 1.0); } /*TEST_CASE(scaled_unit)*/ TEST_CASE("su_product", "[scaled_unit]") { diff --git a/utest/Quantity.test.cpp b/utest/xquantity.test.cpp similarity index 99% rename from utest/Quantity.test.cpp rename to utest/xquantity.test.cpp index 62a5b3d1..319edcd6 100644 --- a/utest/Quantity.test.cpp +++ b/utest/xquantity.test.cpp @@ -1,7 +1,7 @@ /* @file Quantity.test.cpp */ -#include "Quantity.hpp" -#include "Quantity_iostream.hpp" +#include "xquantity.hpp" +#include "xquantity_iostream.hpp" #include "xo/randomgen/random_seed.hpp" #include "xo/randomgen/xoshiro256.hpp" #include "xo/indentlog/scope.hpp"