forked from mpusz/mp-units
Implicit conversions fixed
This commit is contained in:
39
src/include/units/bits/unit_op.h
Normal file
39
src/include/units/bits/unit_op.h
Normal file
@@ -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 <units/unit.h>
|
||||
|
||||
namespace units::detail {
|
||||
|
||||
template<Dimension Dim1, Unit U1, Dimension Dim2, Unit U2,
|
||||
typename Ratio1 = ratio_divide<typename U1::ratio, typename dimension_unit<Dim1>::ratio>,
|
||||
typename Ratio2 = ratio_divide<typename U2::ratio, typename dimension_unit<Dim2>::ratio>>
|
||||
using unit_ratio_multiply = ratio_multiply<Ratio1, Ratio2>;
|
||||
|
||||
template<Dimension Dim1, Unit U1, Dimension Dim2, Unit U2,
|
||||
typename Ratio1 = ratio_divide<typename U1::ratio, typename dimension_unit<Dim1>::ratio>,
|
||||
typename Ratio2 = ratio_divide<typename U2::ratio, typename dimension_unit<Dim2>::ratio>>
|
||||
using unit_ratio_divide = ratio_divide<Ratio1, Ratio2>;
|
||||
|
||||
} // namespace units::detail
|
@@ -24,10 +24,13 @@
|
||||
|
||||
#include <units/bits/concepts.h>
|
||||
#include <units/bits/dimension_op.h>
|
||||
#include <units/bits/unit_op.h>
|
||||
#include <units/bits/unit_text.h>
|
||||
|
||||
#if __GNUC__ >= 10
|
||||
#include <compare>
|
||||
#endif
|
||||
|
||||
#include <limits>
|
||||
#include <ostream>
|
||||
|
||||
@@ -603,13 +606,11 @@ template<typename D1, typename U1, typename Rep1, typename D2, typename U2, type
|
||||
[[nodiscard]] constexpr Quantity AUTO operator*(const quantity<D1, U1, Rep1>& lhs, const quantity<D2, U2, Rep2>& rhs)
|
||||
requires (!equivalent_dim<D1, dim_invert<D2>>) && // TODO equivalent_derived_dim?
|
||||
(treat_as_floating_point<decltype(lhs.count() * rhs.count())> ||
|
||||
(std::ratio_multiply<typename U1::ratio, typename U2::ratio>::den == 1)) &&
|
||||
detail::unit_ratio_multiply<D1, U1, D2, U2>::den == 1) &&
|
||||
detail::basic_arithmetic<Rep1, Rep2>
|
||||
{
|
||||
using dim = dimension_multiply<D1, D2>;
|
||||
using ratio1 = ratio_divide<typename U1::ratio, typename dimension_unit<D1>::ratio>;
|
||||
using ratio2 = ratio_divide<typename U2::ratio, typename dimension_unit<D2>::ratio>;
|
||||
using ratio = ratio_multiply<ratio_multiply<ratio1, ratio2>, typename dimension_unit<dim>::ratio>;
|
||||
using ratio = ratio_multiply<detail::unit_ratio_multiply<D1, U1, D2, U2>, typename dimension_unit<dim>::ratio>; ;
|
||||
using unit = downcast_unit<dim, ratio>;
|
||||
using common_rep = decltype(lhs.count() * rhs.count());
|
||||
using ret = quantity<dim, unit, common_rep>;
|
||||
@@ -656,15 +657,13 @@ template<typename D1, typename U1, typename Rep1, typename D2, typename U2, type
|
||||
[[nodiscard]] constexpr Quantity AUTO operator/(const quantity<D1, U1, Rep1>& lhs, const quantity<D2, U2, Rep2>& rhs)
|
||||
requires detail::basic_arithmetic<Rep1, Rep2> && (!equivalent_dim<D1, D2>) && // TODO equivalent_derived_dim?
|
||||
(treat_as_floating_point<decltype(lhs.count() / rhs.count())> ||
|
||||
(ratio_divide<typename U1::ratio, typename U2::ratio>::den == 1))
|
||||
detail::unit_ratio_divide<D1, U1, D2, U2>::den == 1)
|
||||
{
|
||||
Expects(rhs.count() != 0);
|
||||
|
||||
using common_rep = decltype(lhs.count() / rhs.count());
|
||||
using dim = dimension_divide<D1, D2>;
|
||||
using ratio1 = ratio_divide<typename U1::ratio, typename dimension_unit<D1>::ratio>;
|
||||
using ratio2 = ratio_divide<typename U2::ratio, typename dimension_unit<D2>::ratio>;
|
||||
using ratio = ratio_multiply<ratio_divide<ratio1, ratio2>, typename dimension_unit<dim>::ratio>;
|
||||
using ratio = ratio_multiply<detail::unit_ratio_divide<D1, U1, D2, U2>, typename dimension_unit<dim>::ratio>;
|
||||
using unit = downcast_unit<dim, ratio>;
|
||||
using ret = quantity<dim, unit, common_rep>;
|
||||
return ret(lhs.count() / rhs.count());
|
||||
|
Reference in New Issue
Block a user