math/include/nil/crypto3/math/expressions/math.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2021 Mikhail Komarov <nemo@nil.foundation>
3 // Copyright (c) 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_MATH_EXPRESSION_MATH_HPP
27 #define CRYPTO3_MATH_EXPRESSION_MATH_HPP
28 
29 #ifndef CRYPTO3_MATH_EXPRESSION_HPP
30 #error "math.hpp must not be included directly!"
31 #endif
32 
33 #include <boost/math/constants/constants.hpp>
34 
35 #include <cmath>
36 
37 namespace nil {
38  namespace crypto3 {
39  namespace math {
40  namespace expressions {
41  namespace detail {
42  namespace math {
43 
45  template <typename T>
46  T sgn(T x) {
47  return (T{0} < x) - (x < T{0});
48  }
49 
51  template <typename T>
52  T isnan(T x) {
53  return std::isnan(x);
54  }
55 
57  template <typename T>
58  T isinf(T x) {
59  return std::isinf(x);
60  }
61 
63  template <typename T>
64  T deg(T x) {
65  return x * boost::math::constants::radian<T>();
66  }
67 
69  template <typename T>
70  T rad(T x) {
71  return x * boost::math::constants::degree<T>();
72  }
73 
75  template <typename T>
76  T plus(T x) {
77  return x;
78  }
79 
81  template <typename T>
82  T plus(T x, T y) {
83  return x + y;
84  }
85 
87  template <typename T>
88  T minus(T x) {
89  return -x;
90  }
91 
93  template <typename T>
94  T minus(T x, T y) {
95  return x - y;
96  }
97 
99  template <typename T>
100  T multiplies(T x, T y) {
101  return x * y;
102  }
103 
105  template <typename T>
106  T divides(T x, T y) {
107  return x / y;
108  }
109 
111  template <typename T>
112  T unary_not(T x) {
113  return !x;
114  }
115 
117  template <typename T>
118  T logical_and(T x, T y) {
119  return x && y;
120  }
121 
123  template <typename T>
124  T logical_or(T x, T y) {
125  return x || y;
126  }
127 
129  template <typename T>
130  T less(T x, T y) {
131  return x < y;
132  }
133 
135  template <typename T>
136  T less_equals(T x, T y) {
137  return x <= y;
138  }
139 
141  template <typename T>
142  T greater(T x, T y) {
143  return x > y;
144  }
145 
147  template <typename T>
148  T greater_equals(T x, T y) {
149  return x >= y;
150  }
151 
153  template <typename T>
154  T equals(T x, T y) {
155  return x == y;
156  }
157 
159  template <typename T>
160  T not_equals(T x, T y) {
161  return x != y;
162  }
163 
164  } // namespace math
165  } // namespace detail
166  } // namespace expressions
167  } // namespace math
168  } // namespace crypto3
169 } // namespace nil
170 
171 #endif // CRYPTO3_MATH_EXPRESSION_MATH_HPP
T greater_equals(T x, T y)
greater equals
Definition: math/include/nil/crypto3/math/expressions/math.hpp:148
T divides(T x, T y)
divide
Definition: math/include/nil/crypto3/math/expressions/math.hpp:106
T less_equals(T x, T y)
less equals
Definition: math/include/nil/crypto3/math/expressions/math.hpp:136
T deg(T x)
Convert radians to degrees.
Definition: math/include/nil/crypto3/math/expressions/math.hpp:64
T multiplies(T x, T y)
multiply
Definition: math/include/nil/crypto3/math/expressions/math.hpp:100
T equals(T x, T y)
equals
Definition: math/include/nil/crypto3/math/expressions/math.hpp:154
T unary_not(T x)
unary not
Definition: math/include/nil/crypto3/math/expressions/math.hpp:112
T greater(T x, T y)
greater
Definition: math/include/nil/crypto3/math/expressions/math.hpp:142
T isinf(T x)
isinf function with adjusted return type
Definition: math/include/nil/crypto3/math/expressions/math.hpp:58
T less(T x, T y)
less
Definition: math/include/nil/crypto3/math/expressions/math.hpp:130
T plus(T x)
unary plus
Definition: math/include/nil/crypto3/math/expressions/math.hpp:76
T isnan(T x)
isnan function with adjusted return type
Definition: math/include/nil/crypto3/math/expressions/math.hpp:52
T rad(T x)
Convert degrees to radians.
Definition: math/include/nil/crypto3/math/expressions/math.hpp:70
T minus(T x)
unary minus
Definition: math/include/nil/crypto3/math/expressions/math.hpp:88
T not_equals(T x, T y)
not equals
Definition: math/include/nil/crypto3/math/expressions/math.hpp:160
T logical_and(T x, T y)
logical and
Definition: math/include/nil/crypto3/math/expressions/math.hpp:118
T sgn(T x)
Sign function.
Definition: math/include/nil/crypto3/math/expressions/math.hpp:46
T logical_or(T x, T y)
logical or
Definition: math/include/nil/crypto3/math/expressions/math.hpp:124
Definition: pair.hpp:31