1 parent
9ca65240c8
commit
9a49df7222
88 files changed
+149
-148
No files matched your search
@@ -11,7 +11,7 @@ Interface
|
||||
The difference is that it uses ``double`` as a default representation and has
|
||||
a few additional member types and functions::
|
||||
|
||||
template<Dimension D, UnitOf<D> U, Scalar Rep = double>
|
||||
template<Dimension D, UnitOf<D> U, ScalableNumber Rep = double>
|
||||
class quantity {
|
||||
public:
|
||||
using dimension = D;
|
||||
@@ -24,23 +24,23 @@ a few additional member types and functions::
|
||||
|
||||
template<typename D1, typename U1, typename Rep1, typename D2, typename U2, typename Rep2>
|
||||
requires detail::basic_arithmetic<Rep1, Rep2> && equivalent_dim<D1, dim_invert<D2>>
|
||||
[[nodiscard]] constexpr Scalar auto operator*(const quantity<D1, U1, Rep1>& lhs,
|
||||
const quantity<D2, U2, Rep2>& rhs);
|
||||
[[nodiscard]] constexpr ScalableNumber auto operator*(const quantity<D1, U1, Rep1>& lhs,
|
||||
const quantity<D2, U2, Rep2>& rhs);
|
||||
|
||||
template<typename D1, typename U1, typename Rep1, typename D2, typename U2, typename Rep2>
|
||||
requires detail::basic_arithmetic<Rep1, Rep2> && (!equivalent_dim<D1, dim_invert<D2>>)
|
||||
[[nodiscard]] constexpr Quantity auto operator*(const quantity<D1, U1, Rep1>& lhs,
|
||||
const quantity<D2, U2, Rep2>& rhs);
|
||||
|
||||
template<Scalar Value, typename D, typename U, typename Rep>
|
||||
template<ScalableNumber Value, typename D, typename U, typename Rep>
|
||||
requires std::magma<std::ranges::divided_by, Value, Rep>
|
||||
[[nodiscard]] constexpr Quantity auto operator/(const Value& v,
|
||||
const quantity<D, U, Rep>& q);
|
||||
|
||||
template<typename D1, typename U1, typename Rep1, typename D2, typename U2, typename Rep2>
|
||||
requires detail::basic_arithmetic<Rep1, Rep2> && equivalent_dim<D1, D2>
|
||||
[[nodiscard]] constexpr Scalar auto operator/(const quantity<D1, U1, Rep1>& lhs,
|
||||
const quantity<D2, U2, Rep2>& rhs);
|
||||
[[nodiscard]] constexpr ScalableNumber auto operator/(const quantity<D1, U1, Rep1>& lhs,
|
||||
const quantity<D2, U2, Rep2>& rhs);
|
||||
|
||||
template<typename D1, typename U1, typename Rep1, typename D2, typename U2, typename Rep2>
|
||||
requires detail::basic_arithmetic<Rep1, Rep2> && (!equivalent_dim<D1, D2>)
|
||||
|
||||
@@ -18,7 +18,7 @@ For example the speed of light constant in :term:`SI` is defined as::
|
||||
|
||||
namespace si::si2019 {
|
||||
|
||||
template<Scalar Rep = double>
|
||||
template<ScalableNumber Rep = double>
|
||||
inline constexpr auto speed_of_light = speed<metre_per_second, Rep>(299792458);
|
||||
|
||||
}
|
||||
@@ -27,7 +27,7 @@ The same constant defined for natural units may be provided as::
|
||||
|
||||
namespace natural {
|
||||
|
||||
template<Scalar Rep = double>
|
||||
template<ScalableNumber Rep = double>
|
||||
inline constexpr auto speed_of_light = speed<unitless, Rep>(1);
|
||||
|
||||
}
|
||||
@@ -23,7 +23,7 @@ each other and the result will always be a quantity of the same dimension:
|
||||
Length auto res2 = dist1 - dist2;
|
||||
|
||||
Additionally, we can always multiply or divide a quantity by a
|
||||
:term:`scalar` and in such a case the quantity's dimension will also
|
||||
:term:`scalable number` and in such a case the quantity's dimension will also
|
||||
not change:
|
||||
|
||||
.. code-block::
|
||||
@@ -35,7 +35,7 @@ not change:
|
||||
Length auto res3 = res2 / 2; // 6 m
|
||||
|
||||
However, if we try to multiply or divide quantities of the same or
|
||||
different dimensions, or we will divide a scalar by a quantity, we most
|
||||
different dimensions, or we will divide a scalable number by a quantity, we most
|
||||
probably will always end up in a quantity of a yet another dimension:
|
||||
|
||||
.. code-block::
|
||||
@@ -50,7 +50,7 @@ probably will always end up in a quantity of a yet another dimension:
|
||||
|
||||
However, please note that there is an exception from the above rule.
|
||||
In case we divide the same dimensions, or multiply by the inverted
|
||||
dimension, than we will end up with just a scalar type:
|
||||
dimension, than we will end up with just a scalable number type:
|
||||
|
||||
.. code-block::
|
||||
:emphasize-lines: 4-5
|
||||
@@ -58,8 +58,8 @@ dimension, than we will end up with just a scalar type:
|
||||
Time auto dur1 = 10q_s;
|
||||
Time auto dur2 = 2q_s;
|
||||
Frequency auto fr1 = 5q_Hz;
|
||||
Scalar auto v1 = dur1 / dur2; // 5
|
||||
Scalar auto v2 = dur1 * fr1; // 50
|
||||
ScalableNumber auto v1 = dur1 / dur2; // 5
|
||||
ScalableNumber auto v2 = dur1 * fr1; // 50
|
||||
|
||||
Quantity points have a more restricted set of operations.
|
||||
Quantity points can't be added together,
|
||||
|
||||
@@ -11,7 +11,7 @@ with a specific representation and is represented in the library with a
|
||||
Quantity Construction
|
||||
---------------------
|
||||
|
||||
To create the quantity object from a :term:`scalar` we just have to pass
|
||||
To create the quantity object from a :term:`scalable number` we just have to pass
|
||||
the value to the `quantity` class template explicit constructor::
|
||||
|
||||
quantity<si::dim_length, si::kilometre, double> d(123);
|
||||
@@ -33,7 +33,7 @@ type to ``double`` by default::
|
||||
|
||||
namespace si {
|
||||
|
||||
template<Unit U, Scalar Rep = double>
|
||||
template<Unit U, ScalableNumber Rep = double>
|
||||
using length = quantity<dim_length, U, Rep>;
|
||||
|
||||
}
|
||||
@@ -73,7 +73,8 @@ be used::
|
||||
|
||||
All instances of `quantity` class always match the `Quantity` concept.
|
||||
All other regular types that are not quantities are called
|
||||
:term:`scalars <scalar>` by the library and match the `Scalar` concept.
|
||||
:term:`scalable numbers <scalable number>` by the library and match the
|
||||
`ScalableNumber` concept.
|
||||
|
||||
However, the above is not the most important usage of those concepts. Let's
|
||||
assume that the user wants to implement an ``avg_speed`` function that will
|
||||
@@ -183,7 +184,7 @@ are provided::
|
||||
template<typename T>
|
||||
concept Dimensionless = QuantityOf<T, dim_one>;
|
||||
|
||||
template<Unit U, Scalar Rep = double>
|
||||
template<Unit U, ScalableNumber Rep = double>
|
||||
using dimensionless = quantity<dim_one, U, Rep>;
|
||||
|
||||
There are two special units provided for usage with such a quantity:
|
||||
|
||||
+1
-1
@@ -198,7 +198,7 @@ Other definitions
|
||||
- The order and types of dimensions used in the recipe determine how an unnamed
|
||||
dimension's unit symbol is being printed in the text output
|
||||
|
||||
scalar
|
||||
scalable number
|
||||
- Not a `quantity`
|
||||
- Can be passed as a representation type to the :class:`units::quantity` type or be used as a factor
|
||||
while multiplying or dividing a `quantity`.
|
||||
|
||||
@@ -9,11 +9,11 @@ its own custom logic for it (i.e. use a complex number or a measurement class th
|
||||
not only a value but also a measurement error).
|
||||
|
||||
|
||||
A `Scalar` concept
|
||||
------------------
|
||||
A `ScalableNumber` concept
|
||||
--------------------------
|
||||
|
||||
To support a minimum set of `quantity` operations all custom representation types have to
|
||||
satisfy at least the `Scalar` concept. Which means that they:
|
||||
satisfy at least the `ScalableNumber` concept. Which means that they:
|
||||
|
||||
- cannot be quantities by themselves,
|
||||
- cannot be wrappers over the `quantity` type (i.e. ``std::optional<si::length<si::metre>>``),
|
||||
@@ -101,8 +101,8 @@ The only difference here is that in this case we have to explicitly cast the `qu
|
||||
Additional Requirements
|
||||
-----------------------
|
||||
|
||||
As noted in the previous chapter, the `Scalar` concept guarantees us the possibility to
|
||||
construct quantities, convert between the units of the same dimension, and compare them
|
||||
As noted in the previous chapter, the `ScalableNumber` concept guarantees us the possibility
|
||||
to construct quantities, convert between the units of the same dimension, and compare them
|
||||
for equality. To provide additional `quantity` operations the custom representation type
|
||||
have to satisfy more requirements.
|
||||
|
||||
@@ -200,7 +200,7 @@ The `quantity` class template has a few static member functions: `quantity::zero
|
||||
representation type. The default implementation is provided through the `quantity_values` class
|
||||
template::
|
||||
|
||||
template<Scalar Rep>
|
||||
template<ScalableNumber Rep>
|
||||
struct quantity_values {
|
||||
static constexpr Rep zero() noexcept { return Rep(0); }
|
||||
static constexpr Rep one() noexcept { return Rep(1); }
|
||||
@@ -220,7 +220,7 @@ library's framework treat floating-point representation types differently than t
|
||||
ones. This behavior can also be extended to the custom representation types with
|
||||
`treat_as_floating_point` customization point which default definition is::
|
||||
|
||||
template<Scalar Rep>
|
||||
template<ScalableNumber Rep>
|
||||
inline constexpr bool treat_as_floating_point = std::is_floating_point_v<Rep>;
|
||||
|
||||
If our representation type should have a floating-point semantics or if it is a class
|
||||
|
||||
@@ -121,7 +121,7 @@ coherent unit::
|
||||
struct desk_per_hour : deduced_unit<desk_per_hour, dim_desk_rate, desk, si::hour> {};
|
||||
|
||||
// a quantity of our dimension
|
||||
template<Unit U, Scalar Rep = double>
|
||||
template<Unit U, ScalableNumber Rep = double>
|
||||
using desk_rate = quantity<dim_desk_rate, U, Rep>;
|
||||
|
||||
// a concept matching the above quantity
|
||||
@@ -150,7 +150,7 @@ define a new base dimension, its units, quantity helper, concept, and UDLs::
|
||||
struct person : named_unit<person, "person", no_prefix> {};
|
||||
struct dim_people : base_dimension<"people", person> {};
|
||||
|
||||
template<Unit U, Scalar Rep = double>
|
||||
template<Unit U, ScalableNumber Rep = double>
|
||||
using people = quantity<dim_people, U, Rep>;
|
||||
|
||||
template<typename T>
|
||||
@@ -169,7 +169,7 @@ With the above we can now define a new derived dimension::
|
||||
|
||||
struct person_per_desk : deduced_unit<person_per_desk, dim_occupancy_rate, person, desk> {};
|
||||
|
||||
template<Unit U, Scalar Rep = double>
|
||||
template<Unit U, ScalableNumber Rep = double>
|
||||
using occupancy_rate = quantity<dim_occupancy_rate, U, Rep>;
|
||||
|
||||
template<typename T>
|
||||
|
||||
Reference in new issue
Block a user