mirror of
https://github.com/mpusz/mp-units.git
synced 2025-06-25 01:01:33 +02:00
warnings.cmake refactored
This commit is contained in:
@ -36,12 +36,12 @@ conan_init(cmake)
|
||||
#enable_clang_tidy()
|
||||
#enable_iwyu()
|
||||
|
||||
# set restrictive compilation warnings
|
||||
set_warnings(TREAT_AS_ERRORS)
|
||||
|
||||
# add project code
|
||||
add_subdirectory(src)
|
||||
|
||||
# set restrictive compilation warnings
|
||||
set_warnings(units)
|
||||
|
||||
# add unit tests
|
||||
enable_testing()
|
||||
add_subdirectory(test)
|
||||
|
Submodule cmake/common updated: f237ec1139...eb5fbd40d1
@ -114,8 +114,8 @@ void example()
|
||||
// Customary Units (double)
|
||||
{
|
||||
using namespace units::physical::international::literals;
|
||||
constexpr Length AUTO distance = 140q_mi; // constructed from a UDL
|
||||
constexpr si::time<si::hour> duration(2); // constructed from a value
|
||||
constexpr Length AUTO distance = 140.q_mi; // constructed from a UDL
|
||||
constexpr si::time<si::hour> duration(2); // constructed from a value
|
||||
|
||||
std::cout << "\nUS Customary Units with 'double' as representation\n";
|
||||
|
||||
@ -151,8 +151,8 @@ void example()
|
||||
// CGS (double)
|
||||
{
|
||||
using namespace units::physical::cgs::literals;
|
||||
constexpr Length AUTO distance = 22'000'000q_cm; // constructed from a UDL
|
||||
constexpr cgs::time<si::hour> duration(2); // constructed from a value
|
||||
constexpr Length AUTO distance = 22'000'000.q_cm; // constructed from a UDL
|
||||
constexpr cgs::time<si::hour> duration(2); // constructed from a value
|
||||
|
||||
std::cout << "\nCGS units with 'double' as representation\n";
|
||||
|
||||
|
@ -93,7 +93,7 @@ void vector_of_quantity_multiply_same()
|
||||
std::cout << "u = " << u << "\n";
|
||||
|
||||
std::cout << "v * u = " << v * u << "\n";
|
||||
std::cout << "2q_m * v = " << 2q_m * v << "\n";
|
||||
std::cout << "2q_m * v = " << 2.q_m * v << "\n";
|
||||
}
|
||||
|
||||
void vector_of_quantity_multiply_different()
|
||||
@ -107,7 +107,7 @@ void vector_of_quantity_multiply_different()
|
||||
std::cout << "u = " << u << "\n";
|
||||
|
||||
std::cout << "v * u = " << v * u << "\n";
|
||||
std::cout << "2q_N * u = " << 2q_N * u << "\n";
|
||||
std::cout << "2q_N * u = " << 2.q_N * u << "\n";
|
||||
std::cout << "2 * u = " << 2 * u << "\n";
|
||||
}
|
||||
|
||||
@ -162,7 +162,7 @@ void matrix_of_quantity_multiply_same()
|
||||
std::cout << "u =\n" << u << "\n";
|
||||
|
||||
std::cout << "v * u =\n" << v * u << "\n";
|
||||
std::cout << "2q_m * u =\n" << 2q_m * u << "\n";
|
||||
std::cout << "2q_m * u =\n" << 2.q_m * u << "\n";
|
||||
}
|
||||
|
||||
void matrix_of_quantity_multiply_different()
|
||||
@ -176,7 +176,7 @@ void matrix_of_quantity_multiply_different()
|
||||
std::cout << "u =\n" << u << "\n";
|
||||
|
||||
std::cout << "v * u =\n" << v * u << "\n";
|
||||
std::cout << "2q_N * u =\n" << 2q_N * u << "\n";
|
||||
std::cout << "2q_N * u =\n" << 2.q_N * u << "\n";
|
||||
std::cout << "2 * u =\n" << 2 * u << "\n";
|
||||
}
|
||||
|
||||
@ -235,7 +235,7 @@ void quantity_of_vector_multiply_same()
|
||||
std::cout << "u = " << u << "\n";
|
||||
|
||||
std::cout << "v * u = " << v * u << "\n";
|
||||
std::cout << "2q_m * v = " << 2q_m * v << "\n";
|
||||
std::cout << "2q_m * v = " << 2.q_m * v << "\n";
|
||||
}
|
||||
|
||||
void quantity_of_vector_multiply_different()
|
||||
@ -249,7 +249,7 @@ void quantity_of_vector_multiply_different()
|
||||
std::cout << "u = " << u << "\n";
|
||||
|
||||
std::cout << "v * u = " << v * u << "\n";
|
||||
std::cout << "2q_N * u = " << 2q_N * u << "\n";
|
||||
std::cout << "2q_N * u = " << 2.q_N * u << "\n";
|
||||
std::cout << "2 * u = " << 2 * u << "\n";
|
||||
}
|
||||
|
||||
@ -307,7 +307,7 @@ void quantity_of_matrix_multiply_same()
|
||||
std::cout << "u =\n" << u << "\n";
|
||||
|
||||
std::cout << "v * u =\n" << v * u << "\n";
|
||||
std::cout << "2q_m * u =\n" << 2q_m * u << "\n";
|
||||
std::cout << "2q_m * u =\n" << 2.q_m * u << "\n";
|
||||
}
|
||||
|
||||
void quantity_of_matrix_multiply_different()
|
||||
@ -321,7 +321,7 @@ void quantity_of_matrix_multiply_different()
|
||||
std::cout << "u =\n" << u << "\n";
|
||||
|
||||
std::cout << "v * u =\n" << v * u << "\n";
|
||||
std::cout << "2q_N * u =\n" << 2q_N * u << "\n";
|
||||
std::cout << "2q_N * u =\n" << 2.q_N * u << "\n";
|
||||
std::cout << "2 * u =\n" << 2 * u << "\n";
|
||||
}
|
||||
|
||||
|
@ -346,9 +346,9 @@ template<typename D1, typename U1, typename Rep1, typename D2, typename U2, type
|
||||
using common_rep = decltype(lhs.count() * rhs.count());
|
||||
using ratio = ratio_multiply<typename U1::ratio, typename U2::ratio>;
|
||||
if constexpr (treat_as_floating_point<common_rep>) {
|
||||
return common_rep(lhs.count()) * common_rep(rhs.count()) * common_rep(ratio::num) * fpow10(ratio::exp) / common_rep(ratio::den);
|
||||
return lhs.count() * rhs.count() * static_cast<common_rep>(ratio::num * fpow10(ratio::exp)) / static_cast<common_rep>(ratio::den);
|
||||
} else {
|
||||
return common_rep(lhs.count()) * common_rep(rhs.count()) * common_rep(ratio::num) * ipow10(ratio::exp) / common_rep(ratio::den);
|
||||
return lhs.count() * rhs.count() * static_cast<common_rep>(ratio::num * ipow10(ratio::exp)) / static_cast<common_rep>(ratio::den);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,19 +41,19 @@ constexpr std::intmax_t ipow10(std::intmax_t exp)
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
constexpr long double fpow10(std::intmax_t exp)
|
||||
template<typename Rep>
|
||||
constexpr Rep fpow10(std::intmax_t exp)
|
||||
{
|
||||
if (exp == 0) return 1.0L;
|
||||
long double result = 1.0L;
|
||||
if (exp == 0) return Rep(1.0);
|
||||
Rep result = Rep(1.0);
|
||||
if (exp < 0) {
|
||||
while (exp < 0) {
|
||||
result /= 10.0L;
|
||||
result = result / Rep(10.0);
|
||||
++exp;
|
||||
}
|
||||
} else {
|
||||
while (exp > 0) {
|
||||
result *= 10.0L;
|
||||
result = result * Rep(10.0);
|
||||
--exp;
|
||||
}
|
||||
}
|
||||
@ -86,7 +86,7 @@ struct quantity_cast_impl<To, CRatio, CRep, true, true, false> {
|
||||
static constexpr To cast(const Q& q)
|
||||
{
|
||||
if constexpr (treat_as_floating_point<CRep>) {
|
||||
return To(static_cast<To::rep>(static_cast<CRep>(q.count()) * static_cast<CRep>(fpow10(CRatio::exp))));
|
||||
return To(static_cast<To::rep>(static_cast<CRep>(q.count()) * static_cast<CRep>(fpow10<CRep>(CRatio::exp))));
|
||||
} else {
|
||||
if constexpr (CRatio::exp > 0) {
|
||||
return To(static_cast<To::rep>(static_cast<CRep>(q.count()) * static_cast<CRep>(ipow10(CRatio::exp))));
|
||||
@ -116,7 +116,7 @@ struct quantity_cast_impl<To, CRatio, CRep, false, false, false> {
|
||||
{
|
||||
if constexpr (treat_as_floating_point<CRep>) {
|
||||
return To(static_cast<To::rep>(static_cast<CRep>(q.count()) *
|
||||
static_cast<CRep>(fpow10(CRatio::exp)) *
|
||||
static_cast<CRep>(fpow10<CRep>(CRatio::exp)) *
|
||||
(static_cast<CRep>(CRatio::num) /
|
||||
static_cast<CRep>(CRatio::den))));
|
||||
} else {
|
||||
@ -151,7 +151,7 @@ struct quantity_cast_impl<To, CRatio, CRep, true, false, false> {
|
||||
static constexpr To cast(const Q& q)
|
||||
{
|
||||
if constexpr (treat_as_floating_point<CRep>) {
|
||||
return To(static_cast<To::rep>(static_cast<CRep>(q.count()) * static_cast<CRep>(fpow10(CRatio::exp)) * (CRep{1} / static_cast<CRep>(CRatio::den))));
|
||||
return To(static_cast<To::rep>(static_cast<CRep>(q.count()) * static_cast<CRep>(fpow10<CRep>(CRatio::exp)) * (CRep{1} / static_cast<CRep>(CRatio::den))));
|
||||
} else {
|
||||
if constexpr (CRatio::exp > 0) {
|
||||
return To(static_cast<To::rep>(static_cast<CRep>(q.count()) * static_cast<CRep>(ipow10(CRatio::exp)) / static_cast<CRep>(CRatio::den)));
|
||||
@ -178,7 +178,7 @@ struct quantity_cast_impl<To, CRatio, CRep, false, true, false> {
|
||||
static constexpr To cast(const Q& q)
|
||||
{
|
||||
if constexpr (treat_as_floating_point<CRep>) {
|
||||
return To(static_cast<To::rep>(static_cast<CRep>(q.count()) * static_cast<CRep>(CRatio::num) * static_cast<CRep>(fpow10(CRatio::exp))));
|
||||
return To(static_cast<To::rep>(static_cast<CRep>(q.count()) * static_cast<CRep>(CRatio::num) * static_cast<CRep>(fpow10<CRep>(CRatio::exp))));
|
||||
} else {
|
||||
if constexpr (CRatio::exp > 0) {
|
||||
return To(static_cast<To::rep>(static_cast<CRep>(q.count()) * static_cast<CRep>(CRatio::num) * static_cast<CRep>(ipow10(CRatio::exp))));
|
||||
@ -196,7 +196,7 @@ struct quantity_cast_impl<To, CRatio, CRep, true, true, false> {
|
||||
static constexpr To cast(const Q& q)
|
||||
{
|
||||
if constexpr (treat_as_floating_point<CRep>) {
|
||||
return To(static_cast<To::rep>(q.count() * fpow10(CRatio::exp)));
|
||||
return To(static_cast<To::rep>(q.count() * fpow10<CRep>(CRatio::exp)));
|
||||
} else {
|
||||
if constexpr (CRatio::exp > 0) {
|
||||
return To(static_cast<To::rep>(q.count() * ipow10(CRatio::exp)));
|
||||
@ -223,7 +223,7 @@ struct quantity_cast_impl<To, CRatio, CRep, false, false, false> {
|
||||
static constexpr To cast(const Q& q)
|
||||
{
|
||||
if constexpr (treat_as_floating_point<CRep>) {
|
||||
return To(static_cast<To::rep>(q.count() * fpow10(CRatio::exp) * (CRatio::num / CRatio::den)));
|
||||
return To(static_cast<To::rep>(q.count() * fpow10<CRep>(CRatio::exp) * (CRatio::num / CRatio::den)));
|
||||
} else {
|
||||
if constexpr (CRatio::exp > 0) {
|
||||
return To(static_cast<To::rep>(q.count() * CRatio::num * ipow10(CRatio::exp) / CRatio::den));
|
||||
@ -250,7 +250,7 @@ struct quantity_cast_impl<To, CRatio, CRep, true, false, false> {
|
||||
static constexpr To cast(const Q& q)
|
||||
{
|
||||
if constexpr (treat_as_floating_point<CRep>) {
|
||||
return To(static_cast<To::rep>(q.count() * fpow10(CRatio::exp) / CRatio::den));
|
||||
return To(static_cast<To::rep>(q.count() * fpow10<CRep>(CRatio::exp) / CRatio::den));
|
||||
} else {
|
||||
if constexpr (CRatio::exp > 0) {
|
||||
return To(static_cast<To::rep>(q.count() * ipow10(CRatio::exp) / CRatio::den));
|
||||
@ -277,7 +277,7 @@ struct quantity_cast_impl<To, CRatio, CRep, false, true, false> {
|
||||
static constexpr To cast(const Q& q)
|
||||
{
|
||||
if constexpr (treat_as_floating_point<CRep>) {
|
||||
return To(static_cast<To::rep>(q.count() * CRatio::num * fpow10(CRatio::exp)));
|
||||
return To(static_cast<To::rep>(q.count() * CRatio::num * fpow10<CRep>(CRatio::exp)));
|
||||
} else {
|
||||
if constexpr (CRatio::exp > 0) {
|
||||
return To(static_cast<To::rep>(q.count() * CRatio::num * ipow10(CRatio::exp)));
|
||||
|
@ -448,7 +448,7 @@ TEST_CASE("operator<< on a quantity", "[text][ostream][fmt]")
|
||||
|
||||
SECTION("CGS base units")
|
||||
{
|
||||
const auto q = 2q_s * cgs::length<cgs::centimetre>(2) * cgs::mass<cgs::gram>(2);
|
||||
const auto q = 2.q_s * cgs::length<cgs::centimetre>(2) * cgs::mass<cgs::gram>(2);
|
||||
os << q;
|
||||
|
||||
SECTION("iostream")
|
||||
@ -533,7 +533,7 @@ TEST_CASE("operator<< on a quantity", "[text][ostream][fmt]")
|
||||
|
||||
SECTION("CGS base units")
|
||||
{
|
||||
const auto q = 2q_s * cgs::length<si::metre>(2) * cgs::mass<si::kilogram>(2);
|
||||
const auto q = 2.q_s * cgs::length<si::metre>(2) * cgs::mass<si::kilogram>(2);
|
||||
os << q;
|
||||
|
||||
SECTION("iostream")
|
||||
|
@ -130,8 +130,8 @@ static_assert(quantity_cast<cgs::length<cgs::centimetre>>(si::length<si::metre>(
|
||||
|
||||
// static_assert(200q_cm * si::length<si::metre>(2) == si::area<si::square_metre>(4)); // should not compile (unknown dimension)
|
||||
|
||||
static_assert(quantity_cast<si::dim_length>(200q_cm) * si::length<si::metre>(2) == si::area<si::square_metre>(4));
|
||||
static_assert(200q_cm * quantity_cast<cgs::dim_length>(si::length<si::metre>(2)) == 40'000q_cm2);
|
||||
static_assert(quantity_cast<si::dim_length>(200.q_cm) * si::length<si::metre>(2) == si::area<si::square_metre>(4));
|
||||
static_assert(200.q_cm * quantity_cast<cgs::dim_length>(si::length<si::metre>(2)) == 40'000q_cm2);
|
||||
|
||||
// TODO Add support for quantity_cast on an unknown_dimension?
|
||||
// static_assert(quantity_cast<si::area<si::square_metre>>(200q_cm * si::length<si::metre>(2)) == si::area<si::square_metre>(4));
|
||||
@ -144,7 +144,7 @@ static_assert(200q_cm * quantity_cast<cgs::dim_length>(si::length<si::metre>(2))
|
||||
// static_assert(si::area<si::square_metre>(4) / 200q_cm == si::length<si::metre>(2)); // should not compile (unknown dimension)
|
||||
|
||||
static_assert(si::area<si::square_metre>(4) / quantity_cast<si::length<si::metre>>(200q_cm) == si::length<si::metre>(2));
|
||||
static_assert(quantity_cast<cgs::area<cgs::square_centimetre>>(si::area<si::square_metre>(4)) / 200q_cm == 200q_cm);
|
||||
static_assert(quantity_cast<cgs::area<cgs::square_centimetre>>(si::area<si::square_metre>(4)) / 200.q_cm == 200q_cm);
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user