diff --git a/src/include/units/bits/unit_op.h b/src/include/units/bits/unit_op.h new file mode 100644 index 00000000..a4a1527a --- /dev/null +++ b/src/include/units/bits/unit_op.h @@ -0,0 +1,39 @@ +// The MIT License (MIT) +// +// Copyright (c) 2018 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +#include + +namespace units::detail { + +template::ratio>, + typename Ratio2 = ratio_divide::ratio>> +using unit_ratio_multiply = ratio_multiply; + +template::ratio>, + typename Ratio2 = ratio_divide::ratio>> +using unit_ratio_divide = ratio_divide; + +} // namespace units::detail diff --git a/src/include/units/quantity.h b/src/include/units/quantity.h index 7241cc78..5f665e7f 100644 --- a/src/include/units/quantity.h +++ b/src/include/units/quantity.h @@ -24,10 +24,13 @@ #include #include +#include #include + #if __GNUC__ >= 10 #include #endif + #include #include @@ -603,13 +606,11 @@ template& lhs, const quantity& rhs) requires (!equivalent_dim>) && // TODO equivalent_derived_dim? (treat_as_floating_point || - (std::ratio_multiply::den == 1)) && + detail::unit_ratio_multiply::den == 1) && detail::basic_arithmetic { using dim = dimension_multiply; - using ratio1 = ratio_divide::ratio>; - using ratio2 = ratio_divide::ratio>; - using ratio = ratio_multiply, typename dimension_unit::ratio>; + using ratio = ratio_multiply, typename dimension_unit::ratio>; ; using unit = downcast_unit; using common_rep = decltype(lhs.count() * rhs.count()); using ret = quantity; @@ -656,15 +657,13 @@ template& lhs, const quantity& rhs) requires detail::basic_arithmetic && (!equivalent_dim) && // TODO equivalent_derived_dim? (treat_as_floating_point || - (ratio_divide::den == 1)) + detail::unit_ratio_divide::den == 1) { Expects(rhs.count() != 0); using common_rep = decltype(lhs.count() / rhs.count()); using dim = dimension_divide; - using ratio1 = ratio_divide::ratio>; - using ratio2 = ratio_divide::ratio>; - using ratio = ratio_multiply, typename dimension_unit::ratio>; + using ratio = ratio_multiply, typename dimension_unit::ratio>; using unit = downcast_unit; using ret = quantity; return ret(lhs.count() / rhs.count());