mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-01 03:14:29 +02:00
CGS support added
This commit is contained in:
@@ -31,14 +31,18 @@ namespace units {
|
||||
/**
|
||||
* @brief A dimension of a base quantity
|
||||
*
|
||||
* Measurement unit that is adopted by convention for a base quantity (a quantity that can not be expressed in terms of
|
||||
* the other quantities within that subset) in a specific system of units.
|
||||
* Base quantity is a quantity in a conventionally chosen subset of a given system of quantities, where no quantity
|
||||
* in the subset can be expressed in terms of the other quantities within that subset. They are referred to as
|
||||
* being mutually independent since a base quantity cannot be expressed as a product of powers of the other base
|
||||
* quantities.
|
||||
*
|
||||
* Base unit is a measurement unit that is adopted by convention for a base quantity in a specific system of units.
|
||||
*
|
||||
* Pair of Name and Unit template parameter forms an unique identifier of the base dimension. The same identifiers can
|
||||
* be multiplied and divided which will result with an adjustment of its factor in an Exponent (in case of zero the
|
||||
* dimension will be simplified and removed from further analysis of current expresion). In case the Name is the same
|
||||
* but the Unit differs (i.e. mixing SI and CGS length), there is no automatic simplification but is possible to force
|
||||
* it with a quantity_cast.
|
||||
* be multiplied and divided which will result with an adjustment of its factor in an Exponent od a DerivedDimension
|
||||
* (in case of zero the dimension will be simplified and removed from further analysis of current expresion). In case
|
||||
* the Name is the same but the Unit differs (i.e. mixing SI and CGS length), there is no automatic simplification but
|
||||
* is possible to force it with a quantity_cast.
|
||||
*
|
||||
* @tparam Name an unique identifier of the base dimension used to provide dimensional analysis support
|
||||
* @tparam U a base unit to be used for this base dimension
|
||||
@@ -47,7 +51,7 @@ template<basic_fixed_string Name, Unit U>
|
||||
struct base_dimension {
|
||||
using base_type_workaround = base_dimension; // TODO Replace with is_derived_from_instantiation when fixed
|
||||
static constexpr auto name = Name;
|
||||
using coherent_unit = U;
|
||||
using base_unit = U;
|
||||
};
|
||||
|
||||
// BaseDimension
|
||||
|
@@ -77,7 +77,7 @@ struct derived_dimension<> : downcast_base<derived_dimension<>> {};
|
||||
* @tparam ERest zero or more following exponents of a derived dimension
|
||||
*/
|
||||
template<Exponent E, Exponent... ERest>
|
||||
struct derived_dimension<E, ERest...> : downcast_base<derived_dimension<E, ERest...>> {};
|
||||
struct derived_dimension<E, ERest...> : downcast_base<derived_dimension<E, ERest...>> {}; // TODO rename to 'dimension'?
|
||||
|
||||
// DerivedDimension
|
||||
template<typename T>
|
||||
@@ -220,6 +220,35 @@ struct extract<exp<derived_dimension<Es...>, Num, Den>, ERest...> {
|
||||
template<Exponent... Es>
|
||||
using make_dimension = dim_consolidate<type_list_sort<typename extract<Es...>::type, exp_less>>::type;
|
||||
|
||||
template<Exponent E>
|
||||
requires (E::den == 1 || E::den == 2) // TODO provide support for any den
|
||||
struct exp_ratio {
|
||||
using base_ratio = E::dimension::base_unit::ratio;
|
||||
using positive_ratio = conditional<E::num * E::den < 0, ratio<base_ratio::den, base_ratio::num>, base_ratio>;
|
||||
static constexpr std::int64_t N = E::num * E::den < 0 ? -E::num : E::num;
|
||||
using pow = ratio_pow<positive_ratio, N>;
|
||||
using type = conditional<E::den == 2, ratio_sqrt<pow>, pow>;
|
||||
};
|
||||
|
||||
template<DerivedDimension D>
|
||||
struct base_units_ratio_impl;
|
||||
|
||||
template<typename E, typename... Es>
|
||||
struct base_units_ratio_impl<derived_dimension<E, Es...>> {
|
||||
using type = ratio_multiply<typename exp_ratio<E>::type, typename base_units_ratio_impl<derived_dimension<Es...>>::type>;
|
||||
};
|
||||
|
||||
template<typename E>
|
||||
struct base_units_ratio_impl<derived_dimension<E>> {
|
||||
using type = exp_ratio<E>::type;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Calculates the common ratio of all the references of base units in the derived dimension
|
||||
*/
|
||||
template<DerivedDimension D>
|
||||
using base_units_ratio = base_units_ratio_impl<D>::type;
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/**
|
||||
@@ -247,16 +276,27 @@ template<typename Child, Unit U, Exponent E, Exponent... ERest>
|
||||
struct derived_dimension<Child, U, E, ERest...> : downcast_child<Child, typename detail::make_dimension<E, ERest...>> {
|
||||
using recipe = derived_dimension<E, ERest...>;
|
||||
using coherent_unit = U;
|
||||
using base_units_ratio = detail::base_units_ratio<typename downcast_child<Child, typename detail::make_dimension<E, ERest...>>::downcast_base_type>;
|
||||
};
|
||||
|
||||
// same_dim
|
||||
template<Dimension D1, Dimension D2>
|
||||
inline constexpr bool same_dim = false;
|
||||
namespace detail {
|
||||
|
||||
template<BaseDimension D1, BaseDimension D2>
|
||||
inline constexpr bool same_dim<D1, D2> = std::is_same_v<D1, D2>;
|
||||
template<Dimension D>
|
||||
struct dimension_unit_impl;
|
||||
|
||||
template<DerivedDimension D1, DerivedDimension D2>
|
||||
inline constexpr bool same_dim<D1, D2> = std::is_same_v<typename D1::downcast_base_type, typename D2::downcast_base_type>;
|
||||
template<BaseDimension D>
|
||||
struct dimension_unit_impl<D> {
|
||||
using type = D::base_unit;
|
||||
};
|
||||
|
||||
template<DerivedDimension D>
|
||||
struct dimension_unit_impl<D> {
|
||||
using type = D::coherent_unit;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
template<Dimension D>
|
||||
using dimension_unit = detail::dimension_unit_impl<D>::type;
|
||||
|
||||
} // namespace units
|
||||
|
@@ -27,6 +27,40 @@
|
||||
|
||||
namespace units {
|
||||
|
||||
// equivalent_dim
|
||||
namespace detail {
|
||||
|
||||
template<Dimension D1, Dimension D2>
|
||||
struct equivalent_dim_impl : std::false_type {};
|
||||
|
||||
template<BaseDimension D1, BaseDimension D2>
|
||||
struct equivalent_base_dim : std::conjunction<std::bool_constant<D1::name == D2::name>,
|
||||
same_unit_reference<typename D1::base_unit, typename D2::base_unit>> {};
|
||||
|
||||
template<BaseDimension D1, BaseDimension D2>
|
||||
struct equivalent_dim_impl<D1, D2> : std::disjunction<std::is_same<D1, D2>, equivalent_base_dim<D1, D2>> {};
|
||||
|
||||
template<Exponent E1, Exponent E2>
|
||||
struct equivalent_exp : std::false_type {};
|
||||
|
||||
template<BaseDimension Dim1, int Num, int Den, BaseDimension Dim2>
|
||||
struct equivalent_exp<exp<Dim1, Num, Den>, exp<Dim2, Num, Den>> : equivalent_dim_impl<Dim1, Dim2> {};
|
||||
|
||||
template<DerivedDimension D1, DerivedDimension D2>
|
||||
struct equivalent_derived_dim : std::false_type {};
|
||||
|
||||
template<typename... Es1, typename... Es2>
|
||||
requires (sizeof...(Es1) == sizeof...(Es2))
|
||||
struct equivalent_derived_dim<derived_dimension<Es1...>, derived_dimension<Es2...>> : std::conjunction<equivalent_exp<Es1, Es2>...> {};
|
||||
|
||||
template<DerivedDimension D1, DerivedDimension D2>
|
||||
struct equivalent_dim_impl<D1, D2> : std::disjunction<std::is_same<D1, D2>, equivalent_derived_dim<downcast_base_t<D1>, downcast_base_t<D2>>> {};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<Dimension D1, Dimension D2>
|
||||
inline constexpr bool equivalent_dim = detail::equivalent_dim_impl<D1, D2>::value;
|
||||
|
||||
/**
|
||||
* @brief Unknown dimension
|
||||
*
|
||||
@@ -43,21 +77,34 @@ struct unknown_dimension : derived_dimension<unknown_dimension<Es...>, scaled_un
|
||||
|
||||
namespace detail {
|
||||
|
||||
template<Dimension D>
|
||||
struct downcast_dimension_impl {
|
||||
template<DerivedDimension D>
|
||||
struct check_unknown {
|
||||
using type = D;
|
||||
};
|
||||
|
||||
// downcast did not find user predefined type
|
||||
// downcast did not find a user predefined type
|
||||
template<typename... Es>
|
||||
struct downcast_dimension_impl<derived_dimension<Es...>> {
|
||||
struct check_unknown<derived_dimension<Es...>> {
|
||||
using type = unknown_dimension<Es...>;
|
||||
};
|
||||
|
||||
template<Dimension D>
|
||||
struct downcast_dimension_impl;
|
||||
|
||||
template<BaseDimension D>
|
||||
struct downcast_dimension_impl<D> {
|
||||
using type = D;
|
||||
};
|
||||
|
||||
template<DerivedDimension D>
|
||||
struct downcast_dimension_impl<D> {
|
||||
using type = check_unknown<downcast<D>>::type;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<Dimension D>
|
||||
using downcast_dimension = detail::downcast_dimension_impl<downcast<D>>::type;
|
||||
using downcast_dimension = detail::downcast_dimension_impl<D>::type;
|
||||
|
||||
// dim_invert
|
||||
namespace detail {
|
||||
|
45
src/include/units/physical/cgs/acceleration.h
Normal file
45
src/include/units/physical/cgs/acceleration.h
Normal file
@@ -0,0 +1,45 @@
|
||||
// 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 <units/physical/dimensions.h>
|
||||
#include <units/physical/cgs/velocity.h>
|
||||
#include <units/quantity.h>
|
||||
|
||||
namespace units::cgs {
|
||||
|
||||
struct gal : named_unit<gal, "Gal", si::prefix> {};
|
||||
struct dim_acceleration : physical::dim_acceleration<dim_acceleration, gal, dim_length, dim_time> {};
|
||||
|
||||
template<Unit U, Scalar Rep = double>
|
||||
using acceleration = quantity<dim_acceleration, U, Rep>;
|
||||
|
||||
inline namespace literals {
|
||||
|
||||
// Gal
|
||||
constexpr auto operator""Gal(unsigned long long l) { return acceleration<gal, std::int64_t>(l); }
|
||||
constexpr auto operator""Gal(long double l) { return acceleration<gal, long double>(l); }
|
||||
|
||||
} // namespace literals
|
||||
|
||||
} // namespace units::cgs
|
39
src/include/units/physical/cgs/area.h
Normal file
39
src/include/units/physical/cgs/area.h
Normal file
@@ -0,0 +1,39 @@
|
||||
// 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 <units/physical/dimensions.h>
|
||||
#include <units/physical/cgs/length.h>
|
||||
#include <units/physical/si/area.h>
|
||||
#include <units/quantity.h>
|
||||
|
||||
namespace units::cgs {
|
||||
|
||||
using si::square_centimetre;
|
||||
|
||||
struct dim_area : physical::dim_area<dim_area, square_centimetre, dim_length> {};
|
||||
|
||||
template<Unit U, Scalar Rep = double>
|
||||
using area = quantity<dim_area, U, Rep>;
|
||||
|
||||
} // namespace units::cgs
|
47
src/include/units/physical/cgs/energy.h
Normal file
47
src/include/units/physical/cgs/energy.h
Normal file
@@ -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 <units/physical/dimensions.h>
|
||||
#include <units/physical/cgs/force.h>
|
||||
#include <units/physical/si/prefixes.h>
|
||||
#include <units/quantity.h>
|
||||
|
||||
namespace units::cgs {
|
||||
|
||||
struct erg : named_unit<erg, "erg", si::prefix> {};
|
||||
|
||||
struct dim_energy : physical::dim_energy<dim_energy, erg, dim_force, dim_length> {};
|
||||
|
||||
template<Unit U, Scalar Rep = double>
|
||||
using energy = quantity<dim_energy, U, Rep>;
|
||||
|
||||
inline namespace literals {
|
||||
|
||||
// erg
|
||||
constexpr auto operator""_erg(unsigned long long l) { return energy<erg, std::int64_t>(l); }
|
||||
constexpr auto operator""_erg(long double l) { return energy<erg, long double>(l); }
|
||||
|
||||
} // namespace literals
|
||||
|
||||
} // namespace units::cgs
|
48
src/include/units/physical/cgs/force.h
Normal file
48
src/include/units/physical/cgs/force.h
Normal file
@@ -0,0 +1,48 @@
|
||||
// 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 <units/physical/dimensions.h>
|
||||
#include <units/physical/cgs/acceleration.h>
|
||||
#include <units/physical/cgs/mass.h>
|
||||
#include <units/physical/si/prefixes.h>
|
||||
#include <units/quantity.h>
|
||||
|
||||
namespace units::cgs {
|
||||
|
||||
struct dyne : named_unit<dyne, "dyn", si::prefix> {};
|
||||
|
||||
struct dim_force : physical::dim_force<dim_force, dyne, dim_mass, dim_acceleration> {};
|
||||
|
||||
template<Unit U, Scalar Rep = double>
|
||||
using force = quantity<dim_force, U, Rep>;
|
||||
|
||||
inline namespace literals {
|
||||
|
||||
// dyn
|
||||
constexpr auto operator""dyn(unsigned long long l) { return force<dyne, std::int64_t>(l); }
|
||||
constexpr auto operator""dyn(long double l) { return force<dyne, long double>(l); }
|
||||
|
||||
} // namespace literals
|
||||
|
||||
} // namespace units::cgs
|
44
src/include/units/physical/cgs/length.h
Normal file
44
src/include/units/physical/cgs/length.h
Normal file
@@ -0,0 +1,44 @@
|
||||
// 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 <units/physical/dimensions.h>
|
||||
#include <units/physical/si/length.h>
|
||||
#include <units/quantity.h>
|
||||
|
||||
namespace units::cgs {
|
||||
|
||||
using si::centimetre;
|
||||
|
||||
struct dim_length : physical::dim_length<centimetre> {};
|
||||
|
||||
template<Unit U, Scalar Rep = double>
|
||||
using length = quantity<dim_length, U, Rep>;
|
||||
|
||||
inline namespace literals {
|
||||
|
||||
using si::literals::operator"" cm;
|
||||
|
||||
}
|
||||
|
||||
} // namespace units::cgs
|
44
src/include/units/physical/cgs/mass.h
Normal file
44
src/include/units/physical/cgs/mass.h
Normal file
@@ -0,0 +1,44 @@
|
||||
// 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 <units/physical/dimensions.h>
|
||||
#include <units/physical/si/mass.h>
|
||||
#include <units/quantity.h>
|
||||
|
||||
namespace units::cgs {
|
||||
|
||||
using si::gram;
|
||||
|
||||
struct dim_mass : physical::dim_mass<gram> {};
|
||||
|
||||
template<Unit U, Scalar Rep = double>
|
||||
using mass = quantity<dim_mass, U, Rep>;
|
||||
|
||||
inline namespace literals {
|
||||
|
||||
using si::literals::operator"" g;
|
||||
|
||||
}
|
||||
|
||||
} // namespace units::cgs
|
47
src/include/units/physical/cgs/power.h
Normal file
47
src/include/units/physical/cgs/power.h
Normal file
@@ -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 <units/physical/dimensions.h>
|
||||
#include <units/physical/cgs/energy.h>
|
||||
#include <units/physical/si/prefixes.h>
|
||||
#include <units/quantity.h>
|
||||
|
||||
namespace units::cgs {
|
||||
|
||||
struct erg_per_second : unit<erg_per_second> {};
|
||||
|
||||
struct dim_power : physical::dim_power<dim_power, erg_per_second, dim_energy, dim_time> {};
|
||||
|
||||
template<Unit U, Scalar Rep = double>
|
||||
using power = quantity<dim_power, U, Rep>;
|
||||
|
||||
inline namespace literals {
|
||||
|
||||
// ergps
|
||||
constexpr auto operator""_ergps(unsigned long long l) { return power<erg_per_second, std::int64_t>(l); }
|
||||
constexpr auto operator""_ergps(long double l) { return power<erg_per_second, long double>(l); }
|
||||
|
||||
} // namespace literals
|
||||
|
||||
} // namespace units::cgs
|
48
src/include/units/physical/cgs/pressure.h
Normal file
48
src/include/units/physical/cgs/pressure.h
Normal file
@@ -0,0 +1,48 @@
|
||||
// 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 <units/physical/dimensions.h>
|
||||
#include <units/physical/cgs/area.h>
|
||||
#include <units/physical/cgs/force.h>
|
||||
#include <units/physical/si/prefixes.h>
|
||||
#include <units/quantity.h>
|
||||
|
||||
namespace units::cgs {
|
||||
|
||||
struct barye : named_unit<barye, "Ba", si::prefix> {};
|
||||
|
||||
struct dim_pressure : physical::dim_pressure<dim_pressure, barye, dim_force, dim_area> {};
|
||||
|
||||
template<Unit U, Scalar Rep = double>
|
||||
using pressure = quantity<dim_pressure, U, Rep>;
|
||||
|
||||
inline namespace literals {
|
||||
|
||||
// Ba
|
||||
constexpr auto operator""Ba(unsigned long long l) { return pressure<barye, std::int64_t>(l); }
|
||||
constexpr auto operator""Ba(long double l) { return pressure<barye, long double>(l); }
|
||||
|
||||
} // namespace literals
|
||||
|
||||
} // namespace units::cgs
|
42
src/include/units/physical/cgs/time.h
Normal file
42
src/include/units/physical/cgs/time.h
Normal file
@@ -0,0 +1,42 @@
|
||||
// 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 <units/physical/dimensions.h>
|
||||
#include <units/physical/si/time.h>
|
||||
#include <units/quantity.h>
|
||||
|
||||
namespace units::cgs {
|
||||
|
||||
using si::second;
|
||||
|
||||
using si::dim_time;
|
||||
using si::time;
|
||||
|
||||
inline namespace literals {
|
||||
|
||||
using si::literals::operator"" s;
|
||||
|
||||
}
|
||||
|
||||
} // namespace units::cgs
|
46
src/include/units/physical/cgs/velocity.h
Normal file
46
src/include/units/physical/cgs/velocity.h
Normal file
@@ -0,0 +1,46 @@
|
||||
// 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 <units/physical/dimensions.h>
|
||||
#include <units/physical/cgs/length.h>
|
||||
#include <units/physical/cgs/time.h>
|
||||
#include <units/quantity.h>
|
||||
|
||||
namespace units::cgs {
|
||||
|
||||
struct centimetre_per_second : unit<centimetre_per_second> {};
|
||||
struct dim_velocity : physical::dim_velocity<dim_velocity, centimetre_per_second, dim_length, dim_time> {};
|
||||
|
||||
template<Unit U, Scalar Rep = double>
|
||||
using velocity = quantity<dim_velocity, U, Rep>;
|
||||
|
||||
inline namespace literals {
|
||||
|
||||
// cmps
|
||||
constexpr auto operator"" cmps(unsigned long long l) { return velocity<centimetre_per_second, std::int64_t>(l); }
|
||||
constexpr auto operator"" cmps(long double l) { return velocity<centimetre_per_second, long double>(l); }
|
||||
|
||||
} // namespace literals
|
||||
|
||||
} // namespace units::cgs
|
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <units/physical/dimensions.h>
|
||||
#include <units/physical/si/prefixes.h>
|
||||
#include <units/quantity.h>
|
||||
|
||||
namespace units::si {
|
||||
|
||||
|
@@ -44,7 +44,7 @@ concept Quantity = detail::is_quantity<T>;
|
||||
|
||||
// QuantityOf
|
||||
template<typename T, typename Dim>
|
||||
concept QuantityOf = Quantity<T> && Dimension<Dim> && same_dim<typename T::dimension, Dim>;
|
||||
concept QuantityOf = Quantity<T> && Dimension<Dim> && equivalent_dim<typename T::dimension, Dim>;
|
||||
|
||||
// Scalar
|
||||
template<typename T>
|
||||
@@ -76,9 +76,23 @@ struct common_quantity_impl<quantity<D, U1, Rep1>, quantity<D, U2, Rep2>, Rep> {
|
||||
using type = quantity<D, downcast_unit<D, common_ratio<typename U1::ratio, typename U2::ratio>>, Rep>;
|
||||
};
|
||||
|
||||
template<typename D1, typename U1, typename Rep1, typename D2, typename U2, typename Rep2, typename Rep>
|
||||
requires same_unit_reference<dimension_unit<D1>, dimension_unit<D2>>::value
|
||||
struct common_quantity_impl<quantity<D1, U1, Rep1>, quantity<D2, U2, Rep2>, Rep> {
|
||||
using type = quantity<D1, downcast_unit<D1, common_ratio<typename U1::ratio, typename U2::ratio>>, Rep>;
|
||||
};
|
||||
|
||||
template<typename D1, typename U1, typename Rep1, typename D2, typename U2, typename Rep2, typename Rep>
|
||||
struct common_quantity_impl<quantity<D1, U1, Rep1>, quantity<D2, U2, Rep2>, Rep> {
|
||||
using ratio1 = ratio_multiply<typename D1::base_units_ratio, typename U1::ratio>;
|
||||
using ratio2 = ratio_multiply<typename D2::base_units_ratio, typename U2::ratio>;
|
||||
using type = quantity<D1, downcast_unit<D1, common_ratio<ratio1, ratio2>>, Rep>;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<Quantity Q1, Quantity Q2, Scalar Rep = std::common_type_t<typename Q1::rep, typename Q2::rep>>
|
||||
requires equivalent_dim<typename Q1::dimension, typename Q2::dimension>
|
||||
using common_quantity = detail::common_quantity_impl<Q1, Q2, Rep>::type;
|
||||
|
||||
// quantity_cast
|
||||
@@ -130,6 +144,27 @@ struct quantity_cast_impl<To, CRatio, CRep, false, true> {
|
||||
}
|
||||
};
|
||||
|
||||
template<Dimension FromD, Unit FromU, Dimension ToD, Unit ToU>
|
||||
struct cast_ratio;
|
||||
|
||||
template<BaseDimension FromD, Unit FromU, BaseDimension ToD, Unit ToU>
|
||||
struct cast_ratio<FromD, FromU, ToD, ToU> {
|
||||
using type = ratio_divide<typename FromU::ratio, typename ToU::ratio>;
|
||||
};
|
||||
|
||||
template<DerivedDimension FromD, Unit FromU, DerivedDimension ToD, Unit ToU>
|
||||
requires same_unit_reference<FromU, ToU>::value
|
||||
struct cast_ratio<FromD, FromU, ToD, ToU> {
|
||||
using type = ratio_divide<typename FromU::ratio, typename ToU::ratio>;
|
||||
};
|
||||
|
||||
template<DerivedDimension FromD, Unit FromU, DerivedDimension ToD, Unit ToU>
|
||||
struct cast_ratio<FromD, FromU, ToD, ToU> {
|
||||
using from_ratio = ratio_multiply<typename FromD::base_units_ratio, typename FromU::ratio>;
|
||||
using to_ratio = ratio_multiply<typename ToD::base_units_ratio, typename ToU::ratio>;
|
||||
using type = ratio_divide<from_ratio, to_ratio>;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/**
|
||||
@@ -150,7 +185,7 @@ template<Quantity To, typename D, typename U, typename Rep>
|
||||
requires QuantityOf<To, D> &&
|
||||
detail::basic_arithmetic<std::common_type_t<typename To::rep, Rep, intmax_t>>
|
||||
{
|
||||
using c_ratio = ratio_divide<typename U::ratio, typename To::unit::ratio>;
|
||||
using c_ratio = detail::cast_ratio<D, U, typename To::dimension, typename To::unit>::type;
|
||||
using c_rep = std::common_type_t<typename To::rep, Rep, intmax_t>;
|
||||
using ret_unit = downcast_unit<D, typename To::unit::ratio>;
|
||||
using ret = quantity<D, ret_unit, typename To::rep>;
|
||||
@@ -172,7 +207,7 @@ template<Quantity To, typename D, typename U, typename Rep>
|
||||
*/
|
||||
template<Dimension ToD, typename D, typename U, typename Rep>
|
||||
[[nodiscard]] constexpr auto quantity_cast(const quantity<D, U, Rep>& q)
|
||||
requires same_dim<ToD, D>
|
||||
requires equivalent_dim<ToD, D>
|
||||
{
|
||||
return quantity_cast<quantity<ToD, U, Rep>>(q);
|
||||
}
|
||||
@@ -260,7 +295,7 @@ public:
|
||||
constexpr explicit quantity(const Value& v) : value_{static_cast<rep>(v)} {}
|
||||
|
||||
template<Quantity Q2>
|
||||
requires same_dim<D, typename Q2::dimension> &&
|
||||
requires equivalent_dim<D, typename Q2::dimension> &&
|
||||
detail::safe_convertible<typename Q2::rep, rep> &&
|
||||
detail::safe_divisible<rep, typename Q2::unit, unit>
|
||||
constexpr quantity(const Q2& q) : value_{quantity_cast<quantity>(q).count()} {}
|
||||
@@ -446,7 +481,7 @@ template<Scalar Value, typename D, typename U, typename Rep>
|
||||
|
||||
template<typename D1, typename U1, typename Rep1, typename D2, typename U2, typename Rep2>
|
||||
[[nodiscard]] constexpr Scalar AUTO operator*(const quantity<D1, U1, Rep1>& lhs, const quantity<D2, U2, Rep2>& rhs)
|
||||
requires same_dim<D1, dim_invert<D2>>&& detail::basic_arithmetic<Rep1, Rep2>
|
||||
requires equivalent_dim<D1, dim_invert<D2>> && detail::basic_arithmetic<Rep1, Rep2>
|
||||
{
|
||||
using common_rep = decltype(lhs.count() * rhs.count());
|
||||
using ratio = ratio_multiply<typename U1::ratio, typename U2::ratio>;
|
||||
@@ -455,14 +490,14 @@ template<typename D1, typename U1, typename Rep1, typename D2, typename U2, type
|
||||
|
||||
template<typename D1, typename U1, typename Rep1, typename D2, typename U2, typename Rep2>
|
||||
[[nodiscard]] constexpr Quantity AUTO operator*(const quantity<D1, U1, Rep1>& lhs, const quantity<D2, U2, Rep2>& rhs)
|
||||
requires (!same_dim<D1, dim_invert<D2>>) &&
|
||||
requires (!equivalent_dim<D1, dim_invert<D2>>) && // TODO equivalent_derived_dim?
|
||||
(treat_as_floating_point<decltype(lhs.count() * rhs.count())> ||
|
||||
(std::ratio_multiply<typename U1::ratio, typename U2::ratio>::den == 1)) &&
|
||||
detail::basic_arithmetic<Rep1, Rep2>
|
||||
{
|
||||
using dim = dimension_multiply<D1, D2>;
|
||||
using ratio1 = ratio_divide<typename U1::ratio, typename D1::coherent_unit::ratio>;
|
||||
using ratio2 = ratio_divide<typename U2::ratio, typename D2::coherent_unit::ratio>;
|
||||
using ratio1 = ratio_divide<typename U1::ratio, typename dimension_unit<D1>::ratio>;
|
||||
using ratio2 = ratio_divide<typename U2::ratio, typename dimension_unit<D2>::ratio>;
|
||||
using ratio = ratio_multiply<ratio1, ratio2>;
|
||||
using unit = downcast_unit<dim, ratio>;
|
||||
using common_rep = decltype(lhs.count() * rhs.count());
|
||||
@@ -495,29 +530,29 @@ template<typename D, typename U, typename Rep, Scalar Value>
|
||||
return ret(q.count() / v);
|
||||
}
|
||||
|
||||
template<typename D, typename U1, typename Rep1, typename U2, typename Rep2>
|
||||
[[nodiscard]] constexpr Scalar AUTO operator/(const quantity<D, U1, Rep1>& lhs, const quantity<D, U2, Rep2>& rhs)
|
||||
requires detail::basic_arithmetic<Rep1, Rep2>
|
||||
template<typename D1, typename U1, typename Rep1, typename D2, typename U2, typename Rep2>
|
||||
[[nodiscard]] constexpr Scalar AUTO operator/(const quantity<D1, U1, Rep1>& lhs, const quantity<D2, U2, Rep2>& rhs)
|
||||
requires detail::basic_arithmetic<Rep1, Rep2> && equivalent_dim<D1, D2>
|
||||
{
|
||||
Expects(rhs != std::remove_cvref_t<decltype(rhs)>(0));
|
||||
|
||||
using common_rep = decltype(lhs.count() / rhs.count());
|
||||
using cq = common_quantity<quantity<D, U1, Rep1>, quantity<D, U2, Rep2>, common_rep>;
|
||||
using cq = common_quantity<quantity<D1, U1, Rep1>, quantity<D2, U2, Rep2>, common_rep>;
|
||||
return cq(lhs).count() / cq(rhs).count();
|
||||
}
|
||||
|
||||
template<typename D1, typename U1, typename Rep1, typename D2, typename U2, typename Rep2>
|
||||
[[nodiscard]] constexpr Quantity AUTO operator/(const quantity<D1, U1, Rep1>& lhs, const quantity<D2, U2, Rep2>& rhs)
|
||||
requires (treat_as_floating_point<decltype(lhs.count() / rhs.count())> ||
|
||||
(ratio_divide<typename U1::ratio, typename U2::ratio>::den == 1)) &&
|
||||
detail::basic_arithmetic<Rep1, Rep2>
|
||||
requires detail::basic_arithmetic<Rep1, Rep2> && (!equivalent_dim<D1, D2>) && // TODO equivalent_derived_dim?
|
||||
(treat_as_floating_point<decltype(lhs.count() / rhs.count())> ||
|
||||
(ratio_divide<typename U1::ratio, typename U2::ratio>::den == 1))
|
||||
{
|
||||
Expects(rhs != std::remove_cvref_t<decltype(rhs)>(0));
|
||||
|
||||
using common_rep = decltype(lhs.count() / rhs.count());
|
||||
using dim = dimension_divide<D1, D2>;
|
||||
using ratio1 = ratio_divide<typename U1::ratio, typename D1::coherent_unit::ratio>;
|
||||
using ratio2 = ratio_divide<typename U2::ratio, typename D2::coherent_unit::ratio>;
|
||||
using ratio1 = ratio_divide<typename U1::ratio, typename dimension_unit<D1>::ratio>;
|
||||
using ratio2 = ratio_divide<typename U2::ratio, typename dimension_unit<D2>::ratio>;
|
||||
using ratio = ratio_divide<ratio1, ratio2>;
|
||||
using unit = downcast_unit<dim, ratio>;
|
||||
using ret = quantity<dim, unit, common_rep>;
|
||||
@@ -546,51 +581,57 @@ template<typename D, typename U1, typename Rep1, typename U2, typename Rep2>
|
||||
return ret(ret(lhs).count() % ret(rhs).count());
|
||||
}
|
||||
|
||||
template<typename D, typename U1, typename Rep1, typename U2, typename Rep2>
|
||||
[[nodiscard]] constexpr bool operator==(const quantity<D, U1, Rep1>& lhs, const quantity<D, U2, Rep2>& rhs)
|
||||
requires detail::basic_arithmetic<Rep1, Rep2> &&
|
||||
template<typename D1, typename U1, typename Rep1, typename D2, typename U2, typename Rep2>
|
||||
[[nodiscard]] constexpr bool operator==(const quantity<D1, U1, Rep1>& lhs, const quantity<D2, U2, Rep2>& rhs)
|
||||
requires equivalent_dim<D1, D2> &&
|
||||
detail::basic_arithmetic<Rep1, Rep2> &&
|
||||
std::equality_comparable_with<Rep1, Rep2>
|
||||
{
|
||||
using cq = common_quantity<quantity<D, U1, Rep1>, quantity<D, U2, Rep2>>;
|
||||
using cq = common_quantity<quantity<D1, U1, Rep1>, quantity<D2, U2, Rep2>>;
|
||||
return cq(lhs).count() == cq(rhs).count();
|
||||
}
|
||||
|
||||
template<typename D, typename U1, typename Rep1, typename U2, typename Rep2>
|
||||
[[nodiscard]] constexpr bool operator!=(const quantity<D, U1, Rep1>& lhs, const quantity<D, U2, Rep2>& rhs)
|
||||
requires detail::basic_arithmetic<Rep1, Rep2> &&
|
||||
template<typename D1, typename U1, typename Rep1, typename D2, typename U2, typename Rep2>
|
||||
[[nodiscard]] constexpr bool operator!=(const quantity<D1, U1, Rep1>& lhs, const quantity<D2, U2, Rep2>& rhs)
|
||||
requires equivalent_dim<D1, D2> &&
|
||||
detail::basic_arithmetic<Rep1, Rep2> &&
|
||||
std::equality_comparable_with<Rep1, Rep2>
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
template<typename D, typename U1, typename Rep1, typename U2, typename Rep2>
|
||||
[[nodiscard]] constexpr bool operator<(const quantity<D, U1, Rep1>& lhs, const quantity<D, U2, Rep2>& rhs)
|
||||
requires detail::basic_arithmetic<Rep1, Rep2> &&
|
||||
template<typename D1, typename U1, typename Rep1, typename D2, typename U2, typename Rep2>
|
||||
[[nodiscard]] constexpr bool operator<(const quantity<D1, U1, Rep1>& lhs, const quantity<D2, U2, Rep2>& rhs)
|
||||
requires equivalent_dim<D1, D2> &&
|
||||
detail::basic_arithmetic<Rep1, Rep2> &&
|
||||
std::totally_ordered_with<Rep1, Rep2>
|
||||
{
|
||||
using cq = common_quantity<quantity<D, U1, Rep1>, quantity<D, U2, Rep2>>;
|
||||
using cq = common_quantity<quantity<D1, U1, Rep1>, quantity<D2, U2, Rep2>>;
|
||||
return cq(lhs).count() < cq(rhs).count();
|
||||
}
|
||||
|
||||
template<typename D, typename U1, typename Rep1, typename U2, typename Rep2>
|
||||
[[nodiscard]] constexpr bool operator<=(const quantity<D, U1, Rep1>& lhs, const quantity<D, U2, Rep2>& rhs)
|
||||
requires detail::basic_arithmetic<Rep1, Rep2> &&
|
||||
template<typename D1, typename U1, typename Rep1, typename D2, typename U2, typename Rep2>
|
||||
[[nodiscard]] constexpr bool operator<=(const quantity<D1, U1, Rep1>& lhs, const quantity<D2, U2, Rep2>& rhs)
|
||||
requires equivalent_dim<D1, D2> &&
|
||||
detail::basic_arithmetic<Rep1, Rep2> &&
|
||||
std::totally_ordered_with<Rep1, Rep2>
|
||||
{
|
||||
return !(rhs < lhs);
|
||||
}
|
||||
|
||||
template<typename D, typename U1, typename Rep1, typename U2, typename Rep2>
|
||||
[[nodiscard]] constexpr bool operator>(const quantity<D, U1, Rep1>& lhs, const quantity<D, U2, Rep2>& rhs)
|
||||
requires detail::basic_arithmetic<Rep1, Rep2> &&
|
||||
template<typename D1, typename U1, typename Rep1, typename D2, typename U2, typename Rep2>
|
||||
[[nodiscard]] constexpr bool operator>(const quantity<D1, U1, Rep1>& lhs, const quantity<D2, U2, Rep2>& rhs)
|
||||
requires equivalent_dim<D1, D2> &&
|
||||
detail::basic_arithmetic<Rep1, Rep2> &&
|
||||
std::totally_ordered_with<Rep1, Rep2>
|
||||
{
|
||||
return rhs < lhs;
|
||||
}
|
||||
|
||||
template<typename D, typename U1, typename Rep1, typename U2, typename Rep2>
|
||||
[[nodiscard]] constexpr bool operator>=(const quantity<D, U1, Rep1>& lhs, const quantity<D, U2, Rep2>& rhs)
|
||||
requires detail::basic_arithmetic<Rep1, Rep2> &&
|
||||
template<typename D1, typename U1, typename Rep1, typename D2, typename U2, typename Rep2>
|
||||
[[nodiscard]] constexpr bool operator>=(const quantity<D1, U1, Rep1>& lhs, const quantity<D2, U2, Rep2>& rhs)
|
||||
requires equivalent_dim<D1, D2> &&
|
||||
detail::basic_arithmetic<Rep1, Rep2> &&
|
||||
std::totally_ordered_with<Rep1, Rep2>
|
||||
{
|
||||
return !(lhs < rhs);
|
||||
|
@@ -54,7 +54,10 @@ struct scaled_unit : downcast_base<scaled_unit<U, R>> {
|
||||
};
|
||||
|
||||
template<Dimension D, UnitRatio R>
|
||||
using downcast_unit = downcast<scaled_unit<typename D::coherent_unit::reference, R>>;
|
||||
using downcast_unit = downcast<scaled_unit<typename dimension_unit<D>::reference, R>>;
|
||||
|
||||
template<Unit U1, Unit U2>
|
||||
struct same_unit_reference : std::is_same<typename U1::reference, typename U2::reference> {};
|
||||
|
||||
/**
|
||||
* @brief A starting point for a new hierarchy of units
|
||||
@@ -146,7 +149,7 @@ template<typename U, typename D>
|
||||
concept UnitOf =
|
||||
Unit<U> &&
|
||||
Dimension<D> &&
|
||||
std::same_as<typename U::reference, typename D::coherent_unit::reference>;
|
||||
std::same_as<typename U::reference, typename dimension_unit<D>::reference>;
|
||||
|
||||
namespace detail {
|
||||
|
||||
|
@@ -21,7 +21,7 @@
|
||||
# SOFTWARE.
|
||||
|
||||
add_library(unit_tests_static
|
||||
# cgs_test.cpp
|
||||
cgs_test.cpp
|
||||
custom_unit_test.cpp
|
||||
data_test.cpp
|
||||
dimension_op_test.cpp
|
||||
|
@@ -20,56 +20,87 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#include <units/dimensions/acceleration.h>
|
||||
#include <units/dimensions/power.h>
|
||||
#include <units/dimensions/pressure.h>
|
||||
#include <units/math.h>
|
||||
|
||||
namespace cgs {
|
||||
|
||||
using units::centimetre;
|
||||
using units::gram;
|
||||
using units::second;
|
||||
struct centimetre_per_second : units::deduced_derived_unit<centimetre_per_second, units::velocity, centimetre, second> {};
|
||||
struct gal : units::named_deduced_derived_unit<gal, units::acceleration, "Gal", units::no_prefix, centimetre, second> {};
|
||||
struct dyne : units::named_deduced_derived_unit<dyne, units::force, "dyn", units::no_prefix, centimetre, gram, second> {};
|
||||
struct erg : units::named_deduced_derived_unit<erg, units::energy, "erg", units::no_prefix, centimetre, gram, second> {};
|
||||
struct ergps : units::named_deduced_derived_unit<ergps, units::power, "erg/s", units::no_prefix, centimetre, gram, second> {}; // TODO make it work for erg and non-named
|
||||
struct barye : units::named_deduced_derived_unit<barye, units::pressure, "Ba", units::no_prefix, centimetre, gram, second> {};
|
||||
|
||||
|
||||
inline namespace literals {
|
||||
|
||||
using namespace units::literals;
|
||||
|
||||
constexpr auto operator""cmps(unsigned long long l) { return units::quantity<centimetre_per_second, std::int64_t>(l); }
|
||||
constexpr auto operator""cmps(long double l) { return units::quantity<centimetre_per_second, long double>(l); }
|
||||
constexpr auto operator""Gal(unsigned long long l) { return units::quantity<gal, std::int64_t>(l); }
|
||||
constexpr auto operator""Gal(long double l) { return units::quantity<gal, long double>(l); }
|
||||
constexpr auto operator""dyn(unsigned long long l) { return units::quantity<dyne, std::int64_t>(l); }
|
||||
constexpr auto operator""dyn(long double l) { return units::quantity<dyne, long double>(l); }
|
||||
constexpr auto operator""_erg(unsigned long long l) { return units::quantity<erg, std::int64_t>(l); }
|
||||
constexpr auto operator""_erg(long double l) { return units::quantity<erg, long double>(l); }
|
||||
constexpr auto operator""_ergps(unsigned long long l) { return units::quantity<ergps, std::int64_t>(l); }
|
||||
constexpr auto operator""_ergps(long double l) { return units::quantity<ergps, long double>(l); }
|
||||
constexpr auto operator""Ba(unsigned long long l) { return units::quantity<barye, std::int64_t>(l); }
|
||||
constexpr auto operator""Ba(long double l) { return units::quantity<barye, long double>(l); }
|
||||
|
||||
} // namespace literals
|
||||
|
||||
}
|
||||
#include <units/physical/cgs/acceleration.h>
|
||||
#include <units/physical/cgs/energy.h>
|
||||
#include <units/physical/cgs/force.h>
|
||||
#include <units/physical/cgs/length.h>
|
||||
#include <units/physical/cgs/mass.h>
|
||||
#include <units/physical/cgs/power.h>
|
||||
#include <units/physical/cgs/pressure.h>
|
||||
#include <units/physical/cgs/time.h>
|
||||
#include <units/physical/cgs/velocity.h>
|
||||
#include <units/physical/si/acceleration.h>
|
||||
#include <units/physical/si/energy.h>
|
||||
#include <units/physical/si/force.h>
|
||||
#include <units/physical/si/length.h>
|
||||
#include <units/physical/si/mass.h>
|
||||
#include <units/physical/si/power.h>
|
||||
#include <units/physical/si/pressure.h>
|
||||
#include <units/physical/si/time.h>
|
||||
#include <units/physical/si/velocity.h>
|
||||
|
||||
namespace {
|
||||
|
||||
using namespace cgs::literals;
|
||||
using namespace units;
|
||||
|
||||
static_assert(100cm == 1m);
|
||||
static_assert(1'000g == 1kg);
|
||||
static_assert(100cmps == 1mps);
|
||||
static_assert(100Gal == 1mps_sq);
|
||||
static_assert(100'000dyn == 1N);
|
||||
static_assert(10'000'000_erg == 1_J);
|
||||
static_assert(10'000'000_ergps == 1W);
|
||||
static_assert(10Ba == 1Pa);
|
||||
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));
|
||||
static_assert(cgs::velocity<cgs::centimetre_per_second>(100) == si::velocity<si::metre_per_second>(1));
|
||||
static_assert(cgs::acceleration<cgs::gal>(100) == si::acceleration<si::metre_per_second_sq>(1));
|
||||
static_assert(cgs::force<cgs::dyne>(100'000) == si::force<si::newton>(1));
|
||||
static_assert(cgs::energy<cgs::erg>(10'000'000) == si::energy<si::joule>(1));
|
||||
static_assert(cgs::power<cgs::erg_per_second>(10'000'000) == si::power<si::watt>(1));
|
||||
static_assert(cgs::pressure<cgs::barye>(10) == si::pressure<si::pascal>(1));
|
||||
|
||||
}
|
||||
namespace si_test {
|
||||
|
||||
using namespace units::si::literals;
|
||||
|
||||
static_assert(cgs::length<cgs::centimetre>(100) == 1m);
|
||||
static_assert(cgs::mass<cgs::gram>(1'000) == 1kg);
|
||||
static_assert(cgs::time<cgs::second>(1) == 1s);
|
||||
static_assert(cgs::velocity<cgs::centimetre_per_second>(100) == 1mps);
|
||||
static_assert(cgs::acceleration<cgs::gal>(100) == 1mps_sq);
|
||||
static_assert(cgs::force<cgs::dyne>(100'000) == 1N);
|
||||
static_assert(cgs::energy<cgs::erg>(10'000'000) == 1_J);
|
||||
static_assert(cgs::power<cgs::erg_per_second>(10'000'000) == 1W);
|
||||
static_assert(cgs::pressure<cgs::barye>(10) == 1Pa);
|
||||
|
||||
}
|
||||
|
||||
namespace cgs_test {
|
||||
|
||||
using namespace units::cgs::literals;
|
||||
|
||||
static_assert(100cm == si::length<si::metre>(1));
|
||||
static_assert(1'000g == si::mass<si::kilogram>(1));
|
||||
static_assert(1s == si::time<si::second>(1));
|
||||
static_assert(100cmps == si::velocity<si::metre_per_second>(1));
|
||||
static_assert(100Gal == si::acceleration<si::metre_per_second_sq>(1));
|
||||
static_assert(100'000dyn == si::force<si::newton>(1));
|
||||
static_assert(10'000'000_erg == si::energy<si::joule>(1));
|
||||
static_assert(10'000'000_ergps == si::power<si::watt>(1));
|
||||
static_assert(10Ba == si::pressure<si::pascal>(1));
|
||||
|
||||
}
|
||||
|
||||
namespace both_test {
|
||||
|
||||
using namespace units::si::literals;
|
||||
using namespace units::cgs::literals;
|
||||
|
||||
static_assert(100cm == 1m);
|
||||
static_assert(1'000g == 1kg);
|
||||
static_assert(1s == 1s);
|
||||
static_assert(100cmps == 1mps);
|
||||
static_assert(100Gal == 1mps_sq);
|
||||
static_assert(100'000dyn == 1N);
|
||||
static_assert(10'000'000_erg == 1_J);
|
||||
static_assert(10'000'000_ergps == 1W);
|
||||
static_assert(10Ba == quantity_cast<double>(1Pa));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user