Downcasting reworked to allow OFF and AUTO modes
This commit is contained in:
1 parent
12c0177633
commit
5c98924efb
24 files changed
+386
-216
No files matched your search
@@ -50,6 +50,8 @@ static_assert(centimetre::symbol == "cm");
|
||||
|
||||
// speed
|
||||
|
||||
static_assert((10q_cm / 5q_s).count() == 2);
|
||||
static_assert((2q_cm_per_s).count() == 2);
|
||||
static_assert(10q_cm / 5q_s == 2q_cm_per_s);
|
||||
static_assert(10q_cm / 2q_cm_per_s == 5q_s);
|
||||
static_assert(10q_cm == 2q_cm_per_s * 5q_s);
|
||||
@@ -59,7 +61,11 @@ static_assert(detail::unit_text<dim_speed, centimetre_per_second>() == "cm/s");
|
||||
// area
|
||||
static_assert(centimetre::ratio / dimension_unit<dim_length>::ratio == ratio(1));
|
||||
|
||||
static_assert((1q_cm * 1q_cm).count() == 1);
|
||||
static_assert((1q_cm2).count() == 1);
|
||||
static_assert(1q_cm * 1q_cm == 1q_cm2);
|
||||
static_assert(100q_cm * 100q_cm == area<physical::si::square_metre>(1));
|
||||
static_assert(100q_cm * 100q_cm == length<physical::si::metre>(1) * length<physical::si::metre>(1));
|
||||
static_assert(100q_cm2 / 10q_cm == 10q_cm);
|
||||
|
||||
static_assert(detail::unit_text<dim_area, square_centimetre>() == basic_symbol_text("cm²", "cm^2"));
|
||||
|
||||
@@ -49,11 +49,14 @@ using amplitude_spectral_density = quantity<dim_amplitude_spectral_density, U, R
|
||||
|
||||
namespace {
|
||||
|
||||
static_assert(is_same_v<dimension_sqrt<dim_power_spectral_density>, dim_amplitude_spectral_density>);
|
||||
static_assert(is_same_v<dimension_pow<dim_amplitude_spectral_density, 2>, dim_power_spectral_density>);
|
||||
template<typename T, typename U>
|
||||
inline constexpr bool compare = DOWNCAST_MODE != 0 ? is_same_v<T, U> : (is_same_v<T, U> || units::equivalent<T, U>);
|
||||
|
||||
static_assert(is_same_v<decltype(pow<2>(amplitude_spectral_density<volt_per_sqrt_hertz>(4))), decltype(power_spectral_density<sq_volt_per_hertz>(16))>);
|
||||
static_assert(is_same_v<decltype(sqrt(power_spectral_density<sq_volt_per_hertz>(16))), decltype(amplitude_spectral_density<volt_per_sqrt_hertz>(4))>);
|
||||
static_assert(compare<dimension_sqrt<dim_power_spectral_density>, dim_amplitude_spectral_density>);
|
||||
static_assert(compare<dimension_pow<dim_amplitude_spectral_density, 2>, dim_power_spectral_density>);
|
||||
|
||||
static_assert(compare<decltype(pow<2>(amplitude_spectral_density<volt_per_sqrt_hertz>(4))), decltype(power_spectral_density<sq_volt_per_hertz>(16))>);
|
||||
static_assert(compare<decltype(sqrt(power_spectral_density<sq_volt_per_hertz>(16))), decltype(amplitude_spectral_density<volt_per_sqrt_hertz>(4))>);
|
||||
|
||||
}
|
||||
|
||||
@@ -63,6 +66,5 @@ struct kilogram_per_second : unit<kilogram_per_second> {};
|
||||
struct dim_mass_rate : derived_dimension<dim_mass_rate, kilogram_per_second, units::exp<dim_mass, 1>, units::exp<dim_time, -1>> {};
|
||||
struct kilogram_per_hour : deduced_unit<kilogram_per_hour, dim_mass_rate, kilogram, hour> {};
|
||||
constexpr auto a = 1q_kg / 1q_h;
|
||||
static_assert(is_same_v<decltype(a)::unit, kilogram_per_hour>);
|
||||
|
||||
}
|
||||
@@ -20,6 +20,8 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#include "units/math.h"
|
||||
#include "units/physical/international/area.h"
|
||||
#include "units/physical/si/area.h"
|
||||
#include "units/physical/si/speed.h"
|
||||
#include "units/physical/international/area.h"
|
||||
@@ -27,18 +29,20 @@
|
||||
|
||||
namespace {
|
||||
|
||||
using namespace units;
|
||||
using namespace units::physical::si::literals;
|
||||
using namespace units::physical::international::literals;
|
||||
using namespace units;
|
||||
using namespace units::physical::si::literals;
|
||||
using namespace units::physical::international::literals;
|
||||
|
||||
static_assert(is_same_v<decltype(pow<0>(2q_m)), std::int64_t>);
|
||||
static_assert(is_same_v<decltype(pow<1>(2q_m)), decltype(2q_m)>);
|
||||
static_assert(is_same_v<decltype(pow<2>(2q_m)), decltype(4q_m2)>);
|
||||
static_assert(is_same_v<decltype(pow<2>(2q_km)), decltype(4q_km2)>);
|
||||
static_assert(is_same_v<decltype(pow<2>(2q_ft)), decltype(4q_ft2)>);
|
||||
static_assert(is_same_v<decltype(sqrt(4q_m2)), decltype(2q_m)>);
|
||||
static_assert(is_same_v<decltype(sqrt(4q_km2)), decltype(2q_km)>);
|
||||
static_assert(is_same_v<decltype(sqrt(4q_ft2)), decltype(2q_ft)>);
|
||||
template<typename T, typename U>
|
||||
inline constexpr bool compare = DOWNCAST_MODE != 0 ? is_same_v<T, U> : (is_same_v<T, U> || units::equivalent<T, U>);
|
||||
|
||||
static_assert(compare<decltype(pow<0>(2q_m)), std::int64_t>);
|
||||
static_assert(compare<decltype(pow<1>(2q_m)), decltype(2q_m)>);
|
||||
static_assert(compare<decltype(pow<2>(2q_m)), decltype(4q_m2)>);
|
||||
static_assert(compare<decltype(pow<2>(2q_km)), decltype(4q_km2)>);
|
||||
static_assert(compare<decltype(pow<2>(2q_ft)), decltype(4q_ft2)>);
|
||||
static_assert(compare<decltype(sqrt(4q_m2)), decltype(2q_m)>);
|
||||
static_assert(compare<decltype(sqrt(4q_km2)), decltype(2q_km)>);
|
||||
static_assert(compare<decltype(sqrt(4q_ft2)), decltype(2q_ft)>);
|
||||
|
||||
} // namespace
|
||||
@@ -35,6 +35,9 @@ namespace {
|
||||
using namespace units;
|
||||
using namespace units::physical::si;
|
||||
|
||||
template<typename T, typename U>
|
||||
inline constexpr bool compare = DOWNCAST_MODE != 0 ? std::is_same_v<T, U> : (std::is_same_v<T, U> || units::equivalent<T, U>);
|
||||
|
||||
// class invariants
|
||||
|
||||
template<typename DimLength>
|
||||
@@ -119,23 +122,23 @@ static_assert((quantity_point(2q_m) -= 1q_m).relative().count() == 1);
|
||||
|
||||
// non-member arithmetic operators
|
||||
|
||||
static_assert(is_same_v<decltype(quantity_point<dim_length, metre, int>() + length<metre, double>()),
|
||||
static_assert(compare<decltype(quantity_point<dim_length, metre, int>() + length<metre, double>()),
|
||||
quantity_point<dim_length, metre, double>>);
|
||||
static_assert(is_same_v<decltype(length<metre, int>() + quantity_point<dim_length, metre, double>()),
|
||||
static_assert(compare<decltype(length<metre, int>() + quantity_point<dim_length, metre, double>()),
|
||||
quantity_point<dim_length, metre, double>>);
|
||||
static_assert(is_same_v<decltype(quantity_point<dim_length, kilometre, int>() + length<metre, double>()),
|
||||
static_assert(compare<decltype(quantity_point<dim_length, kilometre, int>() + length<metre, double>()),
|
||||
quantity_point<dim_length, metre, double>>);
|
||||
static_assert(is_same_v<decltype(length<kilometre, int>() + quantity_point<dim_length, metre, double>()),
|
||||
static_assert(compare<decltype(length<kilometre, int>() + quantity_point<dim_length, metre, double>()),
|
||||
quantity_point<dim_length, metre, double>>);
|
||||
static_assert(is_same_v<decltype(quantity_point<dim_length, metre, double>() - length<metre, int>()),
|
||||
static_assert(compare<decltype(quantity_point<dim_length, metre, double>() - length<metre, int>()),
|
||||
quantity_point<dim_length, metre, double>>);
|
||||
static_assert(is_same_v<decltype(quantity_point<dim_length, kilometre, double>() - length<metre, int>()),
|
||||
static_assert(compare<decltype(quantity_point<dim_length, kilometre, double>() - length<metre, int>()),
|
||||
quantity_point<dim_length, metre, double>>);
|
||||
static_assert(
|
||||
is_same_v<decltype(quantity_point<dim_length, metre, double>() - quantity_point<dim_length, metre, int>()),
|
||||
compare<decltype(quantity_point<dim_length, metre, double>() - quantity_point<dim_length, metre, int>()),
|
||||
length<metre, double>>);
|
||||
static_assert(
|
||||
is_same_v<decltype(quantity_point<dim_length, kilometre, double>() - quantity_point<dim_length, metre, int>()),
|
||||
compare<decltype(quantity_point<dim_length, kilometre, double>() - quantity_point<dim_length, metre, int>()),
|
||||
length<metre, double>>);
|
||||
|
||||
static_assert((1q_m + km).relative().count() == 1001);
|
||||
@@ -187,13 +190,13 @@ static_assert(QuantityPoint<quantity_point<dim_length, millimetre, int>>);
|
||||
|
||||
// common_quantity_point
|
||||
|
||||
static_assert(is_same_v<
|
||||
static_assert(compare<
|
||||
common_quantity_point<quantity_point<dim_length, metre, int>, quantity_point<dim_length, kilometre, int>>,
|
||||
quantity_point<dim_length, metre, int>>);
|
||||
static_assert(is_same_v<common_quantity_point<quantity_point<dim_length, kilometre, long long>,
|
||||
static_assert(compare<common_quantity_point<quantity_point<dim_length, kilometre, long long>,
|
||||
quantity_point<dim_length, metre, int>>,
|
||||
quantity_point<dim_length, metre, long long>>);
|
||||
static_assert(is_same_v<common_quantity_point<quantity_point<dim_length, kilometre, long long>,
|
||||
static_assert(compare<common_quantity_point<quantity_point<dim_length, kilometre, long long>,
|
||||
quantity_point<dim_length, millimetre, double>>,
|
||||
quantity_point<dim_length, millimetre, double>>);
|
||||
|
||||
@@ -209,7 +212,7 @@ static_assert(std::equality_comparable_with<decltype(quantity_point(1q_m)), decl
|
||||
// quantity_cast
|
||||
|
||||
static_assert(
|
||||
is_same_v<decltype(quantity_point_cast<scaled_unit<ratio(1), metre>>(quantity_point(2q_km)))::unit, metre>);
|
||||
compare<decltype(quantity_point_cast<scaled_unit<ratio(1), metre>>(quantity_point(2q_km)))::unit, metre>);
|
||||
|
||||
static_assert(quantity_point_cast<quantity_point<dim_length, metre, int>>(quantity_point(2q_km)).relative().count() ==
|
||||
2000);
|
||||
|
||||
@@ -34,6 +34,9 @@ namespace {
|
||||
using namespace units;
|
||||
using namespace units::physical::si;
|
||||
|
||||
template<typename T, typename U>
|
||||
inline constexpr bool compare = DOWNCAST_MODE != 0 ? std::is_same_v<T, U> : (std::is_same_v<T, U> || units::equivalent<T, U>);
|
||||
|
||||
// class invariants
|
||||
|
||||
// constexpr quantity<si::dim_length, second, int> error(0); // should not compile (unit of a different dimension)
|
||||
@@ -67,7 +70,7 @@ static_assert(length<metre, double>(1000.0q_m).count() == 1000.0);
|
||||
static_assert(length<metre, double>(km).count() == 1000.0);
|
||||
static_assert(length<metre, int>(1q_km).count() == 1000);
|
||||
// static_assert(length<metre, int>(1q_s).count() == 1); // should not compile (different dimensions)
|
||||
//static_assert(length<kilometre, int>(1010q_m).count() == 1); // should not compile (truncating conversion)
|
||||
// static_assert(length<kilometre, int>(1010q_m).count() == 1); // should not compile (truncating conversion)
|
||||
|
||||
// assignment operator
|
||||
|
||||
@@ -134,37 +137,34 @@ static_assert((2.5q_m *= 3.5).count() == 8.75);
|
||||
|
||||
// non-member arithmetic operators
|
||||
|
||||
static_assert(is_same_v<decltype(length<metre, int>() + length<metre, double>()), length<metre, double>>);
|
||||
static_assert(is_same_v<decltype(length<metre, int>() + length<metre, double>()), length<metre, double>>);
|
||||
static_assert(compare<decltype(length<metre, int>() + length<metre, double>()), length<metre, double>>);
|
||||
static_assert(compare<decltype(length<metre, int>() + length<metre, double>()), length<metre, double>>);
|
||||
static_assert(compare<decltype(length<kilometre, int>() + length<metre, double>()), length<metre, double>>);
|
||||
static_assert(compare<decltype(length<metre, double>() - length<metre, int>()), length<metre, double>>);
|
||||
static_assert(compare<decltype(length<kilometre, double>() - length<metre, int>()), length<metre, double>>);
|
||||
static_assert(compare<decltype(length<metre, int>() * 1.0), length<metre, double>>);
|
||||
static_assert(compare<decltype(1.0 * length<metre, int>()), length<metre, double>>);
|
||||
static_assert(
|
||||
is_same_v<decltype(length<kilometre, int>() + length<metre, double>()), length<metre, double>>);
|
||||
static_assert(is_same_v<decltype(length<metre, double>() - length<metre, int>()), length<metre, double>>);
|
||||
compare<decltype(speed<metre_per_second, int>() * physical::si::time<second, int>()), length<metre, int>>);
|
||||
static_assert(
|
||||
is_same_v<decltype(length<kilometre, double>() - length<metre, int>()), length<metre, double>>);
|
||||
static_assert(is_same_v<decltype(length<metre, int>() * 1.0), length<metre, double>>);
|
||||
static_assert(is_same_v<decltype(1.0 * length<metre, int>()), length<metre, double>>);
|
||||
static_assert(
|
||||
is_same_v<decltype(speed<metre_per_second, int>() * physical::si::time<second, int>()), length<metre, int>>);
|
||||
static_assert(
|
||||
is_same_v<decltype(speed<metre_per_second, int>() * physical::si::time<hour, int>()), length<scaled_unit<ratio(36, 1, 2), metre>, int>>);
|
||||
static_assert(is_same_v<decltype(length<metre>() * physical::si::time<minute>()),
|
||||
compare<decltype(speed<metre_per_second, int>() * physical::si::time<hour, int>()), length<scaled_unit<ratio(36, 1, 2), metre>, int>>);
|
||||
static_assert(compare<decltype(length<metre>() * physical::si::time<minute>()),
|
||||
quantity<unknown_dimension<units::exp<dim_length, 1>, units::exp<dim_time, 1>>, scaled_unit<ratio(6, 1, 1), unknown_coherent_unit>>>);
|
||||
static_assert(is_same_v<decltype(1 / physical::si::time<second, int>()), frequency<hertz, int>>);
|
||||
static_assert(is_same_v<decltype(1 / physical::si::time<minute, int>()), frequency<scaled_unit<ratio(1, 6, -1), hertz>, int>>);
|
||||
static_assert(is_same_v<decltype(1 / frequency<hertz, int>()), physical::si::time<second, int>>);
|
||||
static_assert(is_same_v<decltype(1 / length<kilometre>()),
|
||||
static_assert(compare<decltype(1 / physical::si::time<second, int>()), frequency<hertz, int>>);
|
||||
static_assert(compare<decltype(1 / physical::si::time<minute, int>()), frequency<scaled_unit<ratio(1, 6, -1), hertz>, int>>);
|
||||
static_assert(compare<decltype(1 / frequency<hertz, int>()), physical::si::time<second, int>>);
|
||||
static_assert(compare<decltype(1 / length<kilometre>()),
|
||||
quantity<unknown_dimension<units::exp<dim_length, -1>>, scaled_unit<ratio(1, 1, -3), unknown_coherent_unit>>>);
|
||||
static_assert(is_same_v<decltype(length<metre, int>() / 1.0), length<metre, double>>);
|
||||
static_assert(is_same_v<decltype(length<metre, int>() / length<metre, double>()), double>);
|
||||
static_assert(is_same_v<decltype(length<kilometre, int>() / length<metre, double>()), double>);
|
||||
static_assert(std::is_same_v<decltype(length<metre, int>() / 1.0), length<metre, double>>);
|
||||
static_assert(std::is_same_v<decltype(length<metre, int>() / length<metre, double>()), double>);
|
||||
static_assert(std::is_same_v<decltype(length<kilometre, int>() / length<metre, double>()), double>);
|
||||
static_assert(compare<decltype(length<metre, int>() / physical::si::time<second, int>()), speed<metre_per_second, int>>);
|
||||
static_assert(
|
||||
is_same_v<decltype(length<metre, int>() / physical::si::time<second, int>()), speed<metre_per_second, int>>);
|
||||
static_assert(
|
||||
is_same_v<decltype(length<metre>() / physical::si::time<minute>()), speed<scaled_unit<ratio(1, 6, -1), metre_per_second>>>);
|
||||
static_assert(is_same_v<decltype(physical::si::time<minute>() / length<metre>()),
|
||||
quantity<unknown_dimension<units::exp<dim_length, -1>, units::exp<dim_time, 1>>, scaled_unit<ratio(6 ,1 , 1), unknown_coherent_unit>>>);
|
||||
static_assert(is_same_v<decltype(length<metre, int>() % short(1)), length<metre, int>>);
|
||||
static_assert(is_same_v<decltype(length<metre, int>() % length<metre, short>(1)), length<metre, int>>);
|
||||
compare<decltype(length<metre>() / physical::si::time<minute>()), speed<scaled_unit<ratio(1, 6, -1), metre_per_second>>>);
|
||||
static_assert(compare<decltype(physical::si::time<minute>() / length<metre>()),
|
||||
quantity<unknown_dimension<units::exp<dim_length, -1>, units::exp<dim_time, 1>>, scaled_unit<ratio(6, 1, 1), unknown_coherent_unit>>>);
|
||||
static_assert(std::is_same_v<decltype(length<metre, int>() % short(1)), length<metre, int>>);
|
||||
static_assert(std::is_same_v<decltype(length<metre, int>() % length<metre, short>(1)), length<metre, int>>);
|
||||
|
||||
static_assert((1q_m + km).count() == 1001);
|
||||
static_assert((1q_m + 1q_km).count() == 1001);
|
||||
@@ -225,11 +225,10 @@ static_assert(Quantity<length<millimetre, int>>);
|
||||
|
||||
// common_quantity
|
||||
|
||||
static_assert(is_same_v<common_quantity<length<metre, int>, length<kilometre, int>>, length<metre, int>>);
|
||||
static_assert(compare<common_quantity<length<metre, int>, length<kilometre, int>>, length<metre, int>>);
|
||||
static_assert(compare<common_quantity<length<kilometre, long long>, length<metre, int>>, length<metre, long long>>);
|
||||
static_assert(
|
||||
is_same_v<common_quantity<length<kilometre, long long>, length<metre, int>>, length<metre, long long>>);
|
||||
static_assert(is_same_v<common_quantity<length<kilometre, long long>, length<millimetre, double>>,
|
||||
length<millimetre, double>>);
|
||||
compare<common_quantity<length<kilometre, long long>, length<millimetre, double>>, length<millimetre, double>>);
|
||||
|
||||
// common_type
|
||||
|
||||
@@ -242,7 +241,7 @@ static_assert(std::equality_comparable_with<decltype(1q_m), decltype(1q_ft_us)>)
|
||||
|
||||
// quantity_cast
|
||||
|
||||
static_assert(is_same_v<decltype(quantity_cast<scaled_unit<ratio(1), metre>>(2q_km))::unit, metre>);
|
||||
static_assert(compare<decltype(quantity_cast<scaled_unit<ratio(1), metre>>(2q_km))::unit, metre>);
|
||||
|
||||
static_assert(quantity_cast<length<metre, int>>(2q_km).count() == 2000);
|
||||
static_assert(quantity_cast<length<kilometre, int>>(2000q_m).count() == 2);
|
||||
@@ -271,6 +270,20 @@ static_assert(1q_km / 1q_s == 1000q_m_per_s);
|
||||
static_assert(2q_km_per_h * 2q_h == 4q_km);
|
||||
static_assert(2q_km / 2q_km_per_h == 1q_h);
|
||||
|
||||
static_assert(is_same_v<decltype(pow<2>(2q_m)), decltype(4q_m2)>);
|
||||
static_assert(compare<decltype(pow<2>(2q_m)), decltype(4q_m2)>);
|
||||
|
||||
// downcasting
|
||||
|
||||
#if DOWNCAST_MODE == 0
|
||||
|
||||
static_assert(std::is_same_v<decltype(10q_m / 5q_s), quantity<unknown_dimension<units::exp<dim_length, 1>, units::exp<dim_time, -1>>, scaled_unit<ratio(1), unknown_coherent_unit>, std::int64_t>>);
|
||||
static_assert(std::is_same_v<decltype(1q_mm + 1q_km), length<scaled_unit<ratio(1, 1, -3), metre>, std::int64_t>>);
|
||||
|
||||
#else
|
||||
|
||||
static_assert(std::is_same_v<decltype(10q_m / 5q_s), speed<metre_per_second, std::int64_t>>);
|
||||
static_assert(std::is_same_v<decltype(1q_mm + 1q_km), length<millimetre, std::int64_t>>);
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace
|
||||
@@ -46,6 +46,13 @@ namespace {
|
||||
|
||||
using namespace units::physical;
|
||||
|
||||
static_assert(units::detail::quantity_ratio(si::length<si::metre>(1)) == units::ratio(1));
|
||||
static_assert(units::detail::quantity_ratio(cgs::length<cgs::centimetre>(1)) == units::ratio(1, 100));
|
||||
static_assert(units::detail::quantity_ratio(si::speed<si::metre_per_second>(1)) == units::ratio(1));
|
||||
static_assert(units::detail::quantity_ratio(cgs::speed<cgs::centimetre_per_second>(1)) == units::ratio(1, 100));
|
||||
static_assert(units::detail::quantity_ratio(si::force<si::newton>(1)) == units::ratio(1000)); // defined in terms of kilogram that are 1000 * gram
|
||||
static_assert(units::detail::quantity_ratio(cgs::force<cgs::dyne>(1)) == units::ratio(1, 100)); // defined in terms of gram so only centimetre ratio counts here
|
||||
|
||||
static_assert(cgs::length<cgs::centimetre>(100) == si::length<si::metre>(1));
|
||||
static_assert(cgs::mass<cgs::gram>(1'000) == si::mass<si::kilogram>(1));
|
||||
static_assert(cgs::time<cgs::second>(1) == si::time<si::second>(1));
|
||||
|
||||
@@ -52,14 +52,14 @@ static_assert(fps::time<fps::second>(1) == si::time<si::second>(1));
|
||||
static_assert(fps::speed<fps::foot_per_second>(1) == si::speed<si::metre_per_second>(0.3048));
|
||||
static_assert(fps::area<fps::square_foot>(1) == si::area<si::square_metre>(0.09290304));
|
||||
static_assert(fps::acceleration<fps::foot_per_second_sq>(1) == si::acceleration<si::metre_per_second_sq>(0.3048));
|
||||
static_assert(fps::force<fps::poundal>(1) >= si::force<si::newton>(0.138254) &&
|
||||
fps::force<fps::poundal>(1) <= si::force<si::newton>(0.138256));
|
||||
static_assert(fps::energy<fps::foot_poundal>(1) >= si::energy<si::joule>(0.042140110093804) &&
|
||||
fps::energy<fps::foot_poundal>(1) <= si::energy<si::joule>(0.042140110093806));
|
||||
static_assert(fps::power<fps::foot_poundal_per_second>(1) >= si::power<si::watt>(0.042140110093804) &&
|
||||
fps::power<fps::foot_poundal_per_second>(1) <= si::power<si::watt>(0.042140110093806));
|
||||
static_assert(fps::pressure<fps::poundal_per_foot_sq>(1) >= si::pressure<si::pascal>(1.4881639435) &&
|
||||
fps::pressure<fps::poundal_per_foot_sq>(1) <= si::pressure<si::pascal>(1.4881639437));
|
||||
static_assert(fps::force<fps::poundal>(1) > si::force<si::newton>(0.138254) &&
|
||||
fps::force<fps::poundal>(1) < si::force<si::newton>(0.138256));
|
||||
static_assert(fps::energy<fps::foot_poundal>(1) > si::energy<si::joule>(0.042140110093804) &&
|
||||
fps::energy<fps::foot_poundal>(1) < si::energy<si::joule>(0.042140110093806));
|
||||
static_assert(fps::power<fps::foot_poundal_per_second>(1) > si::power<si::watt>(0.042140110093804) &&
|
||||
fps::power<fps::foot_poundal_per_second>(1) < si::power<si::watt>(0.042140110093806));
|
||||
static_assert(fps::pressure<fps::poundal_per_foot_sq>(1) > si::pressure<si::pascal>(1.4881639435) &&
|
||||
fps::pressure<fps::poundal_per_foot_sq>(1) < si::pressure<si::pascal>(1.4881639437));
|
||||
|
||||
namespace si_literals {
|
||||
|
||||
@@ -69,16 +69,17 @@ static_assert(fps::length<fps::foot>(1) == 0.3048q_m);
|
||||
static_assert(fps::mass<fps::pound>(1) == 0.45359237q_kg);
|
||||
static_assert(fps::time<fps::second>(1) == 1q_s);
|
||||
static_assert(fps::speed<fps::foot_per_second>(1) == 0.3048q_m_per_s);
|
||||
static_assert(fps::area<fps::square_foot>(1) == 0.09290304q_m2);
|
||||
static_assert(fps::area<fps::square_foot>(1) > 0.09290303q_m2 &&
|
||||
fps::area<fps::square_foot>(1) < 0.09290305q_m2);
|
||||
static_assert(fps::acceleration<fps::foot_per_second_sq>(1) == 0.3048q_m_per_s2);
|
||||
static_assert(fps::force<fps::poundal>(1) >= 0.138254q_N &&
|
||||
fps::force<fps::poundal>(1) <= 0.138256q_N);
|
||||
static_assert(fps::energy<fps::foot_poundal>(1) >= 0.042140110093804q_J &&
|
||||
fps::energy<fps::foot_poundal>(1) <= 0.042140110093806q_J);
|
||||
static_assert(fps::power<fps::foot_poundal_per_second>(1) >= 0.042140110093804q_W &&
|
||||
fps::power<fps::foot_poundal_per_second>(1) <= 0.042140110093806q_W);
|
||||
static_assert(fps::pressure<fps::poundal_per_foot_sq>(1) >= 1.4881639435q_Pa &&
|
||||
fps::pressure<fps::poundal_per_foot_sq>(1) <= 1.4881639437q_Pa);
|
||||
static_assert(fps::force<fps::poundal>(1) > 0.138254q_N &&
|
||||
fps::force<fps::poundal>(1) < 0.138256q_N);
|
||||
static_assert(fps::energy<fps::foot_poundal>(1) > 0.042140110093804q_J &&
|
||||
fps::energy<fps::foot_poundal>(1) < 0.042140110093806q_J);
|
||||
static_assert(fps::power<fps::foot_poundal_per_second>(1) > 0.042140110093804q_W &&
|
||||
fps::power<fps::foot_poundal_per_second>(1) < 0.042140110093806q_W);
|
||||
static_assert(fps::pressure<fps::poundal_per_foot_sq>(1) > 1.4881639435q_Pa &&
|
||||
fps::pressure<fps::poundal_per_foot_sq>(1) < 1.4881639437q_Pa);
|
||||
}
|
||||
|
||||
namespace fps_literals {
|
||||
@@ -91,14 +92,14 @@ static_assert(1q_s == si::time<si::second>(1));
|
||||
static_assert(1q_ft_per_s == si::speed<si::metre_per_second>(0.3048));
|
||||
static_assert(1q_ft2 == si::area<si::square_metre>(0.09290304));
|
||||
static_assert(1q_ft_per_s2 == si::acceleration<si::metre_per_second_sq>(0.3048));
|
||||
static_assert(1q_pdl >= si::force<si::newton>(0.138254) &&
|
||||
1q_pdl <= si::force<si::newton>(0.138256));
|
||||
static_assert(1q_ft_pdl >= si::energy<si::joule>(0.042140110093804) &&
|
||||
1q_ft_pdl <= si::energy<si::joule>(0.042140110093806));
|
||||
static_assert(1q_ft_pdl_per_s >= si::power<si::watt>(0.042140110093804) &&
|
||||
1q_ft_pdl_per_s <= si::power<si::watt>(0.042140110093806));
|
||||
static_assert(1q_pdl_per_ft2>= si::pressure<si::pascal>(1.4881639435) &&
|
||||
1q_pdl_per_ft2 <= si::pressure<si::pascal>(1.4881639437));
|
||||
static_assert(1q_pdl > si::force<si::newton>(0.138254) &&
|
||||
1q_pdl < si::force<si::newton>(0.138256));
|
||||
static_assert(1q_ft_pdl > si::energy<si::joule>(0.042140110093804) &&
|
||||
1q_ft_pdl < si::energy<si::joule>(0.042140110093806));
|
||||
static_assert(1q_ft_pdl_per_s > si::power<si::watt>(0.042140110093804) &&
|
||||
1q_ft_pdl_per_s < si::power<si::watt>(0.042140110093806));
|
||||
static_assert(1q_pdl_per_ft2> si::pressure<si::pascal>(1.4881639435) &&
|
||||
1q_pdl_per_ft2 < si::pressure<si::pascal>(1.4881639437));
|
||||
}
|
||||
|
||||
namespace fps_plus_si_literals {
|
||||
@@ -112,16 +113,17 @@ static_assert(1q_ft == 0.3048q_m);
|
||||
static_assert(1q_lb == 0.45359237q_kg);
|
||||
static_assert(1q_s == 1q_s);
|
||||
static_assert(1q_ft_per_s == 0.3048q_m_per_s);
|
||||
static_assert(1q_ft2 == 0.09290304q_m2);
|
||||
static_assert(1q_ft2 > 0.09290303q_m2 &&
|
||||
1q_ft2 < 0.09290305q_m2);
|
||||
static_assert(1q_ft_per_s2 == 0.3048q_m_per_s2);
|
||||
static_assert(1q_pdl >= 0.138254q_N &&
|
||||
1q_pdl <= 0.138256q_N);
|
||||
static_assert(1q_ft_pdl >= 0.042140110093804q_J &&
|
||||
1q_ft_pdl <= 0.042140110093806q_J);
|
||||
static_assert(1q_ft_pdl_per_s >= 0.042140110093804q_W &&
|
||||
1q_ft_pdl_per_s <= 0.042140110093806q_W);
|
||||
static_assert(1q_pdl_per_ft2>= 1.4881639435q_Pa &&
|
||||
1q_pdl_per_ft2 <=1.4881639437q_Pa);
|
||||
static_assert(1q_pdl > 0.138254q_N &&
|
||||
1q_pdl < 0.138256q_N);
|
||||
static_assert(1q_ft_pdl > 0.042140110093804q_J &&
|
||||
1q_ft_pdl < 0.042140110093806q_J);
|
||||
static_assert(1q_ft_pdl_per_s > 0.042140110093804q_W &&
|
||||
1q_ft_pdl_per_s < 0.042140110093806q_W);
|
||||
static_assert(1q_pdl_per_ft2 > 1.4881639435q_Pa &&
|
||||
1q_pdl_per_ft2 < 1.4881639437q_Pa);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -106,6 +106,7 @@ static_assert(10q_Hz * 1q_min == 600);
|
||||
static_assert(2 / 1q_Hz == 2q_s);
|
||||
|
||||
// force
|
||||
|
||||
static_assert(10q_kg * 10q_m_per_s2 == 100q_N);
|
||||
static_assert(100q_N / 1q_m_per_s2 == 100q_kg);
|
||||
static_assert(100q_N / 1q_kg == 100q_m_per_s2);
|
||||
@@ -237,8 +238,6 @@ static_assert(kilogray::symbol == "kGy");
|
||||
|
||||
// speed
|
||||
|
||||
static_assert(is_same_v<decltype(1q_km / 1q_s), speed<scaled_unit<ratio(1, 1, 3), metre_per_second>, std::int64_t>>);
|
||||
|
||||
static_assert(10q_m / 5q_s == 2q_m_per_s);
|
||||
static_assert(10 / 5q_s * 1q_m == 2q_m_per_s);
|
||||
static_assert(1q_km / 1q_s == 1000q_m_per_s);
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include "units/unit.h"
|
||||
#include "units/bits/equivalent.h"
|
||||
#include "units/physical/si/prefixes.h"
|
||||
|
||||
namespace {
|
||||
@@ -28,6 +29,9 @@ namespace {
|
||||
using namespace units;
|
||||
using namespace units::physical;
|
||||
|
||||
template<typename T, typename U>
|
||||
inline constexpr bool compare = DOWNCAST_MODE != 0 ? std::is_same_v<T, U> : (std::is_same_v<T, U> || units::equivalent<T, U>);
|
||||
|
||||
struct metre : named_unit<metre, "m", si::prefix> {};
|
||||
struct centimetre : prefixed_unit<centimetre, si::centi, metre> {};
|
||||
struct kilometre : prefixed_unit<kilometre, si::kilo, metre> {};
|
||||
@@ -46,11 +50,11 @@ struct metre_per_second : unit<metre_per_second> {};
|
||||
struct dim_speed : derived_dimension<dim_speed, metre_per_second, units::exp<dim_length, 1>, units::exp<dim_time, -1>> {};
|
||||
struct kilometre_per_hour : deduced_unit<kilometre_per_hour, dim_speed, kilometre, hour> {};
|
||||
|
||||
static_assert(is_same_v<downcast<scaled_unit<ratio(1), metre>>, metre>);
|
||||
static_assert(is_same_v<downcast<scaled_unit<ratio(1, 1, -2), metre>>, centimetre>);
|
||||
static_assert(is_same_v<downcast<scaled_unit<ratio(yard::ratio.num, yard::ratio.den, yard::ratio.exp), metre>>, yard>);
|
||||
static_assert(is_same_v<downcast<scaled_unit<yard::ratio * ratio(1, 3), metre>>, foot>);
|
||||
static_assert(is_same_v<downcast<scaled_unit<kilometre::ratio / hour::ratio, metre_per_second>>, kilometre_per_hour>);
|
||||
static_assert(compare<downcast<scaled_unit<ratio(1), metre>>, metre>);
|
||||
static_assert(compare<downcast<scaled_unit<ratio(1, 1, -2), metre>>, centimetre>);
|
||||
static_assert(compare<downcast<scaled_unit<ratio(yard::ratio.num, yard::ratio.den, yard::ratio.exp), metre>>, yard>);
|
||||
static_assert(compare<downcast<scaled_unit<yard::ratio * ratio(1, 3), metre>>, foot>);
|
||||
static_assert(compare<downcast<scaled_unit<kilometre::ratio / hour::ratio, metre_per_second>>, kilometre_per_hour>);
|
||||
|
||||
static_assert(centimetre::symbol == "cm");
|
||||
static_assert(kilometre::symbol == "km");
|
||||
|
||||
Reference in new issue
Block a user