2020-09-08 18:40:46 +02:00
|
|
|
|
.. namespace:: units
|
|
|
|
|
|
2020-03-09 18:55:41 +01:00
|
|
|
|
FAQ
|
|
|
|
|
===
|
|
|
|
|
|
2020-03-19 10:49:09 +01:00
|
|
|
|
.. contents:: Questions:
|
|
|
|
|
:local:
|
|
|
|
|
|
|
|
|
|
|
2020-03-09 18:55:41 +01:00
|
|
|
|
General
|
|
|
|
|
-------
|
|
|
|
|
|
|
|
|
|
Why dimensions depend on units and not vice versa?
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
Most of the libraries define units in terms of dimensions and this was also an
|
2020-03-19 10:49:09 +01:00
|
|
|
|
initial approach for this library. However, it turns out that for such a design
|
2020-03-09 18:55:41 +01:00
|
|
|
|
it is hard to provide support for all the required scenarios.
|
|
|
|
|
|
|
|
|
|
The first of them is to support multiple unit systems (like SI, CGS, ...) where
|
|
|
|
|
each of can have a different base unit for the same dimension. Base quantity of
|
2020-03-19 10:49:09 +01:00
|
|
|
|
dimension length in SI should use ``m`` to print the unit symbol to the text
|
|
|
|
|
output, while the same dimension for CGS should use ``cm``. Also, it helps in
|
|
|
|
|
conversions among those systems.
|
2020-03-09 18:55:41 +01:00
|
|
|
|
|
|
|
|
|
The second one is to support natural units where more than one dimension can be
|
|
|
|
|
measured with the same unit (i.e. ``GeV``). Also if someone will decide to
|
|
|
|
|
implement a systems where SI quantities of the same kind are expressed as
|
|
|
|
|
different dimensions (i.e. height, width, and depth) all of them will just be
|
|
|
|
|
measured in meters.
|
|
|
|
|
|
|
|
|
|
|
2021-03-16 12:03:25 +01:00
|
|
|
|
Why other systems are defined in the `isq::si` namespace?
|
2020-09-14 08:45:36 +02:00
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
2020-09-10 21:16:38 +02:00
|
|
|
|
|
2021-03-16 12:03:25 +01:00
|
|
|
|
All systems defined in the `isq::si` namespace are defined in terms of
|
2020-09-14 08:45:36 +02:00
|
|
|
|
base units that are convertible to the :term:`SI` units. This enables conversions
|
|
|
|
|
of units of the same physical dimension between different systems.
|
2020-09-10 21:16:38 +02:00
|
|
|
|
|
|
|
|
|
.. seealso::
|
|
|
|
|
|
2021-02-16 16:19:57 +01:00
|
|
|
|
More details on this subject can be found in the
|
|
|
|
|
:ref:`use_cases/extensions:Custom Systems` chapter.
|
2020-09-10 21:16:38 +02:00
|
|
|
|
|
|
|
|
|
|
2020-09-08 17:13:38 +02:00
|
|
|
|
Why a dimensionless quantity is not just an fundamental arithmetic type?
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
In the initial design of this library the resulting type of the division of
|
|
|
|
|
two quantities was their common representation type::
|
|
|
|
|
|
2020-09-09 19:20:35 +02:00
|
|
|
|
static_assert(std::is_same_v<decltype(10_q_km / 5_q_km), std::int64_t>);
|
2020-09-08 17:13:38 +02:00
|
|
|
|
|
|
|
|
|
The reasoning behind it was to not provide a false impression of a strong `quantity` type
|
|
|
|
|
for something that looks and feels like a regular number. Also all of the mathematic
|
|
|
|
|
and trigonometric functions were working fine out of the box with such representation
|
|
|
|
|
types, so we did not have to rewrite ``sin()``, ``cos()``, ``exp()``, and others.
|
|
|
|
|
|
|
|
|
|
However, the feedback we got from the production usage was that such an approach
|
|
|
|
|
is really bad for generic programming. It is really hard to handle the result of
|
|
|
|
|
division (or multiplication) of two quantities as it might be either a `quantity`
|
|
|
|
|
or a fundamental type. If we want to raise such a result to some power we have to
|
|
|
|
|
either use ``units::pow`` or ``std::pow`` depending on the resulting type. Those
|
|
|
|
|
are only a few from many similar issues related to such an approach.
|
|
|
|
|
|
|
|
|
|
This is why it was decided to go with the current approach.
|
|
|
|
|
|
|
|
|
|
.. seealso::
|
|
|
|
|
|
2021-02-16 16:19:57 +01:00
|
|
|
|
More information on the current design can be found in
|
|
|
|
|
the :ref:`framework/quantities:Dimensionless Quantities` chapter.
|
2020-09-08 17:13:38 +02:00
|
|
|
|
|
|
|
|
|
|
2020-03-09 18:55:41 +01:00
|
|
|
|
Why do we spell ``metre`` instead of ``meter``?
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
2020-09-11 23:32:41 +02:00
|
|
|
|
Well, this is how [ISO80000]_ defines it (British English spelling by default).
|
2020-03-19 10:49:09 +01:00
|
|
|
|
|
|
|
|
|
|
2020-09-07 12:46:29 +02:00
|
|
|
|
User Defined Literals (UDLs)
|
|
|
|
|
----------------------------
|
|
|
|
|
|
2020-09-09 19:20:35 +02:00
|
|
|
|
Why all UDLs are prefixed with ``_q_`` instead of just using unit symbol?
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
2020-09-11 23:32:41 +02:00
|
|
|
|
.. note::
|
2020-09-09 19:20:35 +02:00
|
|
|
|
|
|
|
|
|
Every ``_q_*`` UDL will be replaced by the ``q_*`` literal when/if **mp-units**
|
|
|
|
|
will become a part of the C++ Standard Library.
|
2020-09-07 12:46:29 +02:00
|
|
|
|
|
|
|
|
|
Usage of only unit symbols in UDLs would be a preferred approach (less to type,
|
|
|
|
|
easier to understand and maintain). However, while increasing the coverage for
|
|
|
|
|
the library we learned that there are a lot unit symbols that conflict with
|
|
|
|
|
built-in types or numeric extensions. A few of those are: ``F`` (farad),
|
|
|
|
|
``J`` (joule), ``W`` (watt), ``K`` (kelvin), ``d`` (day),
|
|
|
|
|
``l`` or ``L`` (litre), ``erg``, ``ergps``. For a while for those we used ``_``
|
|
|
|
|
prefix to make the library work at all, but at some point we had to unify the
|
2020-09-09 19:20:35 +02:00
|
|
|
|
naming and we came up with ``_q_`` prefix which results in a creation of
|
2020-09-07 12:46:29 +02:00
|
|
|
|
quantity of a provided unit.
|
|
|
|
|
|
|
|
|
|
|
2020-03-19 10:49:09 +01:00
|
|
|
|
Text formatting
|
|
|
|
|
---------------
|
|
|
|
|
|
|
|
|
|
Why Unicode quantity symbols are used by default instead of ASCII-only characters?
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
2020-09-11 23:32:41 +02:00
|
|
|
|
Both C++ and :term:`SI` ([ISO80000]_) are standardized by the
|
2020-03-19 10:49:09 +01:00
|
|
|
|
:abbr:`ISO (International Organization for Standardization)`. :term:`SI` standard
|
|
|
|
|
specifies Unicode symbols as the official unit names for some quantities (i.e. ``Ω``
|
|
|
|
|
symbol for the resistance quantity). As **mp-units** library
|
|
|
|
|
is being proposed for standardization as a part of the C++ Standard Library we have
|
|
|
|
|
to obey the rules and be consistent with ISO specifications.
|
|
|
|
|
|
|
|
|
|
.. seealso::
|
|
|
|
|
|
|
|
|
|
We do understand engineering reality and constraints and that is why the library
|
2021-02-16 16:19:57 +01:00
|
|
|
|
has the option of :ref:`framework/text_output:ASCII-only quantity symbols`.
|
2020-03-19 10:49:09 +01:00
|
|
|
|
|
|
|
|
|
|
2020-05-09 13:12:35 +02:00
|
|
|
|
Compilation Errors
|
|
|
|
|
------------------
|
|
|
|
|
|
|
|
|
|
error: reference to ‘time’ is ambiguous
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
Unfortunately, if `using-directives <https://en.cppreference.com/w/cpp/language/namespace#Using-directives>`_
|
2021-03-16 12:03:25 +01:00
|
|
|
|
(i.e. ``using namespace units::isq::si``) are being used, `units::isq::si::time`
|
2021-02-16 16:19:57 +01:00
|
|
|
|
will collide with C `time <https://en.cppreference.com/w/c/chrono/time>`_ function. In
|
|
|
|
|
such a case the library's ``time`` function needs to be prefixed with at least one (or all)
|
|
|
|
|
namespace names.
|