mirror of
https://github.com/mpusz/mp-units.git
synced 2025-07-29 18:07:16 +02:00
change const order
move in,ft,fathom,ft2,ft3,mph from us to international namespace TODO distinguish units with different names for same values
This commit is contained in:
committed by
Mateusz Pusz
parent
c93136e81b
commit
024f5a9c83
@ -22,7 +22,7 @@
|
||||
|
||||
#include <units/physical/cgs/velocity.h>
|
||||
#include <units/physical/si/velocity.h>
|
||||
#include <units/physical/us/velocity.h>
|
||||
#include <units/physical/international/velocity.h>
|
||||
#include <iostream>
|
||||
|
||||
namespace {
|
||||
|
@ -56,26 +56,26 @@ namespace{
|
||||
|
||||
struct Box{
|
||||
|
||||
Box(length::m<> const& l,
|
||||
length::m<> const& w,
|
||||
length::m<> const& h
|
||||
Box(const length::m<> & l,
|
||||
const length::m<> & w,
|
||||
const length::m<> & h
|
||||
): length{l},width{w},height{h}{}
|
||||
|
||||
force::N<> filled_weight()const
|
||||
{
|
||||
volume::m3<> const volume
|
||||
const volume::m3<> volume
|
||||
= length * width * height;
|
||||
mass::kg<> const mass = contents.density * volume;
|
||||
const mass::kg<> mass = contents.density * volume;
|
||||
return mass * acceleration::g<>;
|
||||
}
|
||||
|
||||
length::m<> fill_level(mass::kg<> const & measured_mass)const
|
||||
length::m<> fill_level(const mass::kg<> & measured_mass)const
|
||||
{
|
||||
return height
|
||||
* (measured_mass * acceleration::g<>) / filled_weight();
|
||||
}
|
||||
|
||||
volume::m3<> spare_capacity(mass::kg<> const & measured_mass)const
|
||||
volume::m3<> spare_capacity(const mass::kg<> & measured_mass)const
|
||||
{
|
||||
return (height - fill_level(measured_mass)) * width * length;
|
||||
}
|
||||
@ -85,7 +85,7 @@ struct Box{
|
||||
density::kgpm3<> density;
|
||||
}contents;
|
||||
|
||||
void set_contents_density(density::kgpm3<> const & density_in)
|
||||
void set_contents_density(const density::kgpm3<> & density_in)
|
||||
{
|
||||
assert( density_in > air_density );
|
||||
contents.density = density_in;
|
||||
|
@ -56,13 +56,13 @@ int main()
|
||||
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;
|
||||
constexpr auto C = 0.47uF;
|
||||
constexpr auto V0 = 5.0V;
|
||||
constexpr auto R = 4.7kR;
|
||||
|
||||
for ( auto t = 0ms ; t <= 50ms; ++t ){
|
||||
|
||||
auto const Vt = V0 * std::exp(-t / (R * C));
|
||||
const auto Vt = V0 * std::exp(-t / (R * C));
|
||||
|
||||
std::cout << "at " << t << " voltage is " ;
|
||||
|
||||
|
@ -128,12 +128,13 @@ void simple_quantities()
|
||||
{
|
||||
using distance = length::m<>;
|
||||
using time = time::s<>;
|
||||
distance constexpr km = 1.0km;
|
||||
distance constexpr miles = 1.0mi;
|
||||
|
||||
time constexpr sec = 1s;
|
||||
time constexpr min = 1min;
|
||||
time constexpr hr = 1h;
|
||||
constexpr distance km = 1.0km;
|
||||
constexpr distance miles = 1.0mi;
|
||||
|
||||
constexpr time sec = 1s;
|
||||
constexpr time min = 1min;
|
||||
constexpr time 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";
|
||||
@ -146,15 +147,14 @@ void simple_quantities()
|
||||
|
||||
void quantities_with_typed_units()
|
||||
{
|
||||
length::km<> constexpr km = 1km;
|
||||
|
||||
length::mi<> constexpr miles = 1.0mi;
|
||||
constexpr length::km<> km = 1km;
|
||||
constexpr length::mi<> miles = 1.0mi;
|
||||
|
||||
std::cout.precision(6);
|
||||
|
||||
time::s<> constexpr sec = 1s;
|
||||
time::min<> constexpr min = 1min;
|
||||
time::h<> constexpr hr = 1h;
|
||||
constexpr time::s<> sec = 1s;
|
||||
constexpr time::min<> min = 1min;
|
||||
constexpr time::h<> hr = 1h;
|
||||
|
||||
std::cout << "A more flexible option is to provide separate types for each unit,\n\n";
|
||||
std::cout << km << '\n';
|
||||
@ -163,7 +163,7 @@ void quantities_with_typed_units()
|
||||
std::cout << min << '\n';
|
||||
std::cout << hr << "\n\n";
|
||||
|
||||
length::m<> constexpr meter = 1m;
|
||||
constexpr length::m<> 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";
|
||||
|
||||
|
@ -48,7 +48,7 @@ namespace {
|
||||
}
|
||||
|
||||
// get at the units text of the quantity, without its numeric value
|
||||
auto inline constexpr units_str( units::Quantity const & q)
|
||||
auto inline constexpr units_str( const units::Quantity & q)
|
||||
{
|
||||
typedef std::remove_cvref_t<decltype(q)> qtype;
|
||||
return units::detail::unit_text<typename qtype::dimension, typename qtype::unit>();
|
||||
@ -74,8 +74,8 @@ int main()
|
||||
{
|
||||
std::cout << "conversion factor in mpusz/units...\n\n";
|
||||
|
||||
length::m<> constexpr lengthA = 2.0m;
|
||||
length::mm<> constexpr lengthB = lengthA;
|
||||
constexpr length::m<> lengthA = 2.0m;
|
||||
constexpr length::mm<> lengthB = lengthA;
|
||||
|
||||
std::cout << "lengthA( " << lengthA << " ) and lengthB( " << lengthB << " )\n"
|
||||
"represent the same length in different units.\n\n";
|
||||
|
@ -21,7 +21,7 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include <units/physical/si/velocity.h>
|
||||
#include <units/physical/us/velocity.h>
|
||||
#include <units/physical/international/velocity.h>
|
||||
#include <units/format.h>
|
||||
#include <iostream>
|
||||
|
||||
|
@ -27,9 +27,9 @@
|
||||
|
||||
namespace units::iau {
|
||||
|
||||
struct light_year : named_scaled_unit<light_year,"ly(iau)",no_prefix,ratio<946073,100000,15>,si::metre> {};
|
||||
struct parsec : named_scaled_unit<parsec,"pc(iau)",no_prefix,ratio<1542839,500000,16>,si::metre> {};
|
||||
struct angstrom : named_scaled_unit<angstrom,"angstrom(iau)",no_prefix,ratio<1,1,-10>,si::metre> {};
|
||||
struct light_year : named_scaled_unit<light_year,"ly",no_prefix,ratio<946073,100000,15>,si::metre> {};
|
||||
struct parsec : named_scaled_unit<parsec,"pc",no_prefix,ratio<1542839,500000,16>,si::metre> {};
|
||||
struct angstrom : named_scaled_unit<angstrom,"angstrom",no_prefix,ratio<1,1,-10>,si::metre> {};
|
||||
|
||||
inline namespace literals {
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
#include <units/physical/si/area.h>
|
||||
#include <units/physical/international/length.h>
|
||||
|
||||
namespace units::us {
|
||||
namespace units::international {
|
||||
|
||||
struct square_foot : deduced_unit<square_foot, si::dim_area, international::foot> {};
|
||||
|
||||
@ -37,4 +37,4 @@ constexpr auto operator"" ft2(long double l) { return si::area<square_foot, long
|
||||
|
||||
} // namespace literals
|
||||
|
||||
} // namespace units::us
|
||||
} // namespace units::international
|
@ -35,7 +35,6 @@ namespace units::international {
|
||||
//https://en.wikipedia.org/wiki/International_yard_and_pound
|
||||
struct yard : named_scaled_unit<yard, "yd", no_prefix, ratio<9'144, 1'000,-1>, si::metre> {};
|
||||
|
||||
|
||||
//international foot
|
||||
//https://en.wikipedia.org/wiki/Foot_(unit)#International_foot
|
||||
struct foot : named_scaled_unit<foot, "ft", no_prefix, ratio<3'048,1'000,-1>, si::metre> {};
|
||||
@ -55,10 +54,9 @@ struct mile : named_scaled_unit<mile, "mi", no_prefix, ratio<25'146,15'625,3>, s
|
||||
//https://en.wikipedia.org/wiki/Mile#Nautical_mile
|
||||
struct nautical_mile : named_scaled_unit<nautical_mile,"mi(naut)",no_prefix, ratio<463,250,3>,si::metre> {};
|
||||
|
||||
#if 0
|
||||
//TODO thou
|
||||
//https://en.wikipedia.org/wiki/Thousandth_of_an_inch
|
||||
struct thou : named_scaled_unit<thou,"thou",no_prefix,ratio<127,50,-5>,si::metre> {};
|
||||
#endif
|
||||
//struct thou : named_scaled_unit<thou,"thou",no_prefix,ratio<127,50,-5>,si::metre> {};
|
||||
// different name for thou
|
||||
//https://en.wikipedia.org/wiki/Thousandth_of_an_inch
|
||||
struct mil : named_scaled_unit<mil,"mil",no_prefix,ratio<127,50,-5>,si::metre> {};
|
||||
@ -89,11 +87,10 @@ constexpr auto operator"" mi(long double l) { return si::length<mile, long doubl
|
||||
constexpr auto operator"" naut_mi(unsigned long long l) { return si::length<nautical_mile, std::int64_t>(l); }
|
||||
constexpr auto operator"" naut_mi(long double l) { return si::length<nautical_mile, long double>(l); }
|
||||
|
||||
#if 0
|
||||
// thou
|
||||
constexpr auto operator"" thou(unsigned long long l) { return si::length<thou, std::int64_t>(l); }
|
||||
constexpr auto operator"" thou(long double l) { return si::length<thou, long double>(l); }
|
||||
#endif
|
||||
//TODO thou
|
||||
//constexpr auto operator"" thou(unsigned long long l) { return si::length<thou, std::int64_t>(l); }
|
||||
//constexpr auto operator"" thou(long double l) { return si::length<thou, long double>(l); }
|
||||
|
||||
// mil
|
||||
constexpr auto operator"" mil(unsigned long long l) { return si::length<mil, std::int64_t>(l); }
|
||||
constexpr auto operator"" mil(long double l) { return si::length<mil, long double>(l); }
|
||||
|
@ -25,7 +25,7 @@
|
||||
#include <units/physical/si/velocity.h>
|
||||
#include <units/physical/international/length.h>
|
||||
|
||||
namespace units::us {
|
||||
namespace units::international {
|
||||
|
||||
struct mile_per_hour : deduced_unit<mile_per_hour, si::dim_velocity, international::mile, si::hour> {};
|
||||
|
||||
@ -37,4 +37,4 @@ constexpr auto operator"" mph(long double l) { return si::velocity<mile_per_hour
|
||||
|
||||
} // namespace literals
|
||||
|
||||
} // namespace units::us
|
||||
} // namespace units::international
|
@ -25,7 +25,7 @@
|
||||
#include <units/physical/si/volume.h>
|
||||
#include <units/physical/international/length.h>
|
||||
|
||||
namespace units::us {
|
||||
namespace units::international {
|
||||
|
||||
struct cubic_foot : deduced_unit<cubic_foot, si::dim_volume, international::foot> {};
|
||||
|
||||
@ -37,4 +37,4 @@ constexpr auto operator""ft3(long double l) { return si::volume<cubic_foot, long
|
||||
|
||||
} // namespace literals
|
||||
|
||||
} // namespace units::us
|
||||
} // namespace units::international
|
@ -30,7 +30,7 @@
|
||||
|
||||
namespace units::si {
|
||||
|
||||
struct ohm : named_unit<ohm, "R", prefix> {};
|
||||
struct ohm : named_unit<ohm, "Ω", prefix> {};
|
||||
struct milliohm : prefixed_unit<milliohm, milli, ohm> {};
|
||||
struct kiloohm : prefixed_unit<kiloohm, kilo, ohm> {};
|
||||
struct megaohm : prefixed_unit<megaohm, mega, ohm> {};
|
||||
@ -43,7 +43,7 @@ using resistance = quantity<dim_resistance, U, Rep>;
|
||||
inline namespace literals {
|
||||
|
||||
//R
|
||||
constexpr auto operator""R(unsigned long long l) { return resistance<ohm, std::int64_t>(l); }
|
||||
constexpr auto operator""_R(unsigned long long l) { return resistance<ohm, std::int64_t>(l); }
|
||||
constexpr auto operator""_R(long double l) { return resistance<ohm, long double>(l); }
|
||||
|
||||
//mR
|
||||
|
@ -26,7 +26,6 @@
|
||||
|
||||
namespace units::us {
|
||||
|
||||
#if 1
|
||||
//https://en.wikipedia.org/wiki/Foot_(unit)#US_survey_foot
|
||||
//https://www.nist.gov/pml/special-publication-811/nist-guide-si-appendix-b-conversion-factors#B6
|
||||
//struct foot : named_scaled_unit<foot,"ft(us)",no_prefix,ratio<3'048,1'000,-1>, si::metre> {};
|
||||
@ -39,7 +38,7 @@ struct fathom : named_scaled_unit<fathom,"fathom(us)",no_prefix,ratio<6,1>,us::f
|
||||
|
||||
//https://en.wikipedia.org/wiki/Mile#U.S._survey_mile
|
||||
//https://www.nist.gov/pml/special-publication-811/nist-guide-si-appendix-b-conversion-factors#B6
|
||||
struct mile : named_scaled_unit<mile,"mile(us)",no_prefix,ratio<5280,1000,3>,us::foot> {};
|
||||
struct mile : named_scaled_unit<mile,"mi(us)",no_prefix,ratio<5280,1000,3>,us::foot> {};
|
||||
|
||||
inline namespace literals {
|
||||
|
||||
@ -56,5 +55,5 @@ constexpr auto operator"" mi_us(unsigned long long l) { return si::length<units:
|
||||
constexpr auto operator"" mi_us(long double l) { return si::length<units::us::mile, long double>(l); }
|
||||
|
||||
} // namespace literals
|
||||
#endif
|
||||
|
||||
} // namespace units::us
|
||||
|
@ -26,14 +26,26 @@
|
||||
#include "units/physical/si/velocity.h"
|
||||
#include "units/physical/si/volume.h"
|
||||
#include "units/physical/si/surface_tension.h"
|
||||
#include "units/physical/us/area.h"
|
||||
#include "units/physical/us/velocity.h"
|
||||
#include "units/physical/us/volume.h"
|
||||
#include "units/physical/us/length.h"
|
||||
#include "units/physical/imperial/length.h"
|
||||
#include "units/physical/international/length.h"
|
||||
#include "units/physical/international/area.h"
|
||||
#include "units/physical/international/volume.h"
|
||||
#include "units/physical/international/velocity.h"
|
||||
#include "units/physical/iau/length.h"
|
||||
#include "units/physical/typographic/length.h"
|
||||
#include "units/physical/si/density.h"
|
||||
#include "units/physical/si/resistance.h"
|
||||
#include "units/physical/si/voltage.h"
|
||||
#include "units/format.h"
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
using namespace units::si;
|
||||
using namespace units::international;
|
||||
using namespace units::us;
|
||||
using namespace units::iau;
|
||||
using namespace units::imperial;
|
||||
using namespace units::typographic;
|
||||
|
||||
TEST_CASE("fmt::format on synthesized unit symbols", "[text][fmt]")
|
||||
{
|
||||
@ -49,6 +61,27 @@ TEST_CASE("fmt::format on synthesized unit symbols", "[text][fmt]")
|
||||
CHECK(fmt::format("{}", 1mm) == "1 mm");
|
||||
CHECK(fmt::format("{}", 1cm) == "1 cm");
|
||||
CHECK(fmt::format("{}", 1km) == "1 km");
|
||||
CHECK(fmt::format("{}", 1ft) == "1 ft");
|
||||
CHECK(fmt::format("{}", 1ft_us) == "1 ft(us)");
|
||||
CHECK(fmt::format("{}", 1yd) == "1 yd");
|
||||
CHECK(fmt::format("{}", 1in) == "1 in");
|
||||
CHECK(fmt::format("{}", 1fathom) == "1 fathom");
|
||||
CHECK(fmt::format("{}", 1fathom_us) == "1 fathom(us)");
|
||||
CHECK(fmt::format("{}", 1mi) == "1 mi");
|
||||
CHECK(fmt::format("{}", 1mi_us) == "1 mi(us)");
|
||||
CHECK(fmt::format("{}", 1naut_mi) == "1 mi(naut)");
|
||||
CHECK(fmt::format("{}", 1ch) == "1 ch");
|
||||
CHECK(fmt::format("{}", 1rd) == "1 rd");
|
||||
CHECK(fmt::format("{}", 1mil) == "1 mil");
|
||||
CHECK(fmt::format("{}", 1pc) == "1 pc");
|
||||
CHECK(fmt::format("{}", 1ly) == "1 ly");
|
||||
CHECK(fmt::format("{}", 1pc) == "1 pc");
|
||||
CHECK(fmt::format("{}", 1angstrom) == "1 angstrom");
|
||||
CHECK(fmt::format("{}", 1au) == "1 au");
|
||||
CHECK(fmt::format("{}", 1pica_comp) == "1 pica(comp)");
|
||||
CHECK(fmt::format("{}", 1pica_prn) == "1 pica(prn)");
|
||||
CHECK(fmt::format("{}", 1point_comp) == "1 point(comp)");
|
||||
CHECK(fmt::format("{}", 1point_prn) == "1 point(prn)");
|
||||
}
|
||||
|
||||
SECTION("mass")
|
||||
@ -65,6 +98,28 @@ TEST_CASE("fmt::format on synthesized unit symbols", "[text][fmt]")
|
||||
CHECK(fmt::format("{}", 1ft2) == "1 ft²");
|
||||
}
|
||||
|
||||
SECTION("density")
|
||||
{
|
||||
CHECK(fmt::format("{}", 1kgpm3) == "1 kg/m³");
|
||||
}
|
||||
|
||||
SECTION("resistance")
|
||||
{
|
||||
CHECK(fmt::format("{}", 1_R) == "1 Ω");
|
||||
CHECK(fmt::format("{}", 1kR) == "1 kΩ");
|
||||
CHECK(fmt::format("{}", 1mR) == "1 mΩ");
|
||||
CHECK(fmt::format("{}", 1MR) == "1 MΩ");
|
||||
}
|
||||
|
||||
SECTION("voltage")
|
||||
{
|
||||
CHECK(fmt::format("{}", 1V) == "1 V");
|
||||
CHECK(fmt::format("{}", 1mV) == "1 mV");
|
||||
CHECK(fmt::format("{}", 1uV) == "1 µV");
|
||||
CHECK(fmt::format("{}", 1nV) == "1 nV");
|
||||
CHECK(fmt::format("{}", 1pV) == "1 pV");
|
||||
}
|
||||
|
||||
SECTION("volume")
|
||||
{
|
||||
CHECK(fmt::format("{}", 1m3) == "1 m³");
|
||||
|
@ -25,10 +25,10 @@
|
||||
#include <units/physical/international/length.h>
|
||||
#include <units/physical/si/velocity.h>
|
||||
#include <units/physical/si/volume.h>
|
||||
#include <units/physical/us/area.h>
|
||||
#include <units/physical/international/area.h>
|
||||
#include <units/physical/us/length.h>
|
||||
#include <units/physical/us/velocity.h>
|
||||
#include <units/physical/us/volume.h>
|
||||
#include <units/physical/international/velocity.h>
|
||||
#include <units/physical/international/volume.h>
|
||||
#include <utility>
|
||||
|
||||
namespace {
|
||||
|
Reference in New Issue
Block a user