Skip to content

feat: add floor/ceil/round for quantity_point#811

Open
HazardyKnusperkeks wants to merge 2 commits into
mpusz:masterfrom
FrankeCoffee:round
Open

feat: add floor/ceil/round for quantity_point#811
HazardyKnusperkeks wants to merge 2 commits into
mpusz:masterfrom
FrankeCoffee:round

Conversation

@HazardyKnusperkeks

Copy link
Copy Markdown
Contributor

📋 Pull Request Description

We have the math functions for quantity, but we also want them for quantity_point, this PR adds them.

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not
    work as expected)
  • 📚 Documentation update
  • 🔧 Build system / CI changes
  • 🧪 Test improvements
  • ♻️ Code refactoring
  • 🎨 Code style improvements

🔗 Related Issues

Closes #807

📝 Changes Made

Added the the overloads and tests.

🌟 Additional Context

✅ Checklist

  • I have read the Contributing Guidelines
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the project's documentation to cover the modified or new functionality
    (if this change affects user-facing features)

By submitting this pull request, I confirm that my contribution is made under the terms
of the project's MIT license.

@HazardyKnusperkeks

Copy link
Copy Markdown
Contributor Author

In 2.5.0 this worked like a charm, now I have some troubles, I think they come from 982fc52.

The cruxial point is, how can I use force_in for integer degree celsius to degree fahrenheit? @mpusz if you can give me a hint, I can continue on the PR.

