From 15aa1fe86799f55773d8101f593e5d5c67103ef5 Mon Sep 17 00:00:00 2001 From: Philip Top Date: Thu, 16 Nov 2023 09:17:38 -0800 Subject: [PATCH] More updates (#322) * Update some docs and add a few more conversions from the standards * move most definitions to brace initialization * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- docs/user-guide/equation_units.rst | 8 +- units/unit_definitions.hpp | 563 ++++++++++++++--------------- 2 files changed, 281 insertions(+), 290 deletions(-) diff --git a/docs/user-guide/equation_units.rst b/docs/user-guide/equation_units.rst index 758f33f2..003b9567 100644 --- a/docs/user-guide/equation_units.rst +++ b/docs/user-guide/equation_units.rst @@ -27,9 +27,9 @@ Current equation definitions - 13: 20*log10(x) - 14: log10(x)/log10(3) - 15: 0.5*ln(x) -- 16: UNDEFINED -- 17: UNDEFINED -- 18: UNDEFINED +- 16: API Gravity +- 17: Degree Baume Light +- 18: Degree Baume Heavy - 19: UNDEFINED - 20: UNDEFINED - 21: UNDEFINED @@ -46,7 +46,7 @@ Current equation definitions The wind scales are not very accurate since they match up a slightly fuzzier notion to actual wind speed. There are general charts and the equations in use utilize a polynomial to approximate them to a continuous scale. So the units when used are generally convertible to a velocity unit such as m/s. There are currently 10 undefined equation units available if needed. - +The density scales (API Gravity, Degree Baume Heavy and Light ) are based on handbook definitions at typical temperature scales. A few more like this might be added in the near future. Equation Value conversions ----------------------------- The actual definitions of the equations are found in the `unit::precise::equation` namespace. Two functions are provided that convert values from equation values to units and vice versa. diff --git a/units/unit_definitions.hpp b/units/unit_definitions.hpp index 70c7abf9..7fe935da 100644 --- a/units/unit_definitions.hpp +++ b/units/unit_definitions.hpp @@ -35,96 +35,97 @@ namespace constants { namespace precise { // base units - constexpr precise_unit - meter(detail::unit_data(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)); + constexpr precise_unit meter{ + detail::unit_data{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; constexpr precise_unit m = meter; - constexpr precise_unit - kilogram(detail::unit_data(0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)); + constexpr precise_unit kilogram{ + detail::unit_data{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; constexpr precise_unit kg = kilogram; - constexpr precise_unit - second(detail::unit_data(0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)); + constexpr precise_unit second{ + detail::unit_data{0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; constexpr precise_unit s = second; - constexpr precise_unit - Ampere(detail::unit_data(0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)); + constexpr precise_unit Ampere{ + detail::unit_data{0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; constexpr precise_unit A = Ampere; - constexpr precise_unit - Kelvin(detail::unit_data(0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0)); + constexpr precise_unit Kelvin{ + detail::unit_data{0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; constexpr precise_unit K = Kelvin; - constexpr precise_unit - mol(detail::unit_data(0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0)); - constexpr precise_unit - candela(detail::unit_data(0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0)); + constexpr precise_unit mol{ + detail::unit_data{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0}}; + constexpr precise_unit candela{ + detail::unit_data{0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0}}; constexpr precise_unit cd = candela; - constexpr precise_unit - currency(detail::unit_data(0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0)); - constexpr precise_unit - count(detail::unit_data(0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0)); - constexpr precise_unit - pu(detail::unit_data(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0)); - constexpr precise_unit - iflag(detail::unit_data(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0)); - constexpr precise_unit - eflag(detail::unit_data(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0)); - constexpr precise_unit - radian(detail::unit_data(0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0)); + constexpr precise_unit currency{ + detail::unit_data{0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0}}; + constexpr precise_unit count{ + detail::unit_data{0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0}}; + constexpr precise_unit pu{ + detail::unit_data{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0}}; + constexpr precise_unit iflag{ + detail::unit_data{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0}}; + constexpr precise_unit eflag{ + detail::unit_data{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}}; + constexpr precise_unit radian{ + detail::unit_data{0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0}}; constexpr precise_unit rad = radian; // define some specialized units - constexpr precise_unit - defunit(detail::unit_data(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0)); - constexpr precise_unit - invalid(constants::invalid_conversion, detail::unit_data(nullptr)); - constexpr precise_unit error(detail::unit_data(nullptr)); + constexpr precise_unit defunit{ + detail::unit_data{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0}}; + constexpr precise_unit invalid{ + constants::invalid_conversion, + detail::unit_data{nullptr}}; + constexpr precise_unit error{detail::unit_data{nullptr}}; /// Define some unitless numbers constexpr precise_unit one; - constexpr precise_unit hundred = precise_unit(100.0, one); - constexpr precise_unit thousand = precise_unit(1000.0, one); - constexpr precise_unit ten = precise_unit(10.0, one); - constexpr precise_unit half = precise_unit(0.5, one); - constexpr precise_unit quarter = precise_unit(0.25, one); - constexpr precise_unit percent(0.01, one); + constexpr precise_unit hundred = precise_unit{100.0, one}; + constexpr precise_unit thousand = precise_unit{1000.0, one}; + constexpr precise_unit ten = precise_unit{10.0, one}; + constexpr precise_unit half = precise_unit{0.5, one}; + constexpr precise_unit quarter = precise_unit{0.25, one}; + constexpr precise_unit percent{0.01, one}; constexpr precise_unit ratio = one; - constexpr precise_unit infinite( + constexpr precise_unit infinite{ constants::infinity, - detail::unit_data(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)); - constexpr precise_unit neginfinite( + detail::unit_data{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; + constexpr precise_unit neginfinite{ -constants::infinity, - detail::unit_data(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)); - constexpr precise_unit - nan(constants::invalid_conversion, - detail::unit_data(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)); + detail::unit_data{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; + constexpr precise_unit nan{ + constants::invalid_conversion, + detail::unit_data{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; // SI prefixes as units - constexpr precise_unit deci(1e-1, one); - constexpr precise_unit centi(1e-2, one); - constexpr precise_unit milli(1e-3, one); - constexpr precise_unit micro(1e-6, one); - constexpr precise_unit nano(1e-9, one); - constexpr precise_unit pico(1e-12, one); - constexpr precise_unit femto(1e-15, one); - constexpr precise_unit atto(1e-18, one); - constexpr precise_unit zepto(1e-21, one); - constexpr precise_unit yocto(1e-24, one); - constexpr precise_unit ronto(1e-27, one); - constexpr precise_unit quecto(1e-30, one); - - constexpr precise_unit deka(10, one); - constexpr precise_unit deca(10, one); - constexpr precise_unit hecto(1e2, one); - constexpr precise_unit kilo(1e3, one); - constexpr precise_unit mega(1e6, one); - constexpr precise_unit giga(1e9, one); - constexpr precise_unit tera(1e12, one); - constexpr precise_unit peta(1e15, one); - constexpr precise_unit exa(1e18, one); - constexpr precise_unit zetta(1e21, one); - constexpr precise_unit yotta(1e24, one); - constexpr precise_unit ronna(1e27, one); - constexpr precise_unit quetta(1e30, one); - - constexpr precise_unit kibi(1024, one); + constexpr precise_unit deci{1e-1, one}; + constexpr precise_unit centi{1e-2, one}; + constexpr precise_unit milli{1e-3, one}; + constexpr precise_unit micro{1e-6, one}; + constexpr precise_unit nano{1e-9, one}; + constexpr precise_unit pico{1e-12, one}; + constexpr precise_unit femto{1e-15, one}; + constexpr precise_unit atto{1e-18, one}; + constexpr precise_unit zepto{1e-21, one}; + constexpr precise_unit yocto{1e-24, one}; + constexpr precise_unit ronto{1e-27, one}; + constexpr precise_unit quecto{1e-30, one}; + + constexpr precise_unit deka{10, one}; + constexpr precise_unit deca{10, one}; + constexpr precise_unit hecto{1e2, one}; + constexpr precise_unit kilo{1e3, one}; + constexpr precise_unit mega{1e6, one}; + constexpr precise_unit giga{1e9, one}; + constexpr precise_unit tera{1e12, one}; + constexpr precise_unit peta{1e15, one}; + constexpr precise_unit exa{1e18, one}; + constexpr precise_unit zetta{1e21, one}; + constexpr precise_unit yotta{1e24, one}; + constexpr precise_unit ronna{1e27, one}; + constexpr precise_unit quetta{1e30, one}; + + constexpr precise_unit kibi{1024, one}; constexpr precise_unit mebi = kibi * kibi; constexpr precise_unit gibi = mebi * kibi; constexpr precise_unit tebi = gibi * kibi; @@ -136,48 +137,48 @@ namespace precise { constexpr precise_unit qubi = robi * kibi; // Derived SI units: - constexpr precise_unit - hertz(detail::unit_data(0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)); - - constexpr precise_unit - volt(detail::unit_data(2, 1, -3, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)); - - constexpr precise_unit - newton(detail::unit_data(1, 1, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)); - constexpr precise_unit - Pa(detail::unit_data(-1, 1, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)); - constexpr precise_unit - joule(detail::unit_data(2, 1, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)); - constexpr precise_unit - watt(detail::unit_data(2, 1, -3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)); - constexpr precise_unit - coulomb(detail::unit_data(0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)); - constexpr precise_unit - farad(detail::unit_data(-2, -1, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)); - constexpr precise_unit - ohm(detail::unit_data(2, 1, -3, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)); - constexpr precise_unit - siemens(detail::unit_data(-2, -1, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)); - constexpr precise_unit - weber(detail::unit_data(2, 1, -2, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)); - constexpr precise_unit - tesla(detail::unit_data(0, 1, -2, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)); - constexpr precise_unit - henry(detail::unit_data(2, 1, -2, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)); - constexpr precise_unit - lumen(detail::unit_data(0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0)); - constexpr precise_unit - lux(detail::unit_data(-2, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0)); - constexpr precise_unit - becquerel(detail::unit_data(0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0)); - constexpr precise_unit - gray(detail::unit_data(2, 0, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)); + constexpr precise_unit hertz{ + detail::unit_data{0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; + + constexpr precise_unit volt{ + detail::unit_data{2, 1, -3, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; + + constexpr precise_unit newton{ + detail::unit_data{1, 1, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; + constexpr precise_unit Pa{ + detail::unit_data{-1, 1, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; + constexpr precise_unit joule{ + detail::unit_data{2, 1, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; + constexpr precise_unit watt{ + detail::unit_data{2, 1, -3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; + constexpr precise_unit coulomb{ + detail::unit_data{0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; + constexpr precise_unit farad{ + detail::unit_data{-2, -1, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; + constexpr precise_unit ohm{ + detail::unit_data{2, 1, -3, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; + constexpr precise_unit siemens{ + detail::unit_data{-2, -1, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; + constexpr precise_unit weber{ + detail::unit_data{2, 1, -2, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; + constexpr precise_unit tesla{ + detail::unit_data{0, 1, -2, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; + constexpr precise_unit henry{ + detail::unit_data{2, 1, -2, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; + constexpr precise_unit lumen{ + detail::unit_data{0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0}}; + constexpr precise_unit lux{ + detail::unit_data{-2, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0}}; + constexpr precise_unit becquerel{ + detail::unit_data{0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0}}; + constexpr precise_unit gray{ + detail::unit_data{2, 0, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; // seivert includes relative biological factor so it marked by the eflag to // discriminate from gray - constexpr precise_unit - sievert(detail::unit_data(2, 0, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0)); - constexpr precise_unit - katal(detail::unit_data(0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0)); + constexpr precise_unit sievert{ + detail::unit_data{2, 0, -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}}; + constexpr precise_unit katal{ + detail::unit_data{0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0}}; constexpr precise_unit Hz = hertz; constexpr precise_unit V = volt; @@ -204,28 +205,28 @@ namespace precise { constexpr precise_unit sr = rad * rad; // Extra SI units - constexpr precise_unit bar(100000.0, Pa); + constexpr precise_unit bar{100000.0, Pa}; // Distance units - constexpr precise_unit cm(0.01, m); - constexpr precise_unit km(1000.0, m); - constexpr precise_unit mm(0.001, m); - constexpr precise_unit nm(1e-9, m); + constexpr precise_unit cm{0.01, m}; + constexpr precise_unit km{1000.0, m}; + constexpr precise_unit mm{0.001, m}; + constexpr precise_unit nm{1e-9, m}; // Volume units constexpr precise_unit L{0.001, m* m* m}; constexpr precise_unit mL{0.001, L}; // mass units - constexpr precise_unit g(0.001, kg); - constexpr precise_unit mg(0.001, g); + constexpr precise_unit g{0.001, kg}; + constexpr precise_unit mg{0.001, g}; /// Units from the cgs system namespace cgs { constexpr double c_const = constants::speed_of_light * 100.0; // speed of light in cm/s - constexpr precise_unit erg(1e-7, J); - constexpr precise_unit dyn(1e-5, N); - constexpr precise_unit barye(0.1, Pa); + constexpr precise_unit erg{1e-7, J}; + constexpr precise_unit dyn{1e-5, N}; + constexpr precise_unit barye{0.1, Pa}; constexpr precise_unit gal = cm / s.pow(2); constexpr precise_unit poise{0.1, Pa* s}; constexpr precise_unit stokes{1e-4, m.pow(2) / s}; @@ -239,7 +240,7 @@ namespace precise { constexpr precise_unit stilb = cd / cm.pow(2); constexpr precise_unit lambert{1.0 / constants::pi, cd / cm.pow(2)}; constexpr precise_unit phot{10000, lx}; - constexpr precise_unit curie(3.7e10, Bq); + constexpr precise_unit curie{3.7e10, Bq}; constexpr precise_unit roentgen{2.58e-4, C / kg}; constexpr precise_unit REM{0.01, precise::Sv}; constexpr precise_unit RAD{100, erg / g}; @@ -296,18 +297,18 @@ namespace precise { /// Units of time namespace time { // Time unit - constexpr precise_unit min(60.0, s); - constexpr precise_unit ms(0.001, s); - constexpr precise_unit ns(1e-9, s); - constexpr precise_unit hr(60.0, min); - constexpr precise_unit h(60.0, min); - constexpr precise_unit day(24.0, hr); - constexpr precise_unit week(7.0, day); - constexpr precise_unit yr(8760.0, hr); // median calendar year; - constexpr precise_unit fortnight(14, day); + constexpr precise_unit min{60.0, s}; + constexpr precise_unit ms{0.001, s}; + constexpr precise_unit ns{1e-9, s}; + constexpr precise_unit hr{60.0, min}; + constexpr precise_unit h{60.0, min}; + constexpr precise_unit day{24.0, hr}; + constexpr precise_unit week{7.0, day}; + constexpr precise_unit yr{8760.0, hr}; // median calendar year; + constexpr precise_unit fortnight{14, day}; constexpr precise_unit sday{365.24 / 366.24, day}; // sidereal day - constexpr precise_unit syr(365.256363004, day); // sidereal year + constexpr precise_unit syr{365.256363004, day}; // sidereal year constexpr precise_unit at{365.24219, day* eflag}; // mean tropical year constexpr precise_unit aj{365.25, day}; // julian year constexpr precise_unit ag{365.2425, day}; // gregorian year @@ -329,15 +330,15 @@ namespace precise { namespace i { constexpr precise_unit grain{64.79891, mg}; - constexpr precise_unit point(127.0 / 360.0, mm); - constexpr precise_unit pica(127.0 / 30.0, mm); - constexpr precise_unit inch(0.0254, m); - constexpr precise_unit foot(0.3048, m); + constexpr precise_unit point{127.0 / 360.0, mm}; + constexpr precise_unit pica{127.0 / 30.0, mm}; + constexpr precise_unit inch{0.0254, m}; + constexpr precise_unit foot{0.3048, m}; - constexpr precise_unit yard(0.9144, m); - constexpr precise_unit mile(1609.344, m); - constexpr precise_unit league(3.0, mile); - constexpr precise_unit hand(4.0, inch); + constexpr precise_unit yard{0.9144, m}; + constexpr precise_unit mile{1609.344, m}; + constexpr precise_unit league{3.0, mile}; + constexpr precise_unit hand{4.0, inch}; constexpr precise_unit cord{128.0, foot.pow(3)}; constexpr precise_unit board_foot{144, inch.pow(3)}; @@ -386,22 +387,22 @@ namespace precise { constexpr precise_unit foot{1200.0 / 3937.0, m}; constexpr precise_unit inch{1.0 / 12.0, foot}; constexpr precise_unit mil{0.001, inch}; - constexpr precise_unit yard(3.0, foot); - constexpr precise_unit rod(16.5, foot); - constexpr precise_unit chain(4.0, rod); - constexpr precise_unit link(0.01, chain); - constexpr precise_unit furlong(10.0, chain); - constexpr precise_unit mile(8.0, furlong); - constexpr precise_unit league(3.0, mile); + constexpr precise_unit yard{3.0, foot}; + constexpr precise_unit rod{16.5, foot}; + constexpr precise_unit chain{4.0, rod}; + constexpr precise_unit link{0.01, chain}; + constexpr precise_unit furlong{10.0, chain}; + constexpr precise_unit mile{8.0, furlong}; + constexpr precise_unit league{3.0, mile}; namespace engineers { - constexpr precise_unit chain(100.0, foot); - constexpr precise_unit link(0.01, chain); + constexpr precise_unit chain{100.0, foot}; + constexpr precise_unit link{0.01, chain}; } // namespace engineers // area - constexpr precise_unit acre(43560.0, foot.pow(2)); - constexpr precise_unit homestead(160.0, acre); - constexpr precise_unit section(640.0, acre); - constexpr precise_unit township(36.0, section); + constexpr precise_unit acre{43560.0, foot.pow(2)}; + constexpr precise_unit homestead{160.0, acre}; + constexpr precise_unit section{640.0, acre}; + constexpr precise_unit township{36.0, section}; // volume constexpr precise_unit minim{61.611519921875, micro* L}; constexpr precise_unit dram{60.0, minim}; @@ -488,8 +489,8 @@ namespace precise { constexpr precise_unit link{0.01, chain}; constexpr precise_unit pace{2.5, foot}; constexpr precise_unit yard{3.0, foot}; - constexpr precise_unit furlong(201.168, m); - constexpr precise_unit league(4828.032, m); + constexpr precise_unit furlong{201.168, m}; + constexpr precise_unit league{4828.032, m}; constexpr precise_unit mile{5280.0, foot}; constexpr precise_unit nautical_mile{6080, foot}; constexpr precise_unit knot = nautical_mile / h; @@ -537,11 +538,11 @@ namespace precise { // Nautical units namespace nautical { - constexpr precise_unit fathom(2.0, i::yard); - constexpr precise_unit cable(120, fathom); - constexpr precise_unit mile(1.852, km); - constexpr precise_unit knot = mile / h; - constexpr precise_unit league(3.0, mile); + constexpr precise_unit fathom{2.0, i::yard}; + constexpr precise_unit cable{120, fathom}; + constexpr precise_unit mile{1.852, km}; + constexpr precise_unit knot{mile / h}; + constexpr precise_unit league{3.0, mile}; } // namespace nautical /// Some historical Japanese units @@ -590,7 +591,7 @@ namespace precise { constexpr precise_unit point{15625.0 / 41559.0, mm}; constexpr precise_unit ligne{6.0, point}; constexpr precise_unit pouce{12.0, ligne}; - constexpr precise_unit didot = point; + constexpr precise_unit didot{point}; constexpr precise_unit cicero{12.0, didot}; constexpr precise_unit pied{12.0, pouce}; constexpr precise_unit toise{6.0, pied}; @@ -632,10 +633,10 @@ namespace precise { /// units related to distance namespace distance { - constexpr precise_unit ly(9.4607304725808e15, m); - constexpr precise_unit au(149597870700.0, m); - constexpr precise_unit au_old(1.495979e11, m); - constexpr precise_unit angstrom(1e-10, m); + constexpr precise_unit ly{9.4607304725808e15, m}; + constexpr precise_unit au{149597870700.0, m}; + constexpr precise_unit au_old{1.495979e11, m}; + constexpr precise_unit angstrom{1e-10, m}; constexpr precise_unit parsec{3.085678e16, m}; constexpr precise_unit smoot{67.0, precise::i::inch}; constexpr precise_unit cubit{18.0, precise::i::inch}; @@ -671,9 +672,9 @@ namespace precise { constexpr precise_unit quintal{100.0, kg}; constexpr precise_unit ton_assay{29.0 + 1. / 6.0, g}; constexpr precise_unit longton_assay{32.0 + 2.0 / 3.0, g}; - constexpr precise_unit Da(1.6605388628e-27, kg); + constexpr precise_unit Da{1.6605388628e-27, kg}; constexpr precise_unit u = Da; - constexpr precise_unit tonne(1000.0, kg); + constexpr precise_unit tonne{1000.0, kg}; } // namespace mass constexpr precise_unit t = mass::tonne; @@ -686,13 +687,13 @@ namespace precise { /// angle measure units namespace angle { - constexpr precise_unit deg(constants::pi / 180.0, rad); + constexpr precise_unit deg{constants::pi / 180.0, rad}; constexpr precise_unit gon{0.9, deg}; - constexpr precise_unit grad(constants::pi / 200.0, rad); - constexpr precise_unit arcmin(1.0 / 60.0, deg); - constexpr precise_unit arcsec(1.0 / 60.0, arcmin); - constexpr precise_unit - brad(constants::tau / 256.0, rad); // binary radian + constexpr precise_unit grad{constants::pi / 200.0, rad}; + constexpr precise_unit arcmin{1.0 / 60.0, deg}; + constexpr precise_unit arcsec{1.0 / 60.0, arcmin}; + constexpr precise_unit brad{constants::tau / 256.0, rad}; // binary + // radian } // namespace angle constexpr precise_unit deg = angle::deg; @@ -715,7 +716,7 @@ namespace precise { /// Units related to pressure namespace pressure { - constexpr precise_unit atm(101325.0, Pa); + constexpr precise_unit atm{101325.0, Pa}; constexpr precise_unit psi{6894.757293168, Pa}; constexpr precise_unit psig = psi * eflag; constexpr precise_unit mmHg{133.322387415, Pa}; // at 0 deg C @@ -751,56 +752,56 @@ namespace precise { // Power system units namespace electrical { - constexpr precise_unit MW(1000000.0, W); + constexpr precise_unit MW{1000000.0, W}; constexpr precise_unit VAR = W * iflag; - constexpr precise_unit MVAR(1000000.0, VAR); - constexpr precise_unit kW(1000.0, W); - constexpr precise_unit kVAR(1000.0, VAR); - constexpr precise_unit mW(0.001, W); + constexpr precise_unit MVAR{1000000.0, VAR}; + constexpr precise_unit kW{1000.0, W}; + constexpr precise_unit kVAR{1000.0, VAR}; + constexpr precise_unit mW{0.001, W}; constexpr precise_unit puMW = MW * pu; constexpr precise_unit puV = pu * V; constexpr precise_unit puHz = pu * Hz; - constexpr precise_unit MJ(1000000.0, J); + constexpr precise_unit MJ{1000000.0, J}; constexpr precise_unit puOhm = ohm * pu; constexpr precise_unit puA = A * pu; - constexpr precise_unit kV(1000.0, V); - constexpr precise_unit mV(0.001, V); - constexpr precise_unit mA(0.001, A); + constexpr precise_unit kV{1000.0, V}; + constexpr precise_unit mV{0.001, V}; + constexpr precise_unit mA{0.001, A}; } // namespace electrical constexpr precise_unit MW = electrical::MW; /// Power units namespace power { - constexpr precise_unit hpE(746.0, W); // electric horsepower - constexpr precise_unit - hpI(745.69987158227022, W); // mechanical horsepower - constexpr precise_unit hpS(9812.5, W); // Boiler(steam) horsepower - constexpr precise_unit hpM(735.49875, W); // metric horsepower + constexpr precise_unit hpE{746.0, W}; // electric horsepower + constexpr precise_unit hpI{745.69987158227022, W}; // mechanical + // horsepower + constexpr precise_unit hpS{9812.5, W}; // Boiler(steam) horsepower + constexpr precise_unit hpM{735.49875, W}; // metric horsepower } // namespace power - constexpr precise_unit hp = power::hpI; + constexpr precise_unit hp{power::hpI}; // Speed units - constexpr precise_unit mph(mile / h); - constexpr precise_unit mps(m / s); + constexpr precise_unit mph{mile / h}; + constexpr precise_unit mps{m / s}; /// Energy units namespace energy { - constexpr precise_unit kWh(3600000.0, J); - constexpr precise_unit MWh(1000.0, kWh); - constexpr precise_unit - eV(1.602176634e-19, J); // updated to 2019 exact definition - - constexpr precise_unit kcal(4184.0, J); - constexpr precise_unit cal_4(4.204, J); - constexpr precise_unit cal_15(4.18580, J); // calorie at 15 degC - constexpr precise_unit cal_20(4.18190, J); // calorie at 20 degC - constexpr precise_unit cal_mean(4.19002, J); // mean calorie - constexpr precise_unit - cal_it(4.1868, J); // international table calorie - constexpr precise_unit cal_th(4.184, J); // thermochemical calorie + constexpr precise_unit kWh{3600000.0, J}; + constexpr precise_unit MWh{1000.0, kWh}; + constexpr precise_unit eV{1.602176634e-19, J}; // updated to 2019 exact + // definition + + constexpr precise_unit kcal{4184.0, J}; + constexpr precise_unit cal_4{4.204, J}; + constexpr precise_unit cal_15{4.18580, J}; // calorie at 15 degC + constexpr precise_unit cal_20{4.18190, J}; // calorie at 20 degC + constexpr precise_unit cal_mean{4.19002, J}; // mean calorie + constexpr precise_unit cal_it{4.1868, J}; // international table + // calorie + constexpr precise_unit cal_th{4.184, J}; // thermochemical calorie constexpr precise_unit btu_th{1054.350, J}; // thermochemical btu constexpr precise_unit btu_39{1059.67, J}; @@ -810,14 +811,14 @@ namespace precise { constexpr precise_unit btu_it{1055.05585262, J}; // international table // btu constexpr precise_unit btu_iso{1055.06, J}; // rounded btu_it - constexpr precise_unit quad(1e15, btu_it); - constexpr precise_unit tonc(12000.0, btu_th / h); + constexpr precise_unit quad{1e15, btu_it}; + constexpr precise_unit tonc{12000.0, btu_th / h}; - constexpr precise_unit therm_us(100000.0, btu_59); - constexpr precise_unit therm_br(105505585.257348, J); - constexpr precise_unit therm_ec(100000, btu_iso); - constexpr precise_unit EER(btu_th / W / h); // Energy efficiency ratio - constexpr precise_unit SG(lb / ft.pow(3) * pu); // Specific gravity + constexpr precise_unit therm_us{100000.0, btu_59}; + constexpr precise_unit therm_br{105505585.257348, J}; + constexpr precise_unit therm_ec{100000, btu_iso}; + constexpr precise_unit EER{btu_th / W / h}; // Energy efficiency ratio + constexpr precise_unit SG{lb / ft.pow(3) * pu}; // Specific gravity constexpr precise_unit ton_tnt{4.184, precise::giga* precise::J}; constexpr precise_unit boe{5.8e6, btu_59}; @@ -1051,42 +1052,37 @@ namespace precise { /// logarithm based equation units namespace log { // nepers - constexpr precise_unit neper = precise_unit(custom::equation_unit(1)); + constexpr precise_unit neper{custom::equation_unit(1)}; // natural logarithm - constexpr precise_unit logE = precise_unit(custom::equation_unit(9)); - constexpr precise_unit neperA = precise_unit(custom::equation_unit(9)); + constexpr precise_unit logE{custom::equation_unit(9)}; + // neper of amplitude unit + constexpr precise_unit neperA{custom::equation_unit(9)}; // neper of power unit - constexpr precise_unit neperP = precise_unit(custom::equation_unit(15)); + constexpr precise_unit neperP{custom::equation_unit(15)}; // base 10 logarithm - constexpr precise_unit logbase10 = - precise_unit(custom::equation_unit(0)); + constexpr precise_unit logbase10{custom::equation_unit(0)}; // base 10 logarithm bel auto detect power - constexpr precise_unit bel = precise_unit(custom::equation_unit(2)); + constexpr precise_unit bel{custom::equation_unit(2)}; // base 10 logarithm of Power levels (assume power always) - constexpr precise_unit belP = precise_unit(custom::equation_unit(10)); + constexpr precise_unit belP{custom::equation_unit(10)}; // base 10 logarithm of Power levels (assume power always) - constexpr precise_unit dBP = precise_unit(custom::equation_unit(11)); + constexpr precise_unit dBP{custom::equation_unit(11)}; // base 10 logarithm of Power levels (assume power always) - constexpr precise_unit belA = precise_unit(custom::equation_unit(12)); + constexpr precise_unit belA{custom::equation_unit(12)}; // base 10 logarithm of Power levels (assume power always) - constexpr precise_unit dBA = precise_unit(custom::equation_unit(13)); + constexpr precise_unit dBA{custom::equation_unit(13)}; // base 2 logarithm - constexpr precise_unit logbase2 = - precise_unit(custom::equation_unit(8)); + constexpr precise_unit logbase2{custom::equation_unit(8)}; // 10*base10 logarithm - constexpr precise_unit dB = precise_unit(custom::equation_unit(3)); + constexpr precise_unit dB{custom::equation_unit(3)}; // -base10 logarithm - constexpr precise_unit neglog10 = - precise_unit(custom::equation_unit(4)); + constexpr precise_unit neglog10{custom::equation_unit(4)}; // -base100 logarithm - constexpr precise_unit neglog100 = - precise_unit(custom::equation_unit(5)); + constexpr precise_unit neglog100{custom::equation_unit(5)}; // -base1000 logarithm - constexpr precise_unit neglog1000 = - precise_unit(custom::equation_unit(6)); + constexpr precise_unit neglog1000{custom::equation_unit(6)}; // -base50000 logarithm - constexpr precise_unit neglog50000 = - precise_unit(custom::equation_unit(7)); + constexpr precise_unit neglog50000{custom::equation_unit(7)}; constexpr precise_unit B_SPL{2 * 1e-5, precise::Pa* bel}; constexpr precise_unit B_V = bel * V; @@ -1297,7 +1293,7 @@ namespace precise { constexpr precise_unit woodu = precise::pressure::mmHg * precise::min / precise::L; //!< wood unit constexpr precise_unit diopter = m.inv(); - constexpr precise_unit prism_diopter(custom::equation_unit(27)); + constexpr precise_unit prism_diopter{custom::equation_unit(27)}; constexpr precise_unit mesh = i::inch.inv(); constexpr precise_unit charriere{1.0 / 3.0, mm}; constexpr precise_unit drop{0.05, mL}; @@ -1310,22 +1306,20 @@ namespace precise { /// Units used in chemical and biological laboratories namespace laboratory { constexpr precise_unit svedberg{1e-13, precise::s}; - constexpr precise_unit HPF = precise_unit(custom::custom_count_unit(5)); + constexpr precise_unit HPF{custom::custom_count_unit(5)}; constexpr precise_unit LPF{100.0, HPF}; constexpr precise_unit enzyme_unit = precise::micro * precise::mol / precise::min; // International Unit - constexpr precise_unit IU = precise_unit(custom::custom_count_unit(2)); + constexpr precise_unit IU{custom::custom_count_unit(2)}; // Arbitrary Unit - constexpr precise_unit arbU = - precise_unit(custom::custom_count_unit(1)); + constexpr precise_unit arbU{custom::custom_count_unit(1)}; // index of reactivity - constexpr precise_unit IR = precise_unit(custom::custom_count_unit(3)); + constexpr precise_unit IR{custom::custom_count_unit(3)}; // limit of flocculation - constexpr precise_unit Lf = precise_unit(custom::custom_count_unit(4)); + constexpr precise_unit Lf{custom::custom_count_unit(4)}; - constexpr precise_unit PFU = - precise_unit(1.0, precise::count, commodities::tissue); + constexpr precise_unit PFU{1.0, precise::count, commodities::tissue}; constexpr precise_unit pH = precise::mol / precise::L * precise::log::neglog10; constexpr precise_unit molarity = precise::mol / precise::L; @@ -1336,17 +1330,17 @@ namespace precise { /// Units related to quantities of data namespace data { constexpr precise_unit bit = count; - constexpr precise_unit nibble(4, count); - constexpr precise_unit byte(8, count); + constexpr precise_unit nibble{4, count}; + constexpr precise_unit byte{8, count}; // https://physics.nist.gov/cuu/Units/binary.html - constexpr precise_unit kB(1000.0, byte); - constexpr precise_unit MB(1000.0, kB); - constexpr precise_unit GB(1000.0, MB); + constexpr precise_unit kB{1000.0, byte}; + constexpr precise_unit MB{1000.0, kB}; + constexpr precise_unit GB{1000.0, MB}; - constexpr precise_unit KiB(1024.0, byte); - constexpr precise_unit MiB(1024.0, KiB); - constexpr precise_unit GiB(1024.0, MiB); + constexpr precise_unit KiB{1024.0, byte}; + constexpr precise_unit MiB{1024.0, KiB}; + constexpr precise_unit GiB{1024.0, MiB}; constexpr precise_unit bit_s = log::logbase2; constexpr precise_unit shannon = bit_s; @@ -1356,10 +1350,9 @@ namespace precise { constexpr precise_unit deciban = precise::log::dB * precise::count; constexpr precise_unit nat = precise::log::neper * precise::count; - constexpr precise_unit trit = - precise_unit(precise::custom::equation_unit(14)); + constexpr precise_unit trit{precise::custom::equation_unit(14)}; // compute the number of digits - constexpr precise_unit digits = precise_unit(custom::equation_unit(10)); + constexpr precise_unit digits{custom::equation_unit(10)}; } // namespace data constexpr precise_unit bit = data::bit; @@ -1370,20 +1363,17 @@ namespace precise { /// Units related to computer computations namespace computation { - constexpr precise_unit flop = - precise_unit(1.0, precise::count, commodities::flop); + constexpr precise_unit flop{1.0, precise::count, commodities::flop}; constexpr precise_unit flops{flop / s}; - constexpr precise_unit mips = precise_unit( - 1.0, - precise::count / precise::s, - commodities::instruction); + constexpr precise_unit + mips{1.0, precise::count / precise::s, commodities::instruction}; } // namespace computation /// other special units namespace special { // Amplitude spectral density - constexpr precise_unit ASD = precise_unit( - detail::unit_data(1, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0)); + constexpr precise_unit ASD{ + detail::unit_data{1, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0}}; // Moment magnitude scale for earthquakes constexpr precise_unit moment_magnitude = precise_unit(custom::equation_unit(29)) * precise::cgs::dyn * @@ -1403,11 +1393,11 @@ namespace precise { // mach number constexpr precise_unit mach = m / s * pu; // square root of Hertz - constexpr precise_unit rootHertz = precise_unit( - detail::unit_data(0, 0, -5, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0)); + constexpr precise_unit rootHertz{ + detail::unit_data{0, 0, -5, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0}}; // square root of meter - constexpr precise_unit rootMeter = precise_unit( - detail::unit_data(-5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0)); + constexpr precise_unit rootMeter{ + detail::unit_data{-5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0}}; // custom defined unit of loudness constexpr precise_unit sone = generate_custom_unit(40); @@ -1422,8 +1412,8 @@ namespace precise { namespace other { // concentrations - constexpr precise_unit ppm(1e-6, count); - constexpr precise_unit ppb(1e-9, count); + constexpr precise_unit ppm{1e-6, count}; + constexpr precise_unit ppb{1e-9, count}; constexpr precise_unit candle{0.98135426889107, cd}; // 2019 redefinition @@ -1432,8 +1422,8 @@ namespace precise { constexpr precise_unit rpm{constants::pi / 30.0, rad* Hz}; constexpr precise_unit CFM(ft* ft* ft / min); - constexpr precise_unit MegaBuck(1000000.0, currency); - constexpr precise_unit GigaBuck(1000.0, MegaBuck); + constexpr precise_unit MegaBuck{1000000.0, currency}; + constexpr precise_unit GigaBuck{1000.0, MegaBuck}; } // namespace other namespace climate { @@ -1470,8 +1460,9 @@ constexpr unit eflag = unit_cast(precise::eflag); constexpr unit rad = unit_cast(precise::rad); constexpr unit defunit = unit_cast(precise::defunit); -constexpr unit - invalid(constants::invalid_conversion, detail::unit_data(nullptr)); +constexpr unit invalid{ + constants::invalid_conversion, + detail::unit_data{nullptr}}; /// Check if a precise unit is a default unit constexpr inline bool is_default(const precise_unit& utest) @@ -1525,20 +1516,20 @@ constexpr inline bool is_valid(const unit& utest) } // SI prefixes as units -constexpr unit deci(0.1, one); -constexpr unit centi(1e-2, one); -constexpr unit milli(1e-3, one); -constexpr unit micro(1e-6, one); -constexpr unit nano(1e-9, one); -constexpr unit pico(1e-12, one); -constexpr unit femto(1e-15, one); -constexpr unit atto(1e-18, one); -constexpr unit kilo(1e3, one); -constexpr unit mega(1e6, one); -constexpr unit giga(1e9, one); -constexpr unit tera(1e12, one); -constexpr unit peta(1e15, one); -constexpr unit exa(1e18, one); +constexpr unit deci{0.1, one}; +constexpr unit centi{1e-2, one}; +constexpr unit milli{1e-3, one}; +constexpr unit micro{1e-6, one}; +constexpr unit nano{1e-9, one}; +constexpr unit pico{1e-12, one}; +constexpr unit femto{1e-15, one}; +constexpr unit atto{1e-18, one}; +constexpr unit kilo{1e3, one}; +constexpr unit mega{1e6, one}; +constexpr unit giga{1e9, one}; +constexpr unit tera{1e12, one}; +constexpr unit peta{1e15, one}; +constexpr unit exa{1e18, one}; // SI Derived units: constexpr unit Hz = unit_cast(precise::Hz);