mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-01 03:14:29 +02:00
refactor: 💥 𝜋 replaced with π
This commit is contained in:
@@ -45,7 +45,7 @@ inline constexpr struct speed_of_light_in_vacuum final :
|
||||
} // namespace si2019
|
||||
|
||||
inline constexpr struct magnetic_constant final :
|
||||
named_unit<{u8"μ₀", "u_0"}, mag<4> * mag<𝜋> * mag_power<10, -7> * henry / metre> {} magnetic_constant;
|
||||
named_unit<{u8"μ₀", "u_0"}, mag<4> * mag<π> * mag_power<10, -7> * henry / metre> {} magnetic_constant;
|
||||
|
||||
} // namespace mp_units::si
|
||||
```
|
||||
|
@@ -196,12 +196,12 @@ For some units, a magnitude might also be irrational. The best example here is a
|
||||
is defined using a floating-point magnitude having a factor of the number π (Pi):
|
||||
|
||||
```cpp
|
||||
inline constexpr struct pi final : mag_constant<symbol_text{u8"𝜋", "pi"}, std::numbers::pi_v<long double>> {} pi;
|
||||
inline constexpr auto 𝜋 = pi;
|
||||
inline constexpr struct pi final : mag_constant<symbol_text{u8"\u03c0", "pi"}, std::numbers::pi_v<long double>> {} pi;
|
||||
inline constexpr auto π = pi;
|
||||
```
|
||||
|
||||
```cpp
|
||||
inline constexpr struct degree final : named_unit<{u8"°", "deg"}, mag<𝜋> / mag<180> * si::radian> {} degree;
|
||||
inline constexpr struct degree final : named_unit<{u8"°", "deg"}, mag<π> / mag<180> * si::radian> {} degree;
|
||||
```
|
||||
|
||||
|
||||
|
@@ -314,7 +314,7 @@ prints:
|
||||
40771 EQUIV{[1/25146 mi], [1/15625 km]}
|
||||
108167 EQUIV{[1/50292 mi], [1/57875 nmi]}
|
||||
23 EQUIV{[1/5 km/h], [1/18 m/s]}
|
||||
183.142 EQUIV{[1/𝜋°], [1/180 rad]}
|
||||
183.142 EQUIV{[1/π°], [1/180 rad]}
|
||||
```
|
||||
|
||||
Thanks to the above, it might be easier for the user to reason about the magnitude of the resulting
|
||||
|
@@ -690,13 +690,13 @@ constexpr Magnitude auto mag_power = _pow<Num, Den>(mag<Base>);
|
||||
* @brief A convenient Magnitude constant for pi, which we can manipulate like a regular number.
|
||||
*/
|
||||
#if defined MP_UNITS_COMP_CLANG || MP_UNITS_COMP_CLANG < 18
|
||||
inline constexpr struct pi final : mag_constant<symbol_text{u8"\U0001D70B", "pi"}> {
|
||||
inline constexpr struct pi final : mag_constant<symbol_text{u8"\u03c0", "pi"}> {
|
||||
static constexpr auto _value_ = std::numbers::pi_v<long double>;
|
||||
#else
|
||||
inline constexpr struct pi final : mag_constant<symbol_text{u8"\U0001D70B", "pi"}, std::numbers::pi_v<long double>> {
|
||||
inline constexpr struct pi final : mag_constant<symbol_text{u8"\u03c0", "pi"}, std::numbers::pi_v<long double>> {
|
||||
#endif
|
||||
} pi;
|
||||
inline constexpr auto 𝜋 = pi;
|
||||
inline constexpr auto π = pi;
|
||||
|
||||
[[deprecated("Use `mag<pi>` instead")]] inline constexpr Magnitude auto mag_pi = mag<pi>;
|
||||
|
||||
|
@@ -41,7 +41,7 @@ QUANTITY_SPEC(angle, dim_angle);
|
||||
QUANTITY_SPEC(solid_angle, pow<2>(angle));
|
||||
|
||||
inline constexpr struct radian final : named_unit<"rad", kind_of<angle>> {} radian;
|
||||
inline constexpr struct revolution final : named_unit<"rev", mag<2> * mag<𝜋> * radian> {} revolution;
|
||||
inline constexpr struct revolution final : named_unit<"rev", mag<2> * mag<π> * radian> {} revolution;
|
||||
inline constexpr struct degree final : named_unit<symbol_text{u8"°", "deg"}, mag_ratio<1, 360> * revolution> {} degree;
|
||||
inline constexpr struct gradian final : named_unit<symbol_text{u8"ᵍ", "grad"}, mag_ratio<1, 400> * revolution> {} gradian;
|
||||
inline constexpr struct steradian final : named_unit<"sr", square(radian)> {} steradian;
|
||||
|
@@ -57,7 +57,7 @@ inline constexpr struct luminous_efficacy final :
|
||||
inline constexpr struct standard_gravity final :
|
||||
named_unit<symbol_text{u8"g₀", "g_0"}, mag_ratio<980'665, 100'000> * metre / square(second)> {} standard_gravity;
|
||||
inline constexpr struct magnetic_constant final :
|
||||
named_unit<symbol_text{u8"μ₀", "u_0"}, mag<4> * mag<𝜋> * mag_power<10, -7> * henry / metre> {} magnetic_constant;
|
||||
named_unit<symbol_text{u8"μ₀", "u_0"}, mag<4> * mag<π> * mag_power<10, -7> * henry / metre> {} magnetic_constant;
|
||||
// clang-format on
|
||||
|
||||
} // namespace mp_units::si
|
||||
|
@@ -100,7 +100,7 @@ inline constexpr struct minute final : named_unit<"min", mag<60> * si::second> {
|
||||
inline constexpr struct hour final : named_unit<"h", mag<60> * minute> {} hour;
|
||||
inline constexpr struct day final : named_unit<"d", mag<24> * hour> {} day;
|
||||
inline constexpr struct astronomical_unit final : named_unit<"au", mag<149'597'870'700> * si::metre> {} astronomical_unit;
|
||||
inline constexpr struct degree final : named_unit<symbol_text{u8"°", "deg"}, mag<𝜋> / mag<180> * si::radian> {} degree;
|
||||
inline constexpr struct degree final : named_unit<symbol_text{u8"°", "deg"}, mag<π> / mag<180> * si::radian> {} degree;
|
||||
inline constexpr struct arcminute final : named_unit<symbol_text{u8"′", "'"}, mag_ratio<1, 60> * degree> {} arcminute;
|
||||
inline constexpr struct arcsecond final : named_unit<symbol_text{u8"″", "''"}, mag_ratio<1, 60> * arcminute> {} arcsecond;
|
||||
inline constexpr struct are final : named_unit<"a", square(si::deca<si::metre>)> {} are;
|
||||
|
@@ -42,11 +42,11 @@ using namespace mp_units;
|
||||
using namespace mp_units::angular;
|
||||
using namespace mp_units::angular::unit_symbols;
|
||||
|
||||
inline constexpr struct half_revolution final : named_unit<"hrev", mag<𝜋> * radian> {
|
||||
inline constexpr struct half_revolution final : named_unit<"hrev", mag<π> * radian> {
|
||||
} half_revolution;
|
||||
inline constexpr auto hrev = half_revolution;
|
||||
|
||||
// constexpr auto revb6 = mag_ratio<1,3> * mag<𝜋> * rad;
|
||||
// constexpr auto revb6 = mag_ratio<1,3> * mag<π> * rad;
|
||||
|
||||
TEST_CASE("value_cast should not truncate for valid inputs", "[value_cast]")
|
||||
{
|
||||
|
@@ -216,9 +216,9 @@ static_assert(std::is_same_v<decltype(get_base(power_v<mag_2, 5, 8>{})), mag_2_>
|
||||
|
||||
// SECTION("pi to the 1 supplies correct values")
|
||||
// {
|
||||
// check_same_type_and_value(get_value<float>(mag<𝜋>), std::numbers::pi_v<float>);
|
||||
// check_same_type_and_value(get_value<double>(mag<𝜋>), std::numbers::pi_v<double>);
|
||||
// check_same_type_and_value(get_value<long double>(mag<𝜋>), std::numbers::pi_v<long double>);
|
||||
// check_same_type_and_value(get_value<float>(mag<π>), std::numbers::pi_v<float>);
|
||||
// check_same_type_and_value(get_value<double>(mag<π>), std::numbers::pi_v<double>);
|
||||
// check_same_type_and_value(get_value<long double>(mag<π>), std::numbers::pi_v<long double>);
|
||||
// }
|
||||
|
||||
// SECTION("pi to arbitrary power performs computations in most accurate type at compile time")
|
||||
|
@@ -150,58 +150,58 @@ inline constexpr struct e final : mag_constant<"e", std::numbers::e_v<long doubl
|
||||
#endif
|
||||
} e;
|
||||
|
||||
static_assert(unit_symbol(mag<𝜋> * one) == "[𝜋]");
|
||||
static_assert(unit_symbol<usf{.encoding = portable}>(mag<𝜋> * one) == "[pi]");
|
||||
static_assert(unit_symbol(mag<𝜋> * metre) == "[𝜋 m]");
|
||||
static_assert(unit_symbol<usf{.encoding = portable}>(mag<𝜋> * metre) == "[pi m]");
|
||||
static_assert(unit_symbol(mag<2> * mag<𝜋> * metre) == "[2 𝜋 m]");
|
||||
static_assert(unit_symbol<usf{.encoding = portable}>(mag<2> * mag<𝜋> * metre) == "[2 pi m]");
|
||||
static_assert(unit_symbol<usf{.separator = half_high_dot}>(mag<2> * mag<𝜋> * metre) == "[2⋅𝜋 m]");
|
||||
static_assert(unit_symbol(mag<π> * one) == "[π]");
|
||||
static_assert(unit_symbol<usf{.encoding = portable}>(mag<π> * one) == "[pi]");
|
||||
static_assert(unit_symbol(mag<π> * metre) == "[π m]");
|
||||
static_assert(unit_symbol<usf{.encoding = portable}>(mag<π> * metre) == "[pi m]");
|
||||
static_assert(unit_symbol(mag<2> * mag<π> * metre) == "[2 π m]");
|
||||
static_assert(unit_symbol<usf{.encoding = portable}>(mag<2> * mag<π> * metre) == "[2 pi m]");
|
||||
static_assert(unit_symbol<usf{.separator = half_high_dot}>(mag<2> * mag<π> * metre) == "[2⋅π m]");
|
||||
|
||||
static_assert(unit_symbol(mag<1> / mag<𝜋> * one) == "[1/𝜋]");
|
||||
static_assert(unit_symbol<usf{.encoding = portable}>(mag<1> / mag<𝜋> * one) == "[1/pi]");
|
||||
static_assert(unit_symbol<usf{.solidus = never}>(mag<1> / mag<𝜋> * one) == "[𝜋⁻¹]");
|
||||
static_assert(unit_symbol<usf{.encoding = portable, .solidus = never}>(mag<1> / mag<𝜋> * one) == "[pi^-1]");
|
||||
static_assert(unit_symbol(mag<1> / mag<π> * one) == "[1/π]");
|
||||
static_assert(unit_symbol<usf{.encoding = portable}>(mag<1> / mag<π> * one) == "[1/pi]");
|
||||
static_assert(unit_symbol<usf{.solidus = never}>(mag<1> / mag<π> * one) == "[π⁻¹]");
|
||||
static_assert(unit_symbol<usf{.encoding = portable, .solidus = never}>(mag<1> / mag<π> * one) == "[pi^-1]");
|
||||
|
||||
static_assert(unit_symbol(mag<1> / mag<𝜋> * metre) == "[1/𝜋 m]");
|
||||
static_assert(unit_symbol<usf{.encoding = portable}>(mag<1> / mag<𝜋> * metre) == "[1/pi m]");
|
||||
static_assert(unit_symbol<usf{.solidus = never}>(mag<1> / mag<𝜋> * metre) == "[𝜋⁻¹ m]");
|
||||
static_assert(unit_symbol<usf{.encoding = portable, .solidus = never}>(mag<1> / mag<𝜋> * metre) == "[pi^-1 m]");
|
||||
static_assert(unit_symbol(mag<1> / mag<π> * metre) == "[1/π m]");
|
||||
static_assert(unit_symbol<usf{.encoding = portable}>(mag<1> / mag<π> * metre) == "[1/pi m]");
|
||||
static_assert(unit_symbol<usf{.solidus = never}>(mag<1> / mag<π> * metre) == "[π⁻¹ m]");
|
||||
static_assert(unit_symbol<usf{.encoding = portable, .solidus = never}>(mag<1> / mag<π> * metre) == "[pi^-1 m]");
|
||||
|
||||
static_assert(unit_symbol(mag<2> / mag<𝜋> * metre) == "[2/𝜋 m]");
|
||||
static_assert(unit_symbol<usf{.encoding = portable}>(mag<2> / mag<𝜋> * metre) == "[2/pi m]");
|
||||
static_assert(unit_symbol<usf{.solidus = never}>(mag<2> / mag<𝜋> * metre) == "[2 𝜋⁻¹ m]");
|
||||
static_assert(unit_symbol<usf{.encoding = portable, .solidus = never}>(mag<2> / mag<𝜋> * metre) == "[2 pi^-1 m]");
|
||||
static_assert(unit_symbol<usf{.solidus = never, .separator = half_high_dot}>(mag<2> / mag<𝜋> * metre) == "[2⋅𝜋⁻¹ m]");
|
||||
static_assert(unit_symbol(mag<2> / mag<π> * metre) == "[2/π m]");
|
||||
static_assert(unit_symbol<usf{.encoding = portable}>(mag<2> / mag<π> * metre) == "[2/pi m]");
|
||||
static_assert(unit_symbol<usf{.solidus = never}>(mag<2> / mag<π> * metre) == "[2 π⁻¹ m]");
|
||||
static_assert(unit_symbol<usf{.encoding = portable, .solidus = never}>(mag<2> / mag<π> * metre) == "[2 pi^-1 m]");
|
||||
static_assert(unit_symbol<usf{.solidus = never, .separator = half_high_dot}>(mag<2> / mag<π> * metre) == "[2⋅π⁻¹ m]");
|
||||
|
||||
static_assert(unit_symbol(mag<1> / (mag<2> * mag<𝜋>)*metre) == "[2⁻¹ 𝜋⁻¹ m]");
|
||||
static_assert(unit_symbol<usf{.solidus = always}>(mag<1> / (mag<2> * mag<𝜋>)*metre) == "[1/(2 𝜋) m]");
|
||||
static_assert(unit_symbol<usf{.encoding = portable, .solidus = always}>(mag<1> / (mag<2> * mag<𝜋>)*metre) ==
|
||||
static_assert(unit_symbol(mag<1> / (mag<2> * mag<π>)*metre) == "[2⁻¹ π⁻¹ m]");
|
||||
static_assert(unit_symbol<usf{.solidus = always}>(mag<1> / (mag<2> * mag<π>)*metre) == "[1/(2 π) m]");
|
||||
static_assert(unit_symbol<usf{.encoding = portable, .solidus = always}>(mag<1> / (mag<2> * mag<π>)*metre) ==
|
||||
"[1/(2 pi) m]");
|
||||
static_assert(unit_symbol(mag_ratio<1, 2> / mag<𝜋> * metre) == "[2⁻¹ 𝜋⁻¹ m]");
|
||||
static_assert(unit_symbol<usf{.solidus = always}>(mag_ratio<1, 2> / mag<𝜋> * metre) == "[1/(2 𝜋) m]");
|
||||
static_assert(unit_symbol<usf{.encoding = portable, .solidus = always}>(mag_ratio<1, 2> / mag<𝜋> * metre) ==
|
||||
static_assert(unit_symbol(mag_ratio<1, 2> / mag<π> * metre) == "[2⁻¹ π⁻¹ m]");
|
||||
static_assert(unit_symbol<usf{.solidus = always}>(mag_ratio<1, 2> / mag<π> * metre) == "[1/(2 π) m]");
|
||||
static_assert(unit_symbol<usf{.encoding = portable, .solidus = always}>(mag_ratio<1, 2> / mag<π> * metre) ==
|
||||
"[1/(2 pi) m]");
|
||||
static_assert(unit_symbol(mag_ratio<1, 2> * mag<𝜋> * metre) == "[𝜋/2 m]");
|
||||
static_assert(unit_symbol(mag_ratio<1, 2> * mag<π> * metre) == "[π/2 m]");
|
||||
|
||||
static_assert(unit_symbol(mag_power<pi, 2> * one) == "[𝜋²]");
|
||||
static_assert(unit_symbol(mag_power<pi, 2> * one) == "[π²]");
|
||||
static_assert(unit_symbol<usf{.encoding = portable}>(mag_power<pi, 2> * one) == "[pi^2]");
|
||||
static_assert(unit_symbol(mag_power<pi, 1, 2> * metre) == "[𝜋^(1/2) m]");
|
||||
static_assert(unit_symbol(mag_power<pi, 1, 2> * metre) == "[π^(1/2) m]");
|
||||
static_assert(unit_symbol<usf{.encoding = portable}>(mag_power<pi, 1, 2> * metre) == "[pi^(1/2) m]");
|
||||
|
||||
static_assert(unit_symbol(mag<𝜋> * mag<e> * one) == "[e 𝜋]");
|
||||
static_assert(unit_symbol(mag<e> * mag<𝜋> * one) == "[e 𝜋]");
|
||||
static_assert(unit_symbol<usf{.encoding = portable}>(mag<𝜋> * mag<e> * one) == "[e pi]");
|
||||
static_assert(unit_symbol(mag<𝜋> / mag<e> * one) == "[𝜋/e]");
|
||||
static_assert(unit_symbol(mag<1> / mag<e> * mag<𝜋> * one) == "[𝜋/e]");
|
||||
static_assert(unit_symbol<usf{.solidus = never}>(mag<𝜋> / mag<e> * one) == "[𝜋 e⁻¹]");
|
||||
static_assert(unit_symbol(mag<e> / mag<𝜋> * one) == "[e/𝜋]");
|
||||
static_assert(unit_symbol(mag<1> / mag<𝜋> * mag<e> * one) == "[e/𝜋]");
|
||||
static_assert(unit_symbol<usf{.solidus = never}>(mag<e> / mag<𝜋> * one) == "[e 𝜋⁻¹]");
|
||||
static_assert(unit_symbol(mag<1> / (mag<𝜋> * mag<e>)*one) == "[e⁻¹ 𝜋⁻¹]");
|
||||
static_assert(unit_symbol<usf{.solidus = always}>(mag<1> / (mag<𝜋> * mag<e>)*one) == "[1/(e 𝜋)]");
|
||||
static_assert(unit_symbol(mag<2> / (mag<𝜋> * mag<e>)*one) == "[2 e⁻¹ 𝜋⁻¹]");
|
||||
static_assert(unit_symbol<usf{.solidus = always}>(mag<2> / (mag<𝜋> * mag<e>)*one) == "[2/(e 𝜋)]");
|
||||
static_assert(unit_symbol(mag<π> * mag<e> * one) == "[e π]");
|
||||
static_assert(unit_symbol(mag<e> * mag<π> * one) == "[e π]");
|
||||
static_assert(unit_symbol<usf{.encoding = portable}>(mag<π> * mag<e> * one) == "[e pi]");
|
||||
static_assert(unit_symbol(mag<π> / mag<e> * one) == "[π/e]");
|
||||
static_assert(unit_symbol(mag<1> / mag<e> * mag<π> * one) == "[π/e]");
|
||||
static_assert(unit_symbol<usf{.solidus = never}>(mag<π> / mag<e> * one) == "[π e⁻¹]");
|
||||
static_assert(unit_symbol(mag<e> / mag<π> * one) == "[e/π]");
|
||||
static_assert(unit_symbol(mag<1> / mag<π> * mag<e> * one) == "[e/π]");
|
||||
static_assert(unit_symbol<usf{.solidus = never}>(mag<e> / mag<π> * one) == "[e π⁻¹]");
|
||||
static_assert(unit_symbol(mag<1> / (mag<π> * mag<e>)*one) == "[e⁻¹ π⁻¹]");
|
||||
static_assert(unit_symbol<usf{.solidus = always}>(mag<1> / (mag<π> * mag<e>)*one) == "[1/(e π)]");
|
||||
static_assert(unit_symbol(mag<2> / (mag<π> * mag<e>)*one) == "[2 e⁻¹ π⁻¹]");
|
||||
static_assert(unit_symbol<usf{.solidus = always}>(mag<2> / (mag<π> * mag<e>)*one) == "[2/(e π)]");
|
||||
|
||||
// common units
|
||||
static_assert(unit_symbol(get_common_unit(kilo<metre>, mile)) == "EQUIV{[1/25146 mi], [1/15625 km]}");
|
||||
@@ -210,7 +210,7 @@ static_assert(unit_symbol(get_common_unit(kilo<metre> / hour, metre / second) /
|
||||
"EQUIV{[1/5 km/h], [1/18 m/s]}/s");
|
||||
static_assert(unit_symbol(get_common_unit(kilo<metre> / hour, metre / second) * second) ==
|
||||
"EQUIV{[1/5 km/h], [1/18 m/s]} s");
|
||||
static_assert(unit_symbol(get_common_unit(radian, degree)) == "EQUIV{[1/𝜋°], [1/180 rad]}");
|
||||
static_assert(unit_symbol(get_common_unit(radian, degree)) == "EQUIV{[1/π°], [1/180 rad]}");
|
||||
|
||||
// derived units
|
||||
static_assert(unit_symbol(one) == ""); // NOLINT(readability-container-size-empty)
|
||||
|
@@ -58,7 +58,7 @@ inline constexpr struct nu_second_ final : named_unit<"s"> {} nu_second;
|
||||
|
||||
// derived named units
|
||||
inline constexpr struct radian_ final : named_unit<"rad", metre / metre, kind_of<isq::angular_measure>> {} radian;
|
||||
inline constexpr struct revolution_ final : named_unit<"rev", mag<2> * mag<𝜋> * radian> {} revolution;
|
||||
inline constexpr struct revolution_ final : named_unit<"rev", mag<2> * mag<π> * radian> {} revolution;
|
||||
inline constexpr struct steradian_ final : named_unit<"sr", square(metre) / square(metre), kind_of<isq::solid_angular_measure>> {} steradian;
|
||||
inline constexpr struct hertz_ final : named_unit<"Hz", inverse(second), kind_of<isq::frequency>> {} hertz;
|
||||
inline constexpr struct becquerel_ final : named_unit<"Bq", inverse(second), kind_of<isq::activity>> {} becquerel;
|
||||
@@ -70,7 +70,7 @@ inline constexpr struct degree_Celsius_ final : named_unit<symbol_text{u8"℃",
|
||||
|
||||
inline constexpr struct minute_ final : named_unit<"min", mag<60> * second> {} minute;
|
||||
inline constexpr struct hour_ final : named_unit<"h", mag<60> * minute> {} hour;
|
||||
inline constexpr struct degree_ final : named_unit<symbol_text{u8"°", "deg"}, mag<𝜋> / mag<180> * radian> {} degree;
|
||||
inline constexpr struct degree_ final : named_unit<symbol_text{u8"°", "deg"}, mag<π> / mag<180> * radian> {} degree;
|
||||
|
||||
inline constexpr struct yard_ final : named_unit<"yd", mag_ratio<9'144, 10'000> * metre> {} yard;
|
||||
inline constexpr struct mile_ final : named_unit<"mi", mag<1760> * yard> {} mile;
|
||||
@@ -138,7 +138,7 @@ static_assert(get_canonical_unit(radian).mag == mag<1>);
|
||||
|
||||
static_assert(is_of_type<degree, degree_>);
|
||||
static_assert(is_of_type<get_canonical_unit(degree).reference_unit, one_>);
|
||||
static_assert(get_canonical_unit(degree).mag == mag<𝜋> / mag<180>);
|
||||
static_assert(get_canonical_unit(degree).mag == mag<π> / mag<180>);
|
||||
static_assert(convertible(radian, degree));
|
||||
static_assert(radian != degree);
|
||||
|
||||
|
Reference in New Issue
Block a user