forked from mpusz/mp-units
feat: gradian
support added
This commit is contained in:
@@ -40,4 +40,5 @@ int main()
|
||||
std::cout << angle << '\n';
|
||||
std::cout << quantity_cast<rotation>(angle) << '\n';
|
||||
std::cout << quantity_cast<degree>(angle) << '\n';
|
||||
std::cout << quantity_cast<gradian>(angle) << '\n';
|
||||
}
|
||||
|
@@ -40,4 +40,5 @@ int main()
|
||||
std::cout << angle << '\n';
|
||||
std::cout << quantity_cast<rotation>(angle) << '\n';
|
||||
std::cout << quantity_cast<degree>(angle) << '\n';
|
||||
std::cout << quantity_cast<gradian>(angle) << '\n';
|
||||
}
|
||||
|
@@ -49,4 +49,5 @@ int main()
|
||||
std::cout << angle << '\n';
|
||||
std::cout << quantity_cast<rotation>(angle) << '\n';
|
||||
std::cout << quantity_cast<degree>(angle) << '\n';
|
||||
std::cout << quantity_cast<gradian>(angle) << '\n';
|
||||
}
|
||||
|
@@ -35,6 +35,7 @@ namespace units {
|
||||
struct radian : named_unit<radian, "rad"> {};
|
||||
struct rotation : named_scaled_unit<rotation, "rot", mag<2>() * mag_pi, radian> {};
|
||||
struct degree : named_scaled_unit<degree, basic_symbol_text{"°", "deg"}, mag<ratio{1, 360}>(), rotation> {};
|
||||
struct gradian : named_scaled_unit<gradian, basic_symbol_text{"ᵍ", "grad"}, mag<ratio{1, 400}>(), rotation> {};
|
||||
|
||||
template<Unit U = radian>
|
||||
struct dim_angle : base_dimension<"A", U> {};
|
||||
@@ -73,6 +74,14 @@ constexpr auto operator"" _q_deg(unsigned long long l)
|
||||
}
|
||||
constexpr auto operator"" _q_deg(long double l) { return angle<degree, long double>(l); }
|
||||
|
||||
// grad
|
||||
constexpr auto operator"" _q_grad(unsigned long long l)
|
||||
{
|
||||
gsl_ExpectsAudit(std::in_range<std::int64_t>(l));
|
||||
return angle<gradian, std::int64_t>(static_cast<std::int64_t>(l));
|
||||
}
|
||||
constexpr auto operator"" _q_grad(long double l) { return angle<gradian, long double>(l); }
|
||||
|
||||
} // namespace literals
|
||||
|
||||
#endif // UNITS_NO_LITERALS
|
||||
@@ -84,6 +93,7 @@ namespace angle_references {
|
||||
inline constexpr auto rad = reference<dim_angle<>, radian>{};
|
||||
inline constexpr auto rot = reference<dim_angle<>, rotation>{};
|
||||
inline constexpr auto deg = reference<dim_angle<>, degree>{};
|
||||
inline constexpr auto grad = reference<dim_angle<>, gradian>{};
|
||||
|
||||
} // namespace angle_references
|
||||
|
||||
@@ -107,6 +117,8 @@ template<Representation Rep = double>
|
||||
using rot = units::angle<units::rotation, Rep>;
|
||||
template<Representation Rep = double>
|
||||
using deg = units::angle<units::degree, Rep>;
|
||||
template<Representation Rep = double>
|
||||
using grad = units::angle<units::gradian, Rep>;
|
||||
|
||||
} // namespace units::aliases::inline angle
|
||||
|
||||
|
@@ -27,26 +27,19 @@ namespace {
|
||||
|
||||
using namespace units::references;
|
||||
|
||||
static_assert(360. * deg == 1. * rot);
|
||||
static_assert(360 * deg == 1 * rot);
|
||||
static_assert(400 * grad == 1 * rot);
|
||||
static_assert(std::numbers::pi * 2 * rad == 1. * rot);
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace {
|
||||
|
||||
using namespace units::literals;
|
||||
|
||||
static_assert(360._q_deg == 1._q_rot);
|
||||
static_assert(360_q_deg == 1_q_rot);
|
||||
static_assert(400_q_grad == 1_q_rot);
|
||||
static_assert(std::numbers::pi * quantity_cast<double>(2._q_rad) == quantity_cast<double>(1._q_rot));
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace {
|
||||
|
||||
static_assert(units::aliases::deg<>(360.) == units::aliases::rot<>(1.));
|
||||
static_assert(units::aliases::deg<int>(360) == units::aliases::rot<int>(1));
|
||||
static_assert(units::aliases::grad<int>(400) == units::aliases::rot<int>(1));
|
||||
static_assert(std::numbers::pi * units::aliases::rad<>(2.) == units::aliases::rot<>(1.));
|
||||
|
||||
} // namespace
|
||||
|
Reference in New Issue
Block a user