forked from mpusz/mp-units
NTTP ratio support added (resolves #49)
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
- `math.h` function signatures refactored to use a `Quantity` concept (thanks [@kwikius](https://github.com/kwikius))
|
||||
- FPS system added (thanks [@mikeford3](https://github.com/mikeford3))
|
||||
- `quantity_point` support added (thanks [@johelegp](https://github.com/johelegp))
|
||||
- `ratio` changed to the NTTP kind
|
||||
|
||||
- **0.5.0 May 17, 2020**
|
||||
- Major refactoring and rewrite of the library
|
||||
|
||||
+35
-32
@@ -186,20 +186,23 @@ Those units are the scaled versions of a time dimension's base unit,
|
||||
namely second. Those can be defined easily in the library using
|
||||
`named_scaled_unit` class template::
|
||||
|
||||
struct minute : named_scaled_unit<minute, "min", no_prefix, ratio<60>, second> {};
|
||||
struct hour : named_scaled_unit<hour, "h", no_prefix, ratio<60>, minute> {};
|
||||
struct day : named_scaled_unit<hour, "d", no_prefix, ratio<24>, hour> {};
|
||||
struct minute : named_scaled_unit<minute, "min", no_prefix, ratio(60), second> {};
|
||||
struct hour : named_scaled_unit<hour, "h", no_prefix, ratio(60), minute> {};
|
||||
struct day : named_scaled_unit<hour, "d", no_prefix, ratio(24), hour> {};
|
||||
|
||||
where `no_prefix` is a special tag type describing that the library should
|
||||
not allow to define a new prefixed unit that would use this unit as a
|
||||
reference ("kilohours" does not have much sense, right?). The `ratio` type
|
||||
used in the definition is really similar to ``std::ratio`` but it takes
|
||||
the third additional argument that defines the exponent of the ratio.
|
||||
an additional ``Exp`` template parameter that defines the exponent of the ratio.
|
||||
Another important difference is the fact that the objects of that class are used
|
||||
as class NTTPs rather then a type template parameter kind.
|
||||
|
||||
Thanks to it we can address nearly infinite scaling factors between units
|
||||
and define units like::
|
||||
|
||||
struct electronvolt : named_scaled_unit<electronvolt, "eV", prefix,
|
||||
ratio<1'602'176'634, 1'000'000'000, -19>, joule> {};
|
||||
ratio(1'602'176'634, 1'000'000'000, -19), joule> {};
|
||||
|
||||
..
|
||||
TODO Submit a bug for above lexing problem
|
||||
@@ -221,26 +224,26 @@ complete list of all the :term:`SI` prefixes supported by the library::
|
||||
|
||||
struct prefix : prefix_family {};
|
||||
|
||||
struct yocto : units::prefix<yocto, prefix, "y", ratio<1, 1, -24>> {};
|
||||
struct zepto : units::prefix<zepto, prefix, "z", ratio<1, 1, -21>> {};
|
||||
struct atto : units::prefix<atto, prefix, "a", ratio<1, 1, -18>> {};
|
||||
struct femto : units::prefix<femto, prefix, "f", ratio<1, 1, -15>> {};
|
||||
struct pico : units::prefix<pico, prefix, "p", ratio<1, 1, -12>> {};
|
||||
struct nano : units::prefix<nano, prefix, "n", ratio<1, 1, -9>> {};
|
||||
struct micro : units::prefix<micro, prefix, "µ", ratio<1, 1, -6>> {};
|
||||
struct milli : units::prefix<milli, prefix, "m", ratio<1, 1, -3>> {};
|
||||
struct centi : units::prefix<centi, prefix, "c", ratio<1, 1, -2>> {};
|
||||
struct deci : units::prefix<deci, prefix, "d", ratio<1, 1, -1>> {};
|
||||
struct deca : units::prefix<deca, prefix, "da", ratio<1, 1, 1>> {};
|
||||
struct hecto : units::prefix<hecto, prefix, "h", ratio<1, 1, 2>> {};
|
||||
struct kilo : units::prefix<kilo, prefix, "k", ratio<1, 1, 3>> {};
|
||||
struct mega : units::prefix<mega, prefix, "M", ratio<1, 1, 6>> {};
|
||||
struct giga : units::prefix<giga, prefix, "G", ratio<1, 1, 9>> {};
|
||||
struct tera : units::prefix<tera, prefix, "T", ratio<1, 1, 12>> {};
|
||||
struct peta : units::prefix<peta, prefix, "P", ratio<1, 1, 15>> {};
|
||||
struct exa : units::prefix<exa, prefix, "E", ratio<1, 1, 18>> {};
|
||||
struct zetta : units::prefix<zetta, prefix, "Z", ratio<1, 1, 21>> {};
|
||||
struct yotta : units::prefix<yotta, prefix, "Y", ratio<1, 1, 24>> {};
|
||||
struct yocto : units::prefix<yocto, prefix, "y", ratio(1, 1, -24)> {};
|
||||
struct zepto : units::prefix<zepto, prefix, "z", ratio(1, 1, -21)> {};
|
||||
struct atto : units::prefix<atto, prefix, "a", ratio(1, 1, -18)> {};
|
||||
struct femto : units::prefix<femto, prefix, "f", ratio(1, 1, -15)> {};
|
||||
struct pico : units::prefix<pico, prefix, "p", ratio(1, 1, -12)> {};
|
||||
struct nano : units::prefix<nano, prefix, "n", ratio(1, 1, -9)> {};
|
||||
struct micro : units::prefix<micro, prefix, "µ", ratio(1, 1, -6)> {};
|
||||
struct milli : units::prefix<milli, prefix, "m", ratio(1, 1, -3)> {};
|
||||
struct centi : units::prefix<centi, prefix, "c", ratio(1, 1, -2)> {};
|
||||
struct deci : units::prefix<deci, prefix, "d", ratio(1, 1, -1)> {};
|
||||
struct deca : units::prefix<deca, prefix, "da", ratio(1, 1, 1)> {};
|
||||
struct hecto : units::prefix<hecto, prefix, "h", ratio(1, 1, 2)> {};
|
||||
struct kilo : units::prefix<kilo, prefix, "k", ratio(1, 1, 3)> {};
|
||||
struct mega : units::prefix<mega, prefix, "M", ratio(1, 1, 6)> {};
|
||||
struct giga : units::prefix<giga, prefix, "G", ratio(1, 1, 9)> {};
|
||||
struct tera : units::prefix<tera, prefix, "T", ratio(1, 1, 12)> {};
|
||||
struct peta : units::prefix<peta, prefix, "P", ratio(1, 1, 15)> {};
|
||||
struct exa : units::prefix<exa, prefix, "E", ratio(1, 1, 18)> {};
|
||||
struct zetta : units::prefix<zetta, prefix, "Z", ratio(1, 1, 21)> {};
|
||||
struct yotta : units::prefix<yotta, prefix, "Y", ratio(1, 1, 24)> {};
|
||||
|
||||
}
|
||||
|
||||
@@ -251,12 +254,12 @@ domain::
|
||||
|
||||
struct prefix : prefix_family {};
|
||||
|
||||
struct kibi : units::prefix<kibi, prefix, "Ki", ratio< 1'024>> {};
|
||||
struct mebi : units::prefix<mebi, prefix, "Mi", ratio< 1'048'576>> {};
|
||||
struct gibi : units::prefix<gibi, prefix, "Gi", ratio< 1'073'741'824>> {};
|
||||
struct tebi : units::prefix<tebi, prefix, "Ti", ratio< 1'099'511'627'776>> {};
|
||||
struct pebi : units::prefix<pebi, prefix, "Pi", ratio< 1'125'899'906'842'624>> {};
|
||||
struct exbi : units::prefix<exbi, prefix, "Ei", ratio<1'152'921'504'606'846'976>> {};
|
||||
struct kibi : units::prefix<kibi, prefix, "Ki", ratio( 1'024)> {};
|
||||
struct mebi : units::prefix<mebi, prefix, "Mi", ratio( 1'048'576)> {};
|
||||
struct gibi : units::prefix<gibi, prefix, "Gi", ratio( 1'073'741'824)> {};
|
||||
struct tebi : units::prefix<tebi, prefix, "Ti", ratio( 1'099'511'627'776)> {};
|
||||
struct pebi : units::prefix<pebi, prefix, "Pi", ratio( 1'125'899'906'842'624)> {};
|
||||
struct exbi : units::prefix<exbi, prefix, "Ei", ratio(1'152'921'504'606'846'976)> {};
|
||||
|
||||
}
|
||||
|
||||
@@ -381,7 +384,7 @@ unknown/undefined unit type like in the below example::
|
||||
Length auto l = 100q_km_per_h * 10q_s;
|
||||
|
||||
The type of ``l`` above will be
|
||||
:expr:`si::length<scaled_unit<ratio<1, 36, 1>, si::metre>, long double>`. This is caused
|
||||
:expr:`si::length<scaled_unit<ratio(1, 36, 1), si::metre>, long double>`. This is caused
|
||||
by the fact that the library does not define a unit of a length quantity that has the
|
||||
ratio ``10/36`` of a `si::metre`. If such a unit was predefined we would see its concrete
|
||||
type here instead.
|
||||
|
||||
@@ -16,14 +16,9 @@ Concepts
|
||||
|
||||
A concept matching a symbol prefix. Satisfied by all instantiations of :class:`prefix`.
|
||||
|
||||
.. concept:: template<typename T> Ratio
|
||||
.. concept:: template<ratio R> UnitRatio
|
||||
|
||||
A concept matching a ratio. Satisfied by all instantiations of :class:`ratio`.
|
||||
|
||||
.. concept:: template<typename R> UnitRatio
|
||||
|
||||
A concept matching unit's ratio. Satisfied by all types that satisfy :expr:`Ratio<R>` and
|
||||
for which :expr:`R::num > 0` and :expr:`R::den > 0`.
|
||||
Satisfied by all ratio values for which :expr:`R.num > 0` and :expr:`R.den > 0`.
|
||||
|
||||
.. concept:: template<typename T> BaseDimension
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ Defining a New Unit
|
||||
My working desk is of ``180 cm x 60 cm`` which gives an area of ``0.3 m²``. I would like to
|
||||
make it a unit of area for my project::
|
||||
|
||||
struct desk : named_scaled_unit<desk, "desk", no_prefix, ratio<3, 10>, si::square_metre> {};
|
||||
struct desk : named_scaled_unit<desk, "desk", no_prefix, ratio(3, 10), si::square_metre> {};
|
||||
|
||||
With the above I can define a quantity with the area of ``2 desks``::
|
||||
|
||||
@@ -59,7 +59,7 @@ Enabling a Unit for Prefixing
|
||||
In case I decide it is reasonable to express my desks with SI prefixes the only thing I have
|
||||
to change in the above code is to replace `no_prefix` with `si_prefix`::
|
||||
|
||||
struct desk : named_scaled_unit<desk, "desk", si::prefix, ratio<3, 10>, si::square_metre> {};
|
||||
struct desk : named_scaled_unit<desk, "desk", si::prefix, ratio(3, 10), si::square_metre> {};
|
||||
|
||||
Now I can define a new unit named ``kilodesk``::
|
||||
|
||||
@@ -72,12 +72,12 @@ prefix family and prefixes are needed::
|
||||
|
||||
struct shipping_prefix : prefix_family {};
|
||||
|
||||
struct package : prefix<package, shipping_prefix, "pkg", ratio<6>> {};
|
||||
struct lorry : prefix<lorry, shipping_prefix, "lorry", ratio<6 * 40>> {};
|
||||
struct package : prefix<package, shipping_prefix, "pkg", ratio(6)> {};
|
||||
struct lorry : prefix<lorry, shipping_prefix, "lorry", ratio(6 * 40)> {};
|
||||
|
||||
Now we can use it for our unit::
|
||||
|
||||
struct desk : named_scaled_unit<desk, "desk", shipping_prefix, ratio<3, 10>, si::square_metre> {};
|
||||
struct desk : named_scaled_unit<desk, "desk", shipping_prefix, ratio(3, 10), si::square_metre> {};
|
||||
struct packagedesk : prefixed_unit<packagedesk, package, desk> {};
|
||||
struct lorrydesk : prefixed_unit<lorrydesk, lorry, desk> {};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user