piranha  0.10
cf_mult_impl.hpp
1 /* Copyright 2009-2017 Francesco Biscani (bluescarni@gmail.com)
2 
3 This file is part of the Piranha library.
4 
5 The Piranha library is free software; you can redistribute it and/or modify
6 it under the terms of either:
7 
8  * the GNU Lesser General Public License as published by the Free
9  Software Foundation; either version 3 of the License, or (at your
10  option) any later version.
11 
12 or
13 
14  * the GNU General Public License as published by the Free Software
15  Foundation; either version 3 of the License, or (at your option) any
16  later version.
17 
18 or both in parallel, as here.
19 
20 The Piranha library is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 for more details.
24 
25 You should have received copies of the GNU General Public License and the
26 GNU Lesser General Public License along with the Piranha library. If not,
27 see https://www.gnu.org/licenses/. */
28 
29 #ifndef PIRANHA_DETAIL_CF_MULT_IMPL_HPP
30 #define PIRANHA_DETAIL_CF_MULT_IMPL_HPP
31 
32 #include <type_traits>
33 #include <utility>
34 
35 #include <piranha/is_cf.hpp>
36 #include <piranha/math.hpp>
37 #include <piranha/mp_rational.hpp>
38 #include <piranha/type_traits.hpp>
39 
40 namespace piranha
41 {
42 
43 inline namespace impl
44 {
45 
46 // Overload if the coefficient is a rational.
47 template <typename Cf, enable_if_t<is_mp_rational<Cf>::value, int> = 0>
48 inline void cf_mult_impl(Cf &out_cf, const Cf &cf1, const Cf &cf2)
49 {
50  math::mul3(out_cf._num(), cf1.num(), cf2.num());
51 }
52 
53 // Overload if the coefficient is not a rational.
54 template <typename Cf, enable_if_t<!is_mp_rational<Cf>::value, int> = 0>
55 inline void cf_mult_impl(Cf &out_cf, const Cf &cf1, const Cf &cf2)
56 {
57  math::mul3(out_cf, cf1, cf2);
58 }
59 }
60 }
61 
62 #endif
Root piranha namespace.
Definition: array_key.hpp:52
Type traits.
auto mul3(T &a, const T &b, const T &c) -> decltype(mul3_impl< T >()(a, b, c))
Ternary multiplication.
Definition: math.hpp:2726