feat: 𝜋 added as an alias for pi

This commit is contained in:
Mateusz Pusz
2024-10-14 22:49:58 +02:00
parent f5649205cf
commit 6591a65d06
10 changed files with 55 additions and 53 deletions

View File

@@ -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<pi> * 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
```

View File

@@ -185,10 +185,11 @@ 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;
```
```cpp
inline constexpr struct degree final : named_unit<{u8"°", "deg"}, mag<pi> / mag<180> * si::radian> {} degree;
inline constexpr struct degree final : named_unit<{u8"°", "deg"}, mag<𝜋> / mag<180> * si::radian> {} degree;
```

View File

@@ -696,6 +696,7 @@ inline constexpr struct pi final : mag_constant<symbol_text{u8"𝜋", "pi"}> {
inline constexpr struct pi final : mag_constant<symbol_text{u8"𝜋", "pi"}, std::numbers::pi_v<long double>> {
#endif
} pi;
inline constexpr auto 𝜋 = pi;
[[deprecated("Use `mag<pi>` instead")]] inline constexpr Magnitude auto mag_pi = mag<pi>;

View File

@@ -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<pi> * 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;

View File

@@ -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<pi> * 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

View File

@@ -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<pi> / 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;

View File

@@ -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<pi> * 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<pi> * rad;
// constexpr auto revb6 = mag_ratio<1,3> * mag<𝜋> * rad;
TEST_CASE("value_cast should not truncate for valid inputs", "[value_cast]")
{

View File

@@ -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<pi>), std::numbers::pi_v<float>);
// check_same_type_and_value(get_value<double>(mag<pi>), std::numbers::pi_v<double>);
// check_same_type_and_value(get_value<long double>(mag<pi>), 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")

View File

@@ -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<pi> * one) == "[𝜋]");
static_assert(unit_symbol<usf{.encoding = portable}>(mag<pi> * one) == "[pi]");
static_assert(unit_symbol(mag<pi> * metre) == "[𝜋 m]");
static_assert(unit_symbol<usf{.encoding = portable}>(mag<pi> * metre) == "[pi m]");
static_assert(unit_symbol(mag<2> * mag<pi> * metre) == "[2 𝜋 m]");
static_assert(unit_symbol<usf{.encoding = portable}>(mag<2> * mag<pi> * metre) == "[2 pi m]");
static_assert(unit_symbol<usf{.separator = half_high_dot}>(mag<2> * mag<pi> * 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<pi> * one) == "[1/𝜋]");
static_assert(unit_symbol<usf{.encoding = portable}>(mag<1> / mag<pi> * one) == "[1/pi]");
static_assert(unit_symbol<usf{.solidus = never}>(mag<1> / mag<pi> * one) == "[𝜋⁻¹]");
static_assert(unit_symbol<usf{.encoding = portable, .solidus = never}>(mag<1> / mag<pi> * 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<pi> * metre) == "[1/𝜋 m]");
static_assert(unit_symbol<usf{.encoding = portable}>(mag<1> / mag<pi> * metre) == "[1/pi m]");
static_assert(unit_symbol<usf{.solidus = never}>(mag<1> / mag<pi> * metre) == "[𝜋⁻¹ m]");
static_assert(unit_symbol<usf{.encoding = portable, .solidus = never}>(mag<1> / mag<pi> * 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<pi> * metre) == "[2/𝜋 m]");
static_assert(unit_symbol<usf{.encoding = portable}>(mag<2> / mag<pi> * metre) == "[2/pi m]");
static_assert(unit_symbol<usf{.solidus = never}>(mag<2> / mag<pi> * metre) == "[2 𝜋⁻¹ m]");
static_assert(unit_symbol<usf{.encoding = portable, .solidus = never}>(mag<2> / mag<pi> * metre) == "[2 pi^-1 m]");
static_assert(unit_symbol<usf{.solidus = never, .separator = half_high_dot}>(mag<2> / mag<pi> * 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<pi>)*metre) == "[2⁻¹ 𝜋⁻¹ m]");
static_assert(unit_symbol<usf{.solidus = always}>(mag<1> / (mag<2> * mag<pi>)*metre) == "[1/(2 𝜋) m]");
static_assert(unit_symbol<usf{.encoding = portable, .solidus = always}>(mag<1> / (mag<2> * mag<pi>)*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<pi> * metre) == "[2⁻¹ 𝜋⁻¹ m]");
static_assert(unit_symbol<usf{.solidus = always}>(mag_ratio<1, 2> / mag<pi> * metre) == "[1/(2 𝜋) m]");
static_assert(unit_symbol<usf{.encoding = portable, .solidus = always}>(mag_ratio<1, 2> / mag<pi> * 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<pi> * 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<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<usf{.encoding = portable}>(mag_power<pi, 1, 2> * metre) == "[pi^(1/2) m]");
static_assert(unit_symbol(mag<pi> * mag<e> * one) == "[e 𝜋]");
static_assert(unit_symbol(mag<e> * mag<pi> * one) == "[e 𝜋]");
static_assert(unit_symbol<usf{.encoding = portable}>(mag<pi> * mag<e> * one) == "[e pi]");
static_assert(unit_symbol(mag<pi> / mag<e> * one) == "[𝜋/e]");
static_assert(unit_symbol(mag<1> / mag<e> * mag<pi> * one) == "[𝜋/e]");
static_assert(unit_symbol<usf{.solidus = never}>(mag<pi> / mag<e> * one) == "[𝜋 e⁻¹]");
static_assert(unit_symbol(mag<e> / mag<pi> * one) == "[e/𝜋]");
static_assert(unit_symbol(mag<1> / mag<pi> * mag<e> * one) == "[e/𝜋]");
static_assert(unit_symbol<usf{.solidus = never}>(mag<e> / mag<pi> * one) == "[e 𝜋⁻¹]");
static_assert(unit_symbol(mag<1> / (mag<pi> * mag<e>)*one) == "[e⁻¹ 𝜋⁻¹]");
static_assert(unit_symbol<usf{.solidus = always}>(mag<1> / (mag<pi> * mag<e>)*one) == "[1/(e 𝜋)]");
static_assert(unit_symbol(mag<2> / (mag<pi> * mag<e>)*one) == "[2 e⁻¹ 𝜋⁻¹]");
static_assert(unit_symbol<usf{.solidus = always}>(mag<2> / (mag<pi> * 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]}");

View File

@@ -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<pi> * 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<pi> / 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<pi> / mag<180>);
static_assert(get_canonical_unit(degree).mag == mag<𝜋> / mag<180>);
static_assert(convertible(radian, degree));
static_assert(radian != degree);