From 868842bd463b30abb5781100fe116b056b62a8cb Mon Sep 17 00:00:00 2001 From: Andy Little Date: Mon, 6 Jan 2020 21:29:05 +0000 Subject: [PATCH] Third party examples : add box example Add si::density quantity header . Add si::resistance quantity header. Update si::capacitance header with mF, uF, nF, pF. Update si::voltage header with mV, uV, nV,pV Third party example : add capacitor time curve example Add incoherent length units, TODO move them out from si header. Third party examples : add clcpp_response showing effectivenes of typed units for physical quantity library Third party examples : add conversion factor example Add third party examples to cmake Third party examples : box example : Add air_density constant for clarity remove explicit this-> and tidy up. Third party examples : in clcpp response example, change base unit from km to m for single type or all units example. Third party examples : conversion_factor , add inline constexpr to units_str function. Third party examples : box_example, change quantity::unit syntax to quantity::unit<> to allow generic(default double) value_type. examples : remove examples from third party to main examples directory. Update cmake. physical/si/resistance.hpp : remove underscores from kiloohm etc, UDL collision with 'R' so prefix with underscore --- example/CMakeLists.txt | 4 + example/box_example.cpp | 125 +++++++++++ example/capacitor_time_curve.cpp | 76 +++++++ example/clcpp_response.cpp | 230 ++++++++++++++++++++ example/conversion_factor.cpp | 91 ++++++++ example/sandbox.cpp | 86 ++++++++ src/include/units/physical/dimensions.h | 6 + src/include/units/physical/si/area.h | 5 + src/include/units/physical/si/capacitance.h | 17 ++ src/include/units/physical/si/density.h | 47 ++++ src/include/units/physical/si/length.h | 88 ++++++++ src/include/units/physical/si/resistance.h | 63 ++++++ src/include/units/physical/si/voltage.h | 16 ++ 13 files changed, 854 insertions(+) create mode 100644 example/box_example.cpp create mode 100644 example/capacitor_time_curve.cpp create mode 100644 example/clcpp_response.cpp create mode 100644 example/conversion_factor.cpp create mode 100644 example/sandbox.cpp create mode 100644 src/include/units/physical/si/density.h create mode 100644 src/include/units/physical/si/resistance.h diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index b06b41b2..54ded95a 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -29,3 +29,7 @@ add_example(avg_velocity) add_example(hello_units) add_example(measurement) add_example(unknown_dimension) +add_example(box_example) +add_example(capacitor_time_curve) +add_example(clcpp_response) +add_example(conversion_factor) diff --git a/example/box_example.cpp b/example/box_example.cpp new file mode 100644 index 00000000..880409dd --- /dev/null +++ b/example/box_example.cpp @@ -0,0 +1,125 @@ + + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace{ + + namespace length{ + + template + using m = units::si::length; + + template + using mm = units::si::length; + } + + namespace acceleration{ + + template + using m_per_s2 = units::si::acceleration; + + template + constexpr m_per_s2<> g{static_cast(9.80665)}; + } + + namespace force{ + + template + using N = units::si::force; + } + + namespace mass { + + template + using kg = units::si::mass; + } + + namespace density { + + template + using kg_per_m3 = units::si::density; + } + + namespace volume { + + template + using m3 = units::si::volume; + } +} + +struct Box{ + + Box(length::m<> const& l, + length::m<> const& w, + length::m<> const& h + ): length{l},width{w},height{h}{} + + force::N<> filled_weight()const + { + volume::m3<> const volume + = length * width * height; + mass::kg<> const mass = contents.density * volume; + return mass * acceleration::g<>; + } + + length::m<> fill_level(mass::kg<> const & measured_mass)const + { + return height + * (measured_mass * acceleration::g<>) / filled_weight(); + } + + volume::m3<> spare_capacity(mass::kg<> const & measured_mass)const + { + return (height - fill_level(measured_mass)) * width * length; + } + + struct contents{ + contents():density{air_density}{} + density::kg_per_m3<> density; + }contents; + + void set_contents_density(density::kg_per_m3<> const & density_in) + { + assert( density_in > air_density ); + contents.density = density_in; + } + + static constexpr density::kg_per_m3<> air_density{1.225}; + + length::m<> length; + length::m<> width; + length::m<> height; +}; + +#include + +using namespace units::si::literals; +int main() +{ + auto box = Box{1000.0mm, 500.0mm, 200.0mm}; + box.set_contents_density(1000.0kg_per_m3); + + auto fill_time = 200.0s; // time since starting fill + auto measured_mass = 20.0kg; // measured mass at fill_time + + std::cout << "mpusz/units box example...\n"; + std::cout << "fill height at " << fill_time << " = " + << box.fill_level(measured_mass) << "( " << (box.fill_level(measured_mass)/ box.height)*100 << "% full)\n"; + std::cout << "spare_capacity at " << fill_time << " = " + << box.spare_capacity(measured_mass) <<'\n'; + std::cout << "input flow rate after " << fill_time + << " = " << measured_mass / fill_time <<'\n'; + std::cout << "float rise rate = " + << box.fill_level(measured_mass) / fill_time <<'\n'; + auto fill_time_left + = (box.height / box.fill_level(measured_mass) - 1) * fill_time ; + std::cout << "box full E.T.A. at current flow rate = " << fill_time_left <<'\n'; + +} diff --git a/example/capacitor_time_curve.cpp b/example/capacitor_time_curve.cpp new file mode 100644 index 00000000..3f30b8a4 --- /dev/null +++ b/example/capacitor_time_curve.cpp @@ -0,0 +1,76 @@ + +/* + Copyright (c) 2003-2020 Andy Little. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see http://www.gnu.org/licenses./ +*/ + +/* + capacitor discharge curve using compile_time + physical_quantities +*/ + +#include +#include +#include +#include +#include + +namespace { + namespace voltage { + + template + using V = units::si::voltage; + + template + using mV = units::si::voltage; + + template + using uV = units::si::voltage; + + template + using nV = units::si::voltage; + + template + using pV = units::si::voltage; + } +} + +#include + +using namespace units::si::literals; +int main() +{ + std::cout << "mpusz/units capacitor time curve example...\n"; + std::cout.setf(std::ios_base::fixed,std::ios_base::floatfield); + std::cout.precision(3); + + auto constexpr C = 0.47uF; + auto constexpr V0 = 5.0V; + auto constexpr R = 4.7kR; + + for ( auto t = 0ms ; t <= 50ms; ++t ){ + + auto const Vt = V0 * std::exp(-t / (R * C)); + + std::cout << "at " << t << " voltage is " ; + + if ( Vt >= 1V ) std::cout << Vt ; + else if( Vt >= 1mV ) std::cout << voltage::mV<>{Vt}; + else if( Vt >= 1uV ) std::cout << voltage::uV<>{Vt}; + else if( Vt >= 1nV ) std::cout << voltage::nV<>{Vt}; + else std::cout << voltage::pV<>{Vt}; + std::cout << "\n"; + } +} diff --git a/example/clcpp_response.cpp b/example/clcpp_response.cpp new file mode 100644 index 00000000..8ffff7d4 --- /dev/null +++ b/example/clcpp_response.cpp @@ -0,0 +1,230 @@ + +/* + Copyright (c) 2003-2019 Andy Little. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see http://www.gnu.org/licenses./ +*/ + +#include +#include +#include +#include +#include + +namespace { + namespace length{ + + template + using m = units::si::length; + + template + using mm = units::si::length; + + template + using fm = units::si::length; + + template + using km = units::si::length; + + template + using AU = units::si::length; + + template + using in = units::si::length; + + template + using angstrom = units::si::length; + + template + using ch = units::si::length; + + template + using fathom = units::si::length; + + template + using fathom_us = units::si::length; + + template + using ft = units::si::length; + + template + using ft_us = units::si::length; + + template + using ly = units::si::length; + + template + using mi = units::si::length; + + template + using mi_naut = units::si::length; + + template + using pc = units::si::length; + + template + using pica_comp = units::si::length; + + template + using pica_prn = units::si::length; + + template + using point_comp = units::si::length; + + template + using point_prn = units::si::length; + + template + using rd = units::si::length; + + template + using yd = units::si::length; + + } + + namespace time{ + + template + using s = units::si::time; + + template + using min = units::si::time; + + template + using h = units::si::time; + } + + namespace area{ + + template + using m2 = units::si::area; + + template + using fm2 = units::si::area; + } +} + +#include + +using namespace units::si::literals; + +void simple_quantities() +{ + using distance = length::m<>; + using time = time::s<>; + distance constexpr km = 1.0km; + distance constexpr miles = 1q_mi; + + time constexpr sec = 1s; + time constexpr min = 1min; + time constexpr hr = 1h; + + std::cout << "A physical quantities library can choose the simple\n"; + std::cout << "option to provide output using a single type for each base unit:\n\n"; + std::cout << km << '\n'; + std::cout << miles << '\n'; + std::cout << sec << '\n'; + std::cout << min << '\n'; + std::cout << hr << "\n\n"; +} + +void quantities_with_typed_units() +{ + length::km<> constexpr km = 1km; + + length::mi<> constexpr miles = 1q_mi; + + std::cout.precision(6); + + time::s<> constexpr sec = 1s; + time::min<> constexpr min = 1min; + time::h<> constexpr hr = 1h; + + std::cout << "A more flexible option is to provide separate types for each unit,\n\n"; + std::cout << km << '\n'; + std::cout << miles << '\n'; + std::cout << sec << '\n'; + std::cout << min << '\n'; + std::cout << hr << "\n\n"; + + length::m<> constexpr meter = 1m; + std::cout << "then a wide range of pre-defined units can be defined and converted,\n" + " for consistency and repeatability across applications:\n\n"; + + std::cout << meter << '\n' ; + + std::cout << " = " << length::AU<>(meter) << '\n'; + std::cout << " = " << length::angstrom<>(meter) << '\n'; + std::cout << " = " << length::ch<>(meter) << '\n'; + std::cout << " = " << length::fathom<>(meter) << '\n'; + std::cout << " = " << length::fathom_us<>(meter) << '\n'; + std::cout << " = " << length::ft<>(meter) << '\n'; + std::cout << " = " << length::ft_us<>(meter) << '\n'; + std::cout << " = " << length::in<>(meter) << '\n'; + std::cout << " = " << length::ly<>(meter) << '\n'; + std::cout << " = " << length::mi<>(meter) << '\n'; + std::cout << " = " << length::mi_naut<>(meter) << '\n'; + std::cout << " = " << length::pc<>(meter) << '\n'; + std::cout << " = " << length::pica_comp<>(meter) << '\n'; + std::cout << " = " << length::pica_prn<>(meter) << '\n'; + std::cout << " = " << length::point_comp<>(meter) << '\n'; + std::cout << " = " << length::point_prn<>(meter) << '\n'; + std::cout << " = " << length::rd<>(meter) << '\n'; + std::cout << " = " << length::yd<>(meter) << '\n'; +} + +void calcs_comparison() +{ + std::cout.precision(20); + std::cout << "\nA distinct unit for each type is efficient and accurate\n" + "when adding two values of the same very big\n" + "or very small type:\n\n"; + + length::fm L1A = 2fm; + length::fm L2A = 3fm; + length::fm LrA = L1A + L2A; + + std::cout << L1A << " + " << L2A << " = " << LrA << "\n\n"; + + std::cout << "The single unit method must convert large\n" + "or small values in other units to the base unit.\n" + "This is both inefficient and inaccurate\n\n"; + + length::m L1B = L1A; + length::m L2B = L2A; + length::m LrB = L1B + L2B; + + std::cout << L1B << " + " << L2B << " = " << LrB << "\n\n"; + + std::cout << "In multiplication and division:\n\n"; + + area::fm2 ArA = L1A * L2A ; + std::cout << L1A << " * " << L2A << " = " << ArA << "\n\n"; + + std::cout <<"similar problems arise\n\n"; + + area::m2 ArB = L1B * L2B; + std::cout << L1B << " * " << L2B << "\n = " << ArB << '\n'; +} + +int main() +{ + std::cout << "This demo was originally posted on com.lang.c++.moderated in 2006\n"; + std::cout << "http://compgroups.net/comp.lang.c++.moderated/dimensional-analysis-units/51712\n"; + std::cout << "Here converted to use mpusz/units library.\n\n"; + + simple_quantities(); + quantities_with_typed_units(); + calcs_comparison(); +} diff --git a/example/conversion_factor.cpp b/example/conversion_factor.cpp new file mode 100644 index 00000000..efc1bb1d --- /dev/null +++ b/example/conversion_factor.cpp @@ -0,0 +1,91 @@ + +/* + Copyright (c) 2003-2020 Andy Little. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see http://www.gnu.org/licenses./ +*/ + +#include + +/* + get conversion factor from one dimensionally equivalent + quantity type to another +*/ + +namespace { + + template < + units::Quantity Target, + units::Quantity Source + > + requires units::equivalent_dim + constexpr inline + std::common_type_t< + typename Target::rep, + typename Source::rep + > + conversion_factor(Target , Source) + { + // get quantities looking like inputs but with Q::rep that doesnt have narrowing conversion + typedef std::common_type_t< + typename Target::rep, + typename Source::rep + > rep; + typedef units::quantity source; + typedef units::quantity target; + return target{source{1}}.count(); + } + + // get at the units text of the quantity, without its numeric value + auto inline constexpr units_str( units::Quantity const & q) + { + typedef std::remove_cvref_t qtype; + return units::detail::unit_text(); + } +} + +namespace { + + namespace length{ + + template + using m = units::si::length; + + template + using mm = units::si::length; + } +} + +#include + +using namespace units::si::literals; +int main() +{ + std::cout << "conversion factor in mpusz/units...\n\n"; + + length::m<> constexpr lengthA = 2.0m; + length::mm<> constexpr lengthB = lengthA; + + std::cout << "lengthA( " << lengthA << " ) and lengthB( " << lengthB << " )\n" + "represent the same length in different units.\n\n"; + + std::cout << "therefore ratio lengthA / lengthB == " << lengthA / lengthB << "\n\n"; + + std::cout << "conversion factor from " + "lengthA::unit of " << units_str(lengthA) + << " to lengthB::unit of " << units_str(lengthB) << " :\n\n" + "lengthB.count( " << lengthB.count() << " ) == " + "lengthA.count( " << lengthA.count() << " ) * " + "conversion_factor( " << conversion_factor(lengthB, lengthA) << " )\n"; +} diff --git a/example/sandbox.cpp b/example/sandbox.cpp new file mode 100644 index 00000000..b24103ae --- /dev/null +++ b/example/sandbox.cpp @@ -0,0 +1,86 @@ + +/* + Copyright (c) 2003-2020 Andy Little. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see http://www.gnu.org/licenses./ +*/ + + +#include + +/* + get conversion factor from one dimensionally-equivalent + quantity type to another +*/ + +namespace { + + + template < + units::Quantity Target, + units::Quantity Source + > + requires units::equivalent_dim + constexpr inline + std::common_type_t< + typename Target::rep, + typename Source::rep + > + conversion_factor() + { + // get quantities looking like inputs but with Q::rep that doesnt have narrowing conversion + typedef std::common_type_t< + typename Target::rep, + typename Source::rep + > rep; + typedef units::quantity source; + typedef units::quantity target; + return target{source{1}}.count(); + } + + auto units_str( units::Quantity const & q) + { + typedef std::remove_cvref_t qtype; + return units::detail::unit_text(); + } + +} + +namespace { + + namespace length{ + using m = units::si::length; + using mm = units::si::length; + } + +} + +#include + +using namespace units::si::literals; +int main() +{ + length::m constexpr plankA = 2.0m; + length::mm constexpr plankB = 1000.0mm; + + std::cout << "ratio plankA / plankB = " << plankA / plankB << '\n'; + + std::cout << "conversion factor to convert from vS in " << units_str(plankA) ; + std::cout << " to vT in " << units_str(plankB) << " : vT = vS * "; + std::cout << conversion_factor() << '\n'; + + // can be evaluated at compile time + static_assert(conversion_factor() == 1000,"error"); + +} diff --git a/src/include/units/physical/dimensions.h b/src/include/units/physical/dimensions.h index 08fff0ae..c13f0cba 100644 --- a/src/include/units/physical/dimensions.h +++ b/src/include/units/physical/dimensions.h @@ -83,12 +83,18 @@ struct dim_force : derived_dimension, exp> {}; template F, DimensionOf L> struct dim_energy : derived_dimension, exp> {}; +template M, DimensionOf L> +struct dim_density : derived_dimension, exp> {}; + template E, DimensionOf T> struct dim_power : derived_dimension, exp> {}; template P, DimensionOf C> struct dim_voltage : derived_dimension, exp> {}; +template V, DimensionOf C> +struct dim_resistance : derived_dimension, exp> {}; + template T, DimensionOf C> struct dim_electric_charge : derived_dimension, exp> {}; diff --git a/src/include/units/physical/si/area.h b/src/include/units/physical/si/area.h index 4a3f9199..c06077dd 100644 --- a/src/include/units/physical/si/area.h +++ b/src/include/units/physical/si/area.h @@ -33,6 +33,7 @@ struct dim_area : physical::dim_area {}; struct square_millimetre : deduced_unit {}; struct square_centimetre : deduced_unit {}; +struct square_femtometre : deduced_unit {}; struct square_kilometre : deduced_unit {}; struct hectare : deduced_unit {}; @@ -54,6 +55,10 @@ constexpr auto operator"" mm2(long double l) { return area(l); } constexpr auto operator"" cm2(long double l) { return area(l); } +// fm2 +constexpr auto operator"" fm2(unsigned long long l) { return area(l); } +constexpr auto operator"" fm2(long double l) { return area(l); } + // km2 constexpr auto operator"" km2(unsigned long long l) { return area(l); } constexpr auto operator"" km2(long double l) { return area(l); } diff --git a/src/include/units/physical/si/capacitance.h b/src/include/units/physical/si/capacitance.h index eb71780f..170e091b 100644 --- a/src/include/units/physical/si/capacitance.h +++ b/src/include/units/physical/si/capacitance.h @@ -32,6 +32,11 @@ namespace units::si { struct farad : named_unit {}; +struct millifarad : prefixed_unit {}; +struct microfarad : prefixed_unit {}; +struct nanofarad : prefixed_unit {}; +struct picofarad : prefixed_unit {}; + struct dim_capacitance : physical::dim_capacitance {}; template @@ -43,6 +48,18 @@ inline namespace literals { constexpr auto operator""F(unsigned long long l) { return capacitance(l); } constexpr auto operator""_F(long double l) { return capacitance(l); } +constexpr auto operator""mF(unsigned long long l) { return capacitance(l); } +constexpr auto operator""mF(long double l) { return capacitance(l); } + +constexpr auto operator""uF(unsigned long long l) { return capacitance(l); } +constexpr auto operator""uF(long double l) { return capacitance(l); } + +constexpr auto operator""nF(unsigned long long l) { return capacitance(l); } +constexpr auto operator""nF(long double l) { return capacitance(l); } + +constexpr auto operator""pF(unsigned long long l) { return capacitance(l); } +constexpr auto operator""pF(long double l) { return capacitance(l); } + } // namespace literals } // namespace units::si diff --git a/src/include/units/physical/si/density.h b/src/include/units/physical/si/density.h new file mode 100644 index 00000000..c87172de --- /dev/null +++ b/src/include/units/physical/si/density.h @@ -0,0 +1,47 @@ +// The MIT License (MIT) +// +// Copyright (c) 2018 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +#include +#include +#include +#include +#include + +namespace units::si { + +struct kilogram_per_metre_cub : unit {}; + +struct dim_density : physical::dim_density {}; + +template +using density = quantity; + +inline namespace literals { + +constexpr auto operator"" kg_per_m3(unsigned long long l) { return density(l); } +constexpr auto operator"" kg_per_m3(long double l) { return density(l); } + +} // namespace literals + +} // namespace units::si diff --git a/src/include/units/physical/si/length.h b/src/include/units/physical/si/length.h index 5830323f..46ef1646 100644 --- a/src/include/units/physical/si/length.h +++ b/src/include/units/physical/si/length.h @@ -34,8 +34,34 @@ struct centimetre : prefixed_unit {}; struct decimetre : prefixed_unit {}; struct hectometre : prefixed_unit {}; struct kilometre : prefixed_unit {}; +struct femtometre : prefixed_unit {}; struct astronomical_unit : named_scaled_unit, metre> {}; +#if 0 +struct inch : named_scaled_unit, metre> {}; +struct foot : named_scaled_unit, metre> {}; +struct yard : named_scaled_unit, metre> {}; +#endif +struct foot_us : named_scaled_unit, metre> {}; +struct fathom : named_scaled_unit, metre> {}; +struct fathom_us : named_scaled_unit,metre> {}; +struct chain : named_scaled_unit, metre> {}; + +#if 0 +struct thou : named_scaled_unit,metre> {}; +#endif +struct mil : named_scaled_unit,metre> {}; + +struct light_year : named_scaled_unit,metre> {}; +struct mile : named_scaled_unit,metre> {}; +struct nautical_mile : named_scaled_unit,metre> {}; +struct parsec : named_scaled_unit,metre> {}; +struct pica_comp : named_scaled_unit,metre> {}; +struct pica_prn : named_scaled_unit,metre> {}; +struct point_comp : named_scaled_unit,metre> {}; +struct point_prn : named_scaled_unit,metre> {}; +struct rod : named_scaled_unit,metre> {}; +struct angstrom : named_scaled_unit,metre> {}; struct dim_length : physical::dim_length {}; @@ -52,6 +78,10 @@ constexpr auto operator"" m(long double l) { return length(l constexpr auto operator"" mm(unsigned long long l) { return length(l); } constexpr auto operator"" mm(long double l) { return length(l); } +// fm +constexpr auto operator"" fm(unsigned long long l) { return length(l); } +constexpr auto operator"" fm(long double l) { return length(l); } + // cm constexpr auto operator"" cm(unsigned long long l) { return length(l); } constexpr auto operator"" cm(long double l) { return length(l); } @@ -71,6 +101,64 @@ constexpr auto operator"" km(long double l) { return length(l); } constexpr auto operator"" au(long double l) { return length(l); } +#if 0 +constexpr auto operator"" q_in(unsigned long long l) { return length(l); } +constexpr auto operator"" q_in(long double l) { return length(l); } + +constexpr auto operator"" q_ft(unsigned long long l) { return length(l); } +constexpr auto operator"" q_ft(long double l) { return length(l); } + +constexpr auto operator"" q_yd(unsigned long long l) { return length(l); } +constexpr auto operator"" q_yd(long double l) { return length(l); } +#endif +constexpr auto operator"" ft_us(unsigned long long l) { return length(l); } +constexpr auto operator"" ft_us(long double l) { return length(l); } + +constexpr auto operator"" fathom(unsigned long long l) { return length(l); } +constexpr auto operator"" fathom(long double l) { return length(l); } + +constexpr auto operator"" fathom_us(unsigned long long l) { return length(l); } +constexpr auto operator"" fathom_us(long double l) { return length(l); } + +constexpr auto operator"" ch(unsigned long long l) { return length(l); } +constexpr auto operator"" ch(long double l) { return length(l); } + +#if 0 +constexpr auto operator"" thou(unsigned long long l) { return length(l); } +constexpr auto operator"" thou(long double l) { return length(l); } +#endif +constexpr auto operator"" mil(unsigned long long l) { return length(l); } +constexpr auto operator"" mil(long double l) { return length(l); } + +constexpr auto operator"" ly(unsigned long long l) { return length(l); } +constexpr auto operator"" ly(long double l) { return length(l); } + +constexpr auto operator"" q_mi(unsigned long long l) { return length(l); } +constexpr auto operator"" q_mi(long double l) { return length(l); } + +constexpr auto operator"" pc(unsigned long long l) { return length(l); } +constexpr auto operator"" pc(long double l) { return length(l); } + +constexpr auto operator"" mi_naut(unsigned long long l) { return length(l); } +constexpr auto operator"" mi_naut(long double l) { return length(l); } + +constexpr auto operator"" pica_comp(unsigned long long l) { return length(l); } +constexpr auto operator"" pica_comp(long double l) { return length(l); } + +constexpr auto operator"" pica_prn(unsigned long long l) { return length(l); } +constexpr auto operator"" pica_prn(long double l) { return length(l); } + +constexpr auto operator"" point_comp(unsigned long long l) { return length(l); } +constexpr auto operator"" point_comp(long double l) { return length(l); } + +constexpr auto operator"" point_prn(unsigned long long l) { return length(l); } +constexpr auto operator"" point_prn(long double l) { return length(l); } + +constexpr auto operator"" rd(unsigned long long l) { return length(l); } +constexpr auto operator"" rd(long double l) { return length(l); } + +constexpr auto operator"" angstrom(unsigned long long l) { return length(l); } +constexpr auto operator"" angstrom(long double l) { return length(l); } } // namespace literals diff --git a/src/include/units/physical/si/resistance.h b/src/include/units/physical/si/resistance.h new file mode 100644 index 00000000..c7ab24a9 --- /dev/null +++ b/src/include/units/physical/si/resistance.h @@ -0,0 +1,63 @@ +// The MIT License (MIT) +// +// Copyright (c) 2018 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +#include +#include +#include +#include +#include + +namespace units::si { + +struct ohm : named_unit {}; +struct milliohm : prefixed_unit {}; +struct kiloohm : prefixed_unit {}; +struct megaohm : prefixed_unit {}; + +struct dim_resistance : physical::dim_resistance {}; + +template +using resistance = quantity; + +inline namespace literals { + +//R +constexpr auto operator""R(unsigned long long l) { return resistance(l); } +constexpr auto operator""_R(long double l) { return resistance(l); } + +//mR +constexpr auto operator""mR(unsigned long long l) { return resistance(l); } +constexpr auto operator""mR(long double l) { return resistance(l); } + +//kR +constexpr auto operator""kR(unsigned long long l) { return resistance(l); } +constexpr auto operator""kR(long double l) { return resistance(l); } + +// MR +constexpr auto operator""MR(unsigned long long l) { return resistance(l); } +constexpr auto operator""MR(long double l) { return resistance(l); } + +} // namespace literals + +} // namespace units::si diff --git a/src/include/units/physical/si/voltage.h b/src/include/units/physical/si/voltage.h index 7138e728..e1d97827 100644 --- a/src/include/units/physical/si/voltage.h +++ b/src/include/units/physical/si/voltage.h @@ -31,6 +31,10 @@ namespace units::si { struct volt : named_unit {}; +struct millivolt : prefixed_unit {}; +struct microvolt : prefixed_unit {}; +struct nanovolt : prefixed_unit {}; +struct picovolt : prefixed_unit {}; struct dim_voltage : physical::dim_voltage {}; @@ -43,6 +47,18 @@ inline namespace literals { constexpr auto operator""V(unsigned long long l) { return voltage(l); } constexpr auto operator""V(long double l) { return voltage(l); } +constexpr auto operator""mV(unsigned long long l) { return voltage(l); } +constexpr auto operator""mV(long double l) { return voltage(l); } + +constexpr auto operator""uV(unsigned long long l) { return voltage(l); } +constexpr auto operator""uV(long double l) { return voltage(l); } + +constexpr auto operator""nV(unsigned long long l) { return voltage(l); } +constexpr auto operator""nV(long double l) { return voltage(l); } + +constexpr auto operator""pV(unsigned long long l) { return voltage(l); } +constexpr auto operator""pV(long double l) { return voltage(l); } + } // namespace literals } // namespace units::si