Skip to content

type_template conversion_factor

kwikius edited this page Jul 9, 2020 · 91 revisions

| Home | Concepts | TypeTemplates | Types | TypeFunctions | InlineConstants |

Signature

pqs::conversion_factor<std::ratio<Nm,Dm>,pqs::exponent10<Ne,De> >

Header

#include <pqs/type_templates/conversion_factor.hpp>

Description

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 using constexpr runtime math operations on them and their exponents and multipliers.

Example
   using namespace pqs;

   auto constexpr pi = std::ratio<314159265358979>() ^ exponent10<-14>();
   static_assert(is_conversion_factor<decltype(pi)> );

   constexpr auto v1 = evaluate(pi);             // object argument form

   std::cout << std::setprecision(16) << "pi = " << v1 << '\n';
 
sample output : pi = 3.14159265358979

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

normal form

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.

Notation

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
cf ^ e10 cfr exponent of cf raised by e10, normalised
evaluate< CF >() i CF can be evaluated to integer
precisely
type argument form
evaluate(cf) i CF can be evaluated to integer
precisely
object argument form
evaluate< CF >() f CF cannot be evaluated to integer
precisely
type argument form
evaluate(cf) f CF cannot be evaluated to integer
precisely
object argument form
Clone this wiki locally