Lengthy compiler errors ``` In file included from ../../src/core/include/mp-units/math.h:29, from ../../test/runtime/math_test.cpp:34: ../../src/core/include/mp-units/framework/quantity_point.h: In instantiation of ‘constexpr mp_units::quantity_point::quantity_point(const QP&) [with QP = mp_units::quantity_point; auto [requires mp_units::Reference<, >] R = mp_units::usc::degree_Fahrenheit(); auto [requires mp_units::PointOriginFor<, get_quantity_spec(R)>] PO = mp_units::si::ice_point(); Rep = int]’: ../../src/core/include/mp-units/math.h:371:12: required from here 371 | return res; | ^~~ ../../test/runtime/math_test.cpp:406:7: in ‘constexpr’ expansion of ‘mp_units::floor(), si::ice_point(), int>(mp_units::point()>.mp_units::point_ >::operator()(-125))’ ../../src/core/include/mp-units/framework/quantity_point.h:587:49: error: no matching function for call to ‘mp_units::quantity::quantity()’ 587 | return quantity_type{qp - point_origin}; | ^ ../../src/core/include/mp-units/framework/quantity_point.h:587:49: note: there are 12 candidates In file included from ../../test/runtime/almost_equals.h:30, from ../../test/runtime/math_test.cpp:23: ../../src/core/include/mp-units/framework/quantity.h:553:85: note: candidate 1: ‘template requires (QuantityLike) && (QuantityConstructibleFrom, mp_units::quantity::reference, typename mp_units::quantity_like_traits::rep> >) constexpr mp_units::quantity::quantity(const Q&) [with auto [requires mp_units::Reference<, >] R = mp_units::usc::degree_Fahrenheit(); Rep = int]’ 553 | !std::convertible_to, quantity>) quantity(const Q& q) : | ^~~~~~~~ ../../src/core/include/mp-units/framework/quantity.h:553:85: note: template argument deduction/substitution failed: ../../src/core/include/mp-units/framework/quantity.h:553:85: note: constraints not satisfied In file included from ../../src/core/include/mp-units/bits/sudo_cast.h:26, from ../../src/core/include/mp-units/framework/quantity.h:28: ../../src/core/include/mp-units/framework/quantity_concepts.h: In substitution of ‘template requires (QuantityLike) && (QuantityConstructibleFrom, mp_units::quantity::reference, typename mp_units::quantity_like_traits::rep> >) constexpr mp_units::quantity::quantity(const Q&) [with Q = mp_units::quantity, mp_units::si::milli_ >(), int>]’: ../../src/core/include/mp-units/framework/quantity_point.h:587:49: required from ‘constexpr mp_units::quantity_point::quantity_point(const QP&) [with QP = mp_units::quantity_point; auto [requires mp_units::Reference<, >] R = mp_units::usc::degree_Fahrenheit(); auto [requires mp_units::PointOriginFor<, get_quantity_spec(R)>] PO = mp_units::si::ice_point(); Rep = int]’ 587 | return quantity_type{qp - point_origin}; | ^ ../../src/core/include/mp-units/math.h:371:12: required from here 371 | return res; | ^~~ ../../src/core/include/mp-units/framework/quantity_concepts.h:86:9: required for the satisfaction of ‘QuantityLike’ [with Q = mp_units::quantity, mp_units::si::milli_ >{}, int>] ../../src/core/include/mp-units/framework/quantity_concepts.h:86:24: note: the expression ‘!(Quantity) [with T = mp_units::quantity, mp_units::si::milli_ >{}, int>]’ evaluated to ‘false’ 86 | concept QuantityLike = !Quantity && detail::QuantityLikeImpl && requires { | ^~~~~~~~~~~~ ../../src/core/include/mp-units/framework/quantity_point.h: In instantiation of ‘constexpr mp_units::quantity_point::quantity_point(const QP&) [with QP = mp_units::quantity_point; auto [requires mp_units::Reference<, >] R = mp_units::usc::degree_Fahrenheit(); auto [requires mp_units::PointOriginFor<, get_quantity_spec(R)>] PO = mp_units::si::ice_point(); Rep = int]’: ../../src/core/include/mp-units/math.h:371:12: required from here 371 | return res; | ^~~ ../../src/core/include/mp-units/framework/quantity.h:544:5: note: candidate 2: ‘template requires (QuantityConstructibleFrom, mp_units::quantity >) && !equivalent(mp_units::quantity::unit, get_unit(R2)) constexpr mp_units::quantity::quantity(const mp_units::quantity&) [with auto R2 = R2; auto [requires mp_units::Reference<, >] R = mp_units::usc::degree_Fahrenheit(); Rep = int]’ 544 | quantity(const quantity& q) : | ^~~~~~~~ ../../src/core/include/mp-units/framework/quantity.h:544:5: note: template argument deduction/substitution failed: ../../src/core/include/mp-units/framework/quantity.h:544:5: note: constraints not satisfied ../../src/core/include/mp-units/framework/quantity_point.h: In substitution of ‘template requires (QuantityConstructibleFrom, mp_units::quantity >) && !equivalent(mp_units::quantity::unit, get_unit(R2)) constexpr mp_units::quantity::quantity(const mp_units::quantity&) [with auto R2 = mp_units::common_unit, mp_units::si::milli_ >(); Rep2 = int]’: ../../src/core/include/mp-units/framework/quantity_point.h:587:49: required from ‘constexpr mp_units::quantity_point::quantity_point(const QP&) [with QP = mp_units::quantity_point; auto [requires mp_units::Reference<, >] R = mp_units::usc::degree_Fahrenheit(); auto [requires mp_units::PointOriginFor<, get_quantity_spec(R)>] PO = mp_units::si::ice_point(); Rep = int]’ 587 | return quantity_type{qp - point_origin}; | ^ ../../src/core/include/mp-units/math.h:371:12: required from here 371 | return res; | ^~~ ../../test/runtime/math_test.cpp:406:7: in ‘constexpr’ expansion of ‘mp_units::floor(), si::ice_point(), int>(mp_units::point()>.mp_units::point_ >::operator()(-125))’ ../../src/core/include/mp-units/framework/quantity.h:99:9: required for the satisfaction of ‘ImplicitConversion’ [with QFrom = mp_units::quantity, mp_units::si::milli_ >{}, int>; QTo = mp_units::quantity] ../../src/core/include/mp-units/framework/quantity.h:105:9: required for the satisfaction of ‘QuantityConstructibleFrom, mp_units::quantity >’ [with R = mp_units::usc::degree_Fahrenheit{}; Rep = int; R2 = mp_units::common_unit, mp_units::si::milli_ >{}; Rep2 = int] ../../src/core/include/mp-units/framework/quantity.h:100:95: note: no operand of the disjunction is satisfied 100 | (mp_units::implicitly_scalable || | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~ 101 | unsatisfied<"Conversion from '{}' as '{}' to '{}' as '{}' is truncating">( | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 102 | unit_symbol(FromUnit), type_name(), unit_symbol(ToUnit), type_name())); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../src/core/include/mp-units/framework/quantity.h:100:41: note: the operand ‘implicitly_scalable’ is unsatisfied because 100 | (mp_units::implicitly_scalable || | ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 101 | unsatisfied<"Conversion from '{}' as '{}' to '{}' as '{}' is truncating">( | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 102 | unit_symbol(FromUnit), type_name(), unit_symbol(ToUnit), type_name())); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../src/core/include/mp-units/framework/quantity.h:99:9: required for the satisfaction of ‘ImplicitConversion’ [with QFrom = mp_units::quantity, mp_units::si::milli_ >{}, int>; QTo = mp_units::quantity] ../../src/core/include/mp-units/framework/quantity.h:105:9: required for the satisfaction of ‘QuantityConstructibleFrom, mp_units::quantity >’ [with R = mp_units::usc::degree_Fahrenheit{}; Rep = int; R2 = mp_units::common_unit, mp_units::si::milli_ >{}; Rep2 = int] ../../src/core/include/mp-units/framework/quantity.h:100:41: note: the expression ‘implicitly_scalable [with FromUnit = mp_units::quantity, mp_units::si::milli_ >{}, int>::unit; FromRep = int; ToUnit = mp_units::quantity::unit; ToRep = int]’ evaluated to ‘false’ 100 | (mp_units::implicitly_scalable || | ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../src/core/include/mp-units/framework/quantity.h:101:104: note: the operand ‘unsatisfied<"Conversion from \'{}\' as \'{}\' to \'{}\' as \'{}\' is truncating">(mp_units::unit_symbol(FromUnit), type_name(), mp_units::unit_symbol(ToUnit), type_name())’ is unsatisfied because 100 | (mp_units::implicitly_scalable || | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 101 | unsatisfied<"Conversion from '{}' as '{}' to '{}' as '{}' is truncating">( | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ 102 | unit_symbol(FromUnit), type_name(), unit_symbol(ToUnit), type_name())); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../test/runtime/math_test.cpp:406:7: in ‘constexpr’ expansion of ‘mp_units::floor(), si::ice_point(), int>(mp_units::point()>.mp_units::point_ >::operator()(-125))’ ../../src/core/include/mp-units/framework/quantity.h:99:9: required for the satisfaction of ‘ImplicitConversion’ [with QFrom = mp_units::quantity, mp_units::si::milli_ >{}, int>; QTo = mp_units::quantity] ../../src/core/include/mp-units/framework/quantity.h:105:9: required for the satisfaction of ‘QuantityConstructibleFrom, mp_units::quantity >’ [with R = mp_units::usc::degree_Fahrenheit{}; Rep = int; R2 = mp_units::common_unit, mp_units::si::milli_ >{}; Rep2 = int] ../../src/core/include/mp-units/framework/quantity.h:101:104: note: the expression ‘(unsatisfied<"Conversion from \'{}\' as \'{}\' to \'{}\' as \'{}\' is truncating">)(mp_units::unit_symbol(FromUnit), (type_name)(), mp_units::unit_symbol(ToUnit), (type_name)()) [with FromUnit = mp_units::quantity, mp_units::si::milli_ >{}, int>::unit; FromRep = int; ToUnit = mp_units::quantity::unit; ToRep = int]’ evaluated to ‘false’ 101 | unsatisfied<"Conversion from '{}' as '{}' to '{}' as '{}' is truncating">( | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ 102 | unit_symbol(FromUnit), type_name(), unit_symbol(ToUnit), type_name())); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../src/core/include/mp-units/framework/quantity_point.h: In instantiation of ‘constexpr mp_units::quantity_point::quantity_point(const QP&) [with QP = mp_units::quantity_point; auto [requires mp_units::Reference<, >] R = mp_units::usc::degree_Fahrenheit(); auto [requires mp_units::PointOriginFor<, get_quantity_spec(R)>] PO = mp_units::si::ice_point(); Rep = int]’: ../../src/core/include/mp-units/math.h:371:12: required from here 371 | return res; | ^~~ ../../src/core/include/mp-units/framework/quantity.h:533:5: note: candidate 3: ‘template requires (QuantityConstructibleFrom, mp_units::quantity >) && equivalent(mp_units::quantity::unit, get_unit(R2)) constexpr mp_units::quantity::quantity(const mp_units::quantity&) [with auto R2 = R2; auto [requires mp_units::Reference<, >] R = mp_units::usc::degree_Fahrenheit(); Rep = int]’ 533 | quantity(const quantity& q) : | ^~~~~~~~ ../../src/core/include/mp-units/framework/quantity.h:533:5: note: template argument deduction/substitution failed: ../../src/core/include/mp-units/framework/quantity.h:533:5: note: constraints not satisfied ../../src/core/include/mp-units/framework/quantity_point.h: In substitution of ‘template requires (QuantityConstructibleFrom, mp_units::quantity >) && equivalent(mp_units::quantity::unit, get_unit(R2)) constexpr mp_units::quantity::quantity(const mp_units::quantity&) [with auto R2 = mp_units::common_unit, mp_units::si::milli_ >(); Rep2 = int]’: ../../src/core/include/mp-units/framework/quantity_point.h:587:49: required from ‘constexpr mp_units::quantity_point::quantity_point(const QP&) [with QP = mp_units::quantity_point; auto [requires mp_units::Reference<, >] R = mp_units::usc::degree_Fahrenheit(); auto [requires mp_units::PointOriginFor<, get_quantity_spec(R)>] PO = mp_units::si::ice_point(); Rep = int]’ 587 | return quantity_type{qp - point_origin}; | ^ ../../src/core/include/mp-units/math.h:371:12: required from here 371 | return res; | ^~~ ../../test/runtime/math_test.cpp:406:7: in ‘constexpr’ expansion of ‘mp_units::floor(), si::ice_point(), int>(mp_units::point()>.mp_units::point_ >::operator()(-125))’ ../../src/core/include/mp-units/framework/quantity.h:99:9: required for the satisfaction of ‘ImplicitConversion’ [with QFrom = mp_units::quantity, mp_units::si::milli_ >{}, int>; QTo = mp_units::quantity] ../../src/core/include/mp-units/framework/quantity.h:105:9: required for the satisfaction of ‘QuantityConstructibleFrom, mp_units::quantity >’ [with R = mp_units::usc::degree_Fahrenheit{}; Rep = int; R2 = mp_units::common_unit, mp_units::si::milli_ >{}; Rep2 = int] ../../src/core/include/mp-units/framework/quantity.h:100:95: note: no operand of the disjunction is satisfied 100 | (mp_units::implicitly_scalable || | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~ 101 | unsatisfied<"Conversion from '{}' as '{}' to '{}' as '{}' is truncating">( | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 102 | unit_symbol(FromUnit), type_name(), unit_symbol(ToUnit), type_name())); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../src/core/include/mp-units/framework/quantity.h:100:41: note: the operand ‘implicitly_scalable’ is unsatisfied because 100 | (mp_units::implicitly_scalable || | ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 101 | unsatisfied<"Conversion from '{}' as '{}' to '{}' as '{}' is truncating">( | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 102 | unit_symbol(FromUnit), type_name(), unit_symbol(ToUnit), type_name())); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../src/core/include/mp-units/framework/quantity.h:99:9: required for the satisfaction of ‘ImplicitConversion’ [with QFrom = mp_units::quantity, mp_units::si::milli_ >{}, int>; QTo = mp_units::quantity] ../../src/core/include/mp-units/framework/quantity.h:105:9: required for the satisfaction of ‘QuantityConstructibleFrom, mp_units::quantity >’ [with R = mp_units::usc::degree_Fahrenheit{}; Rep = int; R2 = mp_units::common_unit, mp_units::si::milli_ >{}; Rep2 = int] ../../src/core/include/mp-units/framework/quantity.h:100:41: note: the expression ‘implicitly_scalable [with FromUnit = mp_units::quantity, mp_units::si::milli_ >{}, int>::unit; FromRep = int; ToUnit = mp_units::quantity::unit; ToRep = int]’ evaluated to ‘false’ 100 | (mp_units::implicitly_scalable || | ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../src/core/include/mp-units/framework/quantity.h:101:104: note: the operand ‘unsatisfied<"Conversion from \'{}\' as \'{}\' to \'{}\' as \'{}\' is truncating">(mp_units::unit_symbol(FromUnit), type_name(), mp_units::unit_symbol(ToUnit), type_name())’ is unsatisfied because 100 | (mp_units::implicitly_scalable || | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 101 | unsatisfied<"Conversion from '{}' as '{}' to '{}' as '{}' is truncating">( | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ 102 | unit_symbol(FromUnit), type_name(), unit_symbol(ToUnit), type_name())); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../test/runtime/math_test.cpp:406:7: in ‘constexpr’ expansion of ‘mp_units::floor(), si::ice_point(), int>(mp_units::point()>.mp_units::point_ >::operator()(-125))’ ../../src/core/include/mp-units/framework/quantity.h:99:9: required for the satisfaction of ‘ImplicitConversion’ [with QFrom = mp_units::quantity, mp_units::si::milli_ >{}, int>; QTo = mp_units::quantity] ../../src/core/include/mp-units/framework/quantity.h:105:9: required for the satisfaction of ‘QuantityConstructibleFrom, mp_units::quantity >’ [with R = mp_units::usc::degree_Fahrenheit{}; Rep = int; R2 = mp_units::common_unit, mp_units::si::milli_ >{}; Rep2 = int] ../../src/core/include/mp-units/framework/quantity.h:101:104: note: the expression ‘(unsatisfied<"Conversion from \'{}\' as \'{}\' to \'{}\' as \'{}\' is truncating">)(mp_units::unit_symbol(FromUnit), (type_name)(), mp_units::unit_symbol(ToUnit), (type_name)()) [with FromUnit = mp_units::quantity, mp_units::si::milli_ >{}, int>::unit; FromRep = int; ToUnit = mp_units::quantity::unit; ToRep = int]’ evaluated to ‘false’ 101 | unsatisfied<"Conversion from '{}' as '{}' to '{}' as '{}' is truncating">( | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ 102 | unit_symbol(FromUnit), type_name(), unit_symbol(ToUnit), type_name())); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../src/core/include/mp-units/framework/quantity_point.h: In instantiation of ‘constexpr mp_units::quantity_point::quantity_point(const QP&) [with QP = mp_units::quantity_point; auto [requires mp_units::Reference<, >] R = mp_units::usc::degree_Fahrenheit(); auto [requires mp_units::PointOriginFor<, get_quantity_spec(R)>] PO = mp_units::si::ice_point(); Rep = int]’: ../../src/core/include/mp-units/math.h:371:12: required from here 371 | return res; | ^~~ ../../src/core/include/mp-units/framework/quantity.h:520:87: note: candidate 4: ‘template requires (ExplicitFromNumber::reference>) && !(RepConstructibleFrom) constexpr mp_units::quantity::quantity(Value) [with auto [requires mp_units::Reference<, >] R = mp_units::usc::degree_Fahrenheit(); Rep = int]’ (deleted) 520 | !mp_units::implicitly_convertible(quantity_spec, dimensionless)) quantity(Value val) | ^~~~~~~~ ../../src/core/include/mp-units/framework/quantity.h:520:87: note: template argument deduction/substitution failed: ../../src/core/include/mp-units/framework/quantity.h:520:87: note: constraints not satisfied ../../src/core/include/mp-units/framework/quantity.h: In substitution of ‘template requires (ExplicitFromNumber::reference>) && !(RepConstructibleFrom) constexpr mp_units::quantity::quantity(Value) [with Value = mp_units::quantity, mp_units::si::milli_ >(), int>]’: ../../src/core/include/mp-units/framework/quantity_point.h:587:49: required from ‘constexpr mp_units::quantity_point::quantity_point(const QP&) [with QP = mp_units::quantity_point; auto [requires mp_units::Reference<, >] R = mp_units::usc::degree_Fahrenheit(); auto [requires mp_units::PointOriginFor<, get_quantity_spec(R)>] PO = mp_units::si::ice_point(); Rep = int]’ 587 | return quantity_type{qp - point_origin}; | ^ ../../src/core/include/mp-units/math.h:371:12: required from here 371 | return res; | ^~~ ../../test/runtime/math_test.cpp:406:7: in ‘constexpr’ expansion of ‘mp_units::floor(), si::ice_point(), int>(mp_units::point()>.mp_units::point_ >::operator()(-125))’ ../../src/core/include/mp-units/framework/quantity.h:118:9: required for the satisfaction of ‘UnitOne’ [with R = mp_units::quantity::reference] ../../src/core/include/mp-units/framework/quantity.h:122:9: required for the satisfaction of ‘ExplicitFromNumber’ [with R = mp_units::usc::degree_Fahrenheit{}; Rep = int] ../../src/core/include/mp-units/framework/quantity.h:119:30: note: the expression ‘equivalent(get_unit(R), mp_units::one) [with R = mp_units::quantity::reference]’ evaluated to ‘false’ 119 | (equivalent(get_unit(R), one) && detail::get_associated_quantity(get_unit(R)) == dimensionless); | ~~~~~~~~~~^~~~~~~~~~~~~~~~~~ ../../src/core/include/mp-units/framework/quantity_point.h: In instantiation of ‘constexpr mp_units::quantity_point::quantity_point(const QP&) [with QP = mp_units::quantity_point; auto [requires mp_units::Reference<, >] R = mp_units::usc::degree_Fahrenheit(); auto [requires mp_units::PointOriginFor<, get_quantity_spec(R)>] PO = mp_units::si::ice_point(); Rep = int]’: ../../src/core/include/mp-units/math.h:371:12: required from here 371 | return res; | ^~~ ../../src/core/include/mp-units/framework/quantity.h:513:22: note: candidate 5: ‘template requires (ExplicitFromNumber::reference>) && (RepConstructibleFrom) && !(convertible_to) constexpr mp_units::quantity::quantity(Value) [with auto [requires mp_units::Reference<, >] R = mp_units::usc::degree_Fahrenheit(); Rep = int]’ 513 | constexpr explicit quantity(Value val) : numerical_value_is_an_implementation_detail_(std::move(val)) | ^~~~~~~~ ../../src/core/include/mp-units/framework/quantity.h:513:22: note: template argument deduction/substitution failed: ../../src/core/include/mp-units/framework/quantity.h:513:22: note: constraints not satisfied ../../src/core/include/mp-units/framework/quantity.h: In substitution of ‘template requires (ExplicitFromNumber::reference>) && (RepConstructibleFrom) && !(convertible_to) constexpr mp_units::quantity::quantity(Value) [with Value = mp_units::quantity, mp_units::si::milli_ >(), int>]’: ../../src/core/include/mp-units/framework/quantity_point.h:587:49: required from ‘constexpr mp_units::quantity_point::quantity_point(const QP&) [with QP = mp_units::quantity_point; auto [requires mp_units::Reference<, >] R = mp_units::usc::degree_Fahrenheit(); auto [requires mp_units::PointOriginFor<, get_quantity_spec(R)>] PO = mp_units::si::ice_point(); Rep = int]’ 587 | return quantity_type{qp - point_origin}; | ^ ../../src/core/include/mp-units/math.h:371:12: required from here 371 | return res; | ^~~ ../../test/runtime/math_test.cpp:406:7: in ‘constexpr’ expansion of ‘mp_units::floor(), si::ice_point(), int>(mp_units::point()>.mp_units::point_ >::operator()(-125))’ ../../src/core/include/mp-units/framework/quantity.h:118:9: required for the satisfaction of ‘UnitOne’ [with R = mp_units::quantity::reference] ../../src/core/include/mp-units/framework/quantity.h:122:9: required for the satisfaction of ‘ExplicitFromNumber’ [with R = mp_units::usc::degree_Fahrenheit{}; Rep = int] ../../src/core/include/mp-units/framework/quantity.h:119:30: note: the expression ‘equivalent(get_unit(R), mp_units::one) [with R = mp_units::quantity::reference]’ evaluated to ‘false’ 119 | (equivalent(get_unit(R), one) && detail::get_associated_quantity(get_unit(R)) == dimensionless); | ~~~~~~~~~~^~~~~~~~~~~~~~~~~~ ../../src/core/include/mp-units/framework/quantity_point.h: In instantiation of ‘constexpr mp_units::quantity_point

@HazardyKnusperkeks

Copy link
Copy Markdown
Contributor Author

Btw. which clang-format version do you use? I have used 21, 22, and 23 (current HEAD), and there seems to be a bug, as the round declaration goes beyond the 120 column limit.

@mpusz

mpusz commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Btw. which clang-format version do you use?

I use the one forced in pre-commit. I tried a newer one but it breaks the formatting of some expressions, so I didn't upgrade.

@mpusz

mpusz commented Jul 8, 2026

Copy link
Copy Markdown
Owner

The cruxial point is, how can I use force_in for integer degree celsius to degree fahrenheit? @mpusz if you can give me a hint, I can continue on the PR.

@HazardyKnusperkeks, I am not sure what problem you might have. Everything seems to work fine: https://godbolt.org/z/GnzW9W5hq. Can you share your use case?

@HazardyKnusperkeks

Copy link
Copy Markdown
Contributor Author

Okay, the problem was solved by using auto as return type. My guess is, that the point origin was the problem. Is auto okay, or should it be explicit?

Is there any documentation I should touch, apart from the doxygen comments?

@mpusz

mpusz commented Jul 10, 2026

Copy link
Copy Markdown
Owner

Is auto okay, or should it be explicit?

I try not to use auto in this repo and promote CTAD. That way, I want users to follow the same practice so they can easily identify where they still deal with pure double and where they already have a strong type. But for the math.h internals auto might be OK, and it follows what I did already in the other function. Unless you meant auto in some other place?

Is there any documentation I should touch, apart from the doxygen comments?

That is a great question. I basically don't have the math functions reference yet, and I don't think a detailed description of each overload is needed in the User's Guide. However, this chapter could mention that the functions also take quantity points.

@mpusz mpusz left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@HazardyKnusperkeks

Copy link
Copy Markdown
Contributor Author

I meant the return type of floor, ceil and round, otherwise I would've needed to replace whatever force_in does to state the return type.

I will try to adapt the documentation a bit on monday.

@mpusz

mpusz commented Jul 10, 2026

Copy link
Copy Markdown
Owner

Can't you do the same I did for quantities (quantity_point<detail::clone_reference_with<To>(R), PO, Rep>)? If it doesn't work, then at least QuantityPoint auto would be helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Rounding for quantity_points

2 participants