openGPMP
Open Source Mathematics Package
arithmetic.hpp
Go to the documentation of this file.
1 /*************************************************************************
2  *
3  * Project
4  * _____ _____ __ __ _____
5  * / ____| __ \| \/ | __ \
6  * ___ _ __ ___ _ __ | | __| |__) | \ / | |__) |
7  * / _ \| '_ \ / _ \ '_ \| | |_ | ___/| |\/| | ___/
8  *| (_) | |_) | __/ | | | |__| | | | | | | |
9  * \___/| .__/ \___|_| |_|\_____|_| |_| |_|_|
10  * | |
11  * |_|
12  *
13  * Copyright (C) Akiel Aries, <akiel@akiel.org>, et al.
14  *
15  * This software is licensed as described in the file LICENSE, which
16  * you should have received as part of this distribution. The terms
17  * among other details are referenced in the official documentation
18  * seen here : https://akielaries.github.io/openGPMP/ along with
19  * important files seen in this project.
20  *
21  * You may opt to use, copy, modify, merge, publish, distribute
22  * and/or sell copies of the Software, and permit persons to whom
23  * the Software is furnished to do so, under the terms of the
24  * LICENSE file. As this is an Open Source effort, all implementations
25  * must be of the same methodology.
26  *
27  *
28  *
29  * This software is distributed on an AS IS basis, WITHOUT
30  * WARRANTY OF ANY KIND, either express or implied.
31  *
32  ************************************************************************/
33 
41 #ifndef ARITHMETIC_HPP
42 #define ARITHMETIC_HPP
43 #include <cstdint>
44 
53 namespace gpmp {
54 
66 template <typename T> class Arith {
67  public:
68  T arr_add(T arr[], int64_t n) {
69  T sum = 0;
70 
71  for (int64_t i = 0; i < n; i++) {
72  sum += arr[i];
73  }
74  return sum;
75  }
76 
77  T arr_sub(T arr[], int64_t n) {
78  T diff = arr[0];
79 
80  for (int64_t i = 1; i < n; i++) {
81  diff -= arr[i];
82  }
83  return diff;
84  }
85 
86  T arr_mlt(T arr[], int64_t n) {
87  T prod = arr[0];
88 
89  for (int64_t i = 0; i < n; i++) {
90  prod *= arr[i];
91  }
92  return prod;
93  }
94 };
95 
101 class Basics {
102  public:
111  int64_t greatest_power(int64_t n, int64_t p);
112 
121  int64_t op_gcd(int64_t x, int64_t y);
122 
123  // TODO floating point operations for square root, logarithms,
124  // exponentation, trigonometric functions of floating points
125 
126  // complex arithmetic, arithmetic on complex numbers
127 
128  // precision arithmetic
129 
130  // TODO FIXME XXX BUG CHECKME TESTME PENDING DOCME
131 };
132 
133 } // namespace gpmp
134 
135 // public:
143 // template <typename T> inline T add(T t) {
144 // return t;
145 // }
146 
147 // template <typename T, typename... Ts> inline auto add(T t, Ts... ts)
148 // {
149 // return t + add(ts...);
150 // }
151 
160 // template <typename X> inline X sub(X x) {
161 // return x;
162 // }
163 // template <typename X, typename... Xy> inline auto sub(X x, Xy... xy)
164 // {
165 // return x - sub(xy...);
166 // }
167 
175 // template <typename W> inline W mult(W w) {
176 // return w;
177 // }
178 // template <typename W, typename... Wv> inline auto mult(W w, Wv... wv)
179 // {
180 // return w * mult(wv...);
181 // }
182 
191 // template <typename Z> inline Z exp(Z z) {
192 // return z;
193 // }
194 // template <typename Z, typename... Zy> inline auto exp(Z z, Zy... zy)
195 // {
196 // return z *= exp(zy...);
197 // }
198 //};
199 
200 #endif
Arithmetic Basics
Definition: arithmetic.hpp:66
T arr_sub(T arr[], int64_t n)
Definition: arithmetic.hpp:77
T arr_add(T arr[], int64_t n)
Definition: arithmetic.hpp:68
T arr_mlt(T arr[], int64_t n)
Definition: arithmetic.hpp:86
Arithmetic Operations
Definition: arithmetic.hpp:101
int64_t greatest_power(int64_t n, int64_t p)
Find greatest power of 2 itegers.
Definition: arith.cpp:39
int64_t op_gcd(int64_t x, int64_t y)
Find Greatest Common Divisor of 2 integers.
Definition: arith.cpp:50
The source C++ openGPMP namespace.