operations.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2020-2021 Mikhail Komarov <nemo@nil.foundation>
3 // Copyright (c) 2020-2021 Nikita Kaskov <nbering@nil.foundation>
4 //
5 // MIT License
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy
8 // of this software and associated documentation files (the "Software"), to deal
9 // in the Software without restriction, including without limitation the rights
10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 // copies of the Software, and to permit persons to whom the Software is
12 // furnished to do so, subject to the following conditions:
13 //
14 // The above copyright notice and this permission notice shall be included in all
15 // copies or substantial portions of the Software.
16 //
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 // SOFTWARE.
24 //---------------------------------------------------------------------------//
25 
26 #ifndef CRYPTO3_ALGEBRA_FIELDS_ELEMENT_OPERATIONS_HPP
27 #define CRYPTO3_ALGEBRA_FIELDS_ELEMENT_OPERATIONS_HPP
28 
30 
31 namespace nil {
32  namespace crypto3 {
33  namespace algebra {
34  namespace fields {
35  namespace detail {
36  template<typename FieldElement, typename Integral,
37  typename = typename std::enable_if<is_field_element<FieldElement>::value &&
38  std::is_constructible<FieldElement, Integral>::value>::type>
39  constexpr FieldElement operator+(const FieldElement &A, Integral B) {
40  return A + FieldElement(B);
41  }
42 
43  template<typename FieldElement, typename Integral,
44  typename = typename std::enable_if<is_field_element<FieldElement>::value &&
45  std::is_constructible<FieldElement, Integral>::value>::type>
46  constexpr FieldElement operator-(const FieldElement &A, Integral B) {
47  return A - FieldElement(B);
48  }
49 
50  template<typename FieldElement, typename Integral,
51  typename = typename std::enable_if<is_field_element<FieldElement>::value &&
52  std::is_constructible<FieldElement, Integral>::value>::type>
53  constexpr FieldElement operator*(const FieldElement &A, Integral B) {
54  return A * FieldElement(B);
55  }
56 
57  template<typename FieldElement, typename Integral,
58  typename = typename std::enable_if<is_field_element<FieldElement>::value &&
59  std::is_constructible<FieldElement, Integral>::value>::type>
60  constexpr FieldElement operator/(const FieldElement &A, Integral B) {
61  // return element_fp2(data / B.data);
62  return A / FieldElement(B);
63  }
64 
65  template<typename FieldElement, typename Integral,
66  typename = typename std::enable_if<is_field_element<FieldElement>::value &&
67  std::is_constructible<FieldElement, Integral>::value>::type>
68  constexpr FieldElement operator+(Integral A, const FieldElement &B) {
69  return FieldElement(A) + B;
70  }
71 
72  template<typename FieldElement, typename Integral,
73  typename = typename std::enable_if<is_field_element<FieldElement>::value &&
74  std::is_constructible<FieldElement, Integral>::value>::type>
75  constexpr FieldElement operator-(Integral A, const FieldElement &B) {
76  return FieldElement(A) - B;
77  }
78 
79  template<typename FieldElement, typename Integral,
80  typename = typename std::enable_if<is_field_element<FieldElement>::value &&
81  std::is_constructible<FieldElement, Integral>::value>::type>
82  constexpr FieldElement operator*(Integral A, const FieldElement &B) {
83  return FieldElement(A) * B;
84  }
85 
86  template<typename FieldElement, typename Integral,
87  typename = typename std::enable_if<is_field_element<FieldElement>::value &&
88  std::is_constructible<FieldElement, Integral>::value>::type>
89  constexpr FieldElement operator/(Integral A, const FieldElement &B) {
90  // return element_fp2(data / B.data);
91  return FieldElement(A) / B;
92  }
93  } // namespace detail
94  } // namespace fields
95  } // namespace algebra
96  } // namespace crypto3
97 } // namespace nil
98 
99 #endif // MINA_OPERATIONS_HPP
constexpr FieldElement operator-(const FieldElement &A, Integral B)
Definition: operations.hpp:46
constexpr FieldElement operator+(const FieldElement &A, Integral B)
Definition: operations.hpp:39
constexpr FieldElement operator/(const FieldElement &A, Integral B)
Definition: operations.hpp:60
element_fp12_2over3over2< FieldParams > operator*(const typename FieldParams::underlying_type::underlying_type::underlying_type &lhs, const element_fp12_2over3over2< FieldParams > &rhs)
Definition: detail/element/fp12_2over3over2.hpp:364
Definition: pair.hpp:31