-
Notifications
You must be signed in to change notification settings - Fork 1
type_template conversion_factor
| Home | Concepts | TypeTemplates | Types | TypeFunctions | InlineConstants |
pqs::conversion_factor<std::ratio<Nm,Dm>,pqs::exponent10<Ne,De> >
#include <pqs/type_templates/conversion_factor.hpp>
An instantiable compile-time numeric constant, which is used as a scaling of the numeric value of a
quantity to the numeric value of the quantity expressed as base_unit_exponents.
The number is represented as a rational number a raised to a rational base10 exponent b.
let k be the conversion factors value, then k = a * 10 b
conversion factors can be easily composed from other conversion factors using runtime (constexpr) math operations on them and their exponents and multipliers.
Maths is exact, but this means that it is possible for the number to overflow. Overflow will cause a compilation failure rather than a runtime failure.
The exponent and multiplier may be any rational number expressible by std::intmax_t
In normal form the multiplier of the conversion factor evaluates to a number n , where n <= 1 and n < 10. The exponent is adjusted accordingly.
value pattern | type | notes |
---|---|---|
mn[x] | std::intmax_t | |
md[x] | std::intmax_t | |
en[x] | std::intmax_t | |
ed[x] | std::intmax_t |
typename pattern | type | notes |
---|---|---|
M[x] | std::ratio<mn[x],md[x]> | multiplier pattern |
E[x] | exponent10<en[x],ed[x]> | exponent pattern |
CF[x] | conversion_factor<M[x],E[x]> > | conversion factor pattern |
typename | type | notes |
---|---|---|
CF | conversion_factor<M, E> | |
CFi | conversion_factor<Mi, Ei> | |
CFo | conversion_factor<Mo, Eo> |
std::ratio_less<Mo,std::ratio<10> > == true std::ratio_greater_equal<Mo,std::ratio<1> > == true |
type_expression | result | notes |
---|---|---|
CF::multiplier | std::ratio< mn , md> | |
CF::exponent | exponent10< en , ed > | |
normalise< CFi > | CFo | Cfo is the normalised version of CFi |
value | type | notes |
---|---|---|
i | integer type | |
f | floating point type | |
cf | conversion_factor | |
cfr | conversion_factor | local result |
r | std::ratio | |
e10 | pqs::exponent10 |
expression | result | requires | notes |
---|---|---|---|
r * cf | cfr | cf multiplied by r , normalised | |
cf * r | cfr | cf multiplied by r , normalised | |
cf / r | cfr | cf divided by r , normalised | |
r / cf | cfr | r divided by cf , normalised | |
r * e10 | cfr | multiplier is r , exponent is e10, normalised | |
e10 * r | cfr | multiplier is r , exponent is e10, normalised | |
r / e10 | cfr | multiplier is r , exponent is -e10, normalised | |
e10 / r | cfr | multiplier is 1/r, exponent is e10 ,normalised | |
cf * e10 | cfr | exponent of cf raised by e10, normalised | |
e10 * cf | cfr | exponent of cf raised by e10, normalised | |
cf / e10 | cfr | exponent of cf lowered by e10, normalised | |
e10 / cf | cfr | cfx --> 1/cf raised by e10, normalised | |
evaluate< CF >() | i | CF can be evaluated to integer precisely |
|
evaluate< CF >() | f | CF cannot be evaluated to integer precisely |