refactor: quantity::value() renamed to quantity::numerical_value()

According to https://jcgm.bipm.org/vim/en/1.19.html "quantity value" also contains a unit. According to https://jcgm.bipm.org/vim/en/1.20.html "numerical value" is the correct term for just a number.

Resolves #423
This commit is contained in:
Mateusz Pusz
2023-08-30 11:30:35 +02:00
parent 24803a96cc
commit f1c2c74ab0
19 changed files with 405 additions and 379 deletions
+41 -35
View File
@@ -71,7 +71,7 @@ template<Quantity Q1, Quantity Q2>
requires(typename Q1::rep v1, typename Q2::rep v2) { cross_product(v1, v2); }
[[nodiscard]] QuantityOf<Q1::quantity_spec * Q2::quantity_spec> auto cross_product(const Q1& q1, const Q2& q2)
{
return cross_product(q1.value(), q2.value()) * (Q1::reference * Q2::reference);
return cross_product(q1.numerical_value(), q2.numerical_value()) * (Q1::reference * Q2::reference);
}
} // namespace
@@ -83,21 +83,21 @@ TEST_CASE("vector quantity", "[la]")
SECTION("non-truncating")
{
const auto v = vector<int>{3, 2, 1} * isq::position_vector[km];
CHECK(v.in(m).value() == vector<int>{3000, 2000, 1000});
CHECK(v.in(m).numerical_value() == vector<int>{3000, 2000, 1000});
}
SECTION("truncating")
{
const auto v = vector<int>{1001, 1002, 1003} * isq::position_vector[m];
CHECK(value_cast<km>(v).value() == vector<int>{1, 1, 1});
CHECK(value_cast<km>(v).numerical_value() == vector<int>{1, 1, 1});
}
}
SECTION("to scalar magnitude")
{
const auto v = vector<int>{2, 3, 6} * isq::velocity[km / h];
const auto speed = get_magnitude(v.value()) * isq::speed[v.unit]; // TODO can we do better here?
CHECK(speed.value() == 7);
const auto speed = get_magnitude(v.numerical_value()) * isq::speed[v.unit]; // TODO can we do better here?
CHECK(speed.numerical_value() == 7);
}
SECTION("multiply by scalar value")
@@ -106,14 +106,14 @@ TEST_CASE("vector quantity", "[la]")
SECTION("integral")
{
SECTION("scalar on LHS") { CHECK((2 * v).value() == vector<int>{2, 4, 6}); }
SECTION("scalar on RHS") { CHECK((v * 2).value() == vector<int>{2, 4, 6}); }
SECTION("scalar on LHS") { CHECK((2 * v).numerical_value() == vector<int>{2, 4, 6}); }
SECTION("scalar on RHS") { CHECK((v * 2).numerical_value() == vector<int>{2, 4, 6}); }
}
SECTION("floating-point")
{
SECTION("scalar on LHS") { CHECK((0.5 * v).value() == vector<double>{0.5, 1., 1.5}); }
SECTION("scalar on RHS") { CHECK((v * 0.5).value() == vector<double>{0.5, 1., 1.5}); }
SECTION("scalar on LHS") { CHECK((0.5 * v).numerical_value() == vector<double>{0.5, 1., 1.5}); }
SECTION("scalar on RHS") { CHECK((v * 0.5).numerical_value() == vector<double>{0.5, 1., 1.5}); }
}
}
@@ -121,8 +121,8 @@ TEST_CASE("vector quantity", "[la]")
{
const auto v = vector<int>{2, 4, 6} * isq::position_vector[m];
SECTION("integral") { CHECK((v / 2).value() == vector<int>{1, 2, 3}); }
SECTION("floating-point") { CHECK((v / 0.5).value() == vector<double>{4., 8., 12.}); }
SECTION("integral") { CHECK((v / 2).numerical_value() == vector<int>{1, 2, 3}); }
SECTION("floating-point") { CHECK((v / 0.5).numerical_value() == vector<double>{4., 8., 12.}); }
}
SECTION("add")
@@ -132,12 +132,12 @@ TEST_CASE("vector quantity", "[la]")
SECTION("same unit")
{
const auto u = vector<int>{3, 2, 1} * isq::position_vector[m];
CHECK((v + u).value() == vector<int>{4, 4, 4});
CHECK((v + u).numerical_value() == vector<int>{4, 4, 4});
}
SECTION("different units")
{
const auto u = vector<int>{3, 2, 1} * isq::position_vector[km];
CHECK((v + u).value() == vector<int>{3001, 2002, 1003});
CHECK((v + u).numerical_value() == vector<int>{3001, 2002, 1003});
}
}
@@ -148,12 +148,12 @@ TEST_CASE("vector quantity", "[la]")
SECTION("same unit")
{
const auto u = vector<int>{3, 2, 1} * isq::position_vector[m];
CHECK((v - u).value() == vector<int>{-2, 0, 2});
CHECK((v - u).numerical_value() == vector<int>{-2, 0, 2});
}
SECTION("different units")
{
const auto u = vector<int>{3, 2, 1} * isq::position_vector[km];
CHECK((v - u).value() == vector<int>{-2999, -1998, -997});
CHECK((v - u).numerical_value() == vector<int>{-2999, -1998, -997});
}
}
@@ -167,25 +167,31 @@ TEST_CASE("vector quantity", "[la]")
SECTION("derived_quantity_spec")
{
SECTION("scalar on LHS") { CHECK((mass * v).value() == vector<int>{2, 4, 6}); }
SECTION("scalar on RHS") { CHECK((v * mass).value() == vector<int>{2, 4, 6}); }
SECTION("scalar on LHS") { CHECK((mass * v).numerical_value() == vector<int>{2, 4, 6}); }
SECTION("scalar on RHS") { CHECK((v * mass).numerical_value() == vector<int>{2, 4, 6}); }
}
SECTION("quantity_cast to momentum")
{
SECTION("scalar on LHS") { CHECK(quantity_cast<isq::momentum>(mass * v).value() == vector<int>{2, 4, 6}); }
SECTION("scalar on RHS") { CHECK(quantity_cast<isq::momentum>(v * mass).value() == vector<int>{2, 4, 6}); }
SECTION("scalar on LHS")
{
CHECK(quantity_cast<isq::momentum>(mass * v).numerical_value() == vector<int>{2, 4, 6});
}
SECTION("scalar on RHS")
{
CHECK(quantity_cast<isq::momentum>(v * mass).numerical_value() == vector<int>{2, 4, 6});
}
}
SECTION("quantity of momentum")
{
SECTION("scalar on LHS")
{
const quantity<isq::momentum[N * s], vector<int>> momentum = mass * v;
CHECK(momentum.value() == vector<int>{2, 4, 6});
CHECK(momentum.numerical_value() == vector<int>{2, 4, 6});
}
SECTION("scalar on RHS")
{
const quantity<isq::momentum[N * s], vector<int>> momentum = v * mass;
CHECK(momentum.value() == vector<int>{2, 4, 6});
CHECK(momentum.numerical_value() == vector<int>{2, 4, 6});
}
}
}
@@ -196,18 +202,18 @@ TEST_CASE("vector quantity", "[la]")
SECTION("derived_quantity_spec")
{
SECTION("scalar on LHS") { CHECK((mass * v).value() == vector<double>{0.5, 1., 1.5}); }
SECTION("scalar on RHS") { CHECK((v * mass).value() == vector<double>{0.5, 1., 1.5}); }
SECTION("scalar on LHS") { CHECK((mass * v).numerical_value() == vector<double>{0.5, 1., 1.5}); }
SECTION("scalar on RHS") { CHECK((v * mass).numerical_value() == vector<double>{0.5, 1., 1.5}); }
}
SECTION("quantity_cast to momentum")
{
SECTION("scalar on LHS")
{
CHECK(quantity_cast<isq::momentum>(mass * v).value() == vector<double>{0.5, 1., 1.5});
CHECK(quantity_cast<isq::momentum>(mass * v).numerical_value() == vector<double>{0.5, 1., 1.5});
}
SECTION("scalar on RHS")
{
CHECK(quantity_cast<isq::momentum>(v * mass).value() == vector<double>{0.5, 1., 1.5});
CHECK(quantity_cast<isq::momentum>(v * mass).numerical_value() == vector<double>{0.5, 1., 1.5});
}
}
SECTION("quantity of momentum")
@@ -215,12 +221,12 @@ TEST_CASE("vector quantity", "[la]")
SECTION("scalar on LHS")
{
const quantity<isq::momentum[N * s], vector<double>> momentum = mass * v;
CHECK(momentum.value() == vector<double>{0.5, 1., 1.5});
CHECK(momentum.numerical_value() == vector<double>{0.5, 1., 1.5});
}
SECTION("scalar on RHS")
{
const quantity<isq::momentum[N * s], vector<double>> momentum = v * mass;
CHECK(momentum.value() == vector<double>{0.5, 1., 1.5});
CHECK(momentum.numerical_value() == vector<double>{0.5, 1., 1.5});
}
}
}
@@ -234,15 +240,15 @@ TEST_CASE("vector quantity", "[la]")
{
const auto dur = 2 * isq::duration[h];
SECTION("derived_quantity_spec") { CHECK((pos / dur).value() == vector<int>{15, 10, 5}); }
SECTION("derived_quantity_spec") { CHECK((pos / dur).numerical_value() == vector<int>{15, 10, 5}); }
SECTION("quantity_cast to velocity")
{
CHECK(quantity_cast<isq::velocity>(pos / dur).value() == vector<int>{15, 10, 5});
CHECK(quantity_cast<isq::velocity>(pos / dur).numerical_value() == vector<int>{15, 10, 5});
}
SECTION("quantity of velocity")
{
const quantity<isq::velocity[km / h], vector<int>> v = pos / dur;
CHECK(v.value() == vector<int>{15, 10, 5});
CHECK(v.numerical_value() == vector<int>{15, 10, 5});
}
}
@@ -250,15 +256,15 @@ TEST_CASE("vector quantity", "[la]")
{
const auto dur = 0.5 * isq::duration[h];
SECTION("derived_quantity_spec") { CHECK((pos / dur).value() == vector<double>{60, 40, 20}); }
SECTION("derived_quantity_spec") { CHECK((pos / dur).numerical_value() == vector<double>{60, 40, 20}); }
SECTION("quantity_cast to velocity")
{
CHECK(quantity_cast<isq::velocity>(pos / dur).value() == vector<double>{60, 40, 20});
CHECK(quantity_cast<isq::velocity>(pos / dur).numerical_value() == vector<double>{60, 40, 20});
}
SECTION("quantity of velocity")
{
const quantity<isq::velocity[km / h], vector<double>> v = pos / dur;
CHECK(v.value() == vector<double>{60, 40, 20});
CHECK(v.numerical_value() == vector<double>{60, 40, 20});
}
}
}
@@ -294,8 +300,8 @@ TEST_CASE("vector of quantities", "[la]")
SECTION("to scalar magnitude")
{
const vector<quantity<isq::velocity[km / h], int>> v = {2 * (km / h), 3 * (km / h), 6 * (km / h)};
const auto speed = get_magnitude(v).value() * isq::speed[v(0).unit]; // TODO can we do better here?
CHECK(speed.value() == 7);
const auto speed = get_magnitude(v).numerical_value() * isq::speed[v(0).unit]; // TODO can we do better here?
CHECK(speed.numerical_value() == 7);
}
SECTION("multiply by scalar value")