openGPMP
Open Source Mathematics Package
arithmetic.cpp
Go to the documentation of this file.
1 
6 #include <cassert>
7 #include <iostream>
9 #include <stdio.h>
10 #include <time.h>
11 #include <vector>
12 
13 int main() {
14  std::cout << "TESTING ARITHMETIC OPERATIONS\n" << std::endl;
15  /*
16  * This functionality was really only implemented for practice
17  * for dealing with complex algorithms and equations later. There
18  * a plethora of ways to store data and then perform basic
19  * arithmetic operations so it is trivial to reinvent the wheel
20  * for these types of operations. Ideally if you want to perform
21  * the summation or product on a list type structure of numbers
22  * you may want to implement it on your own, this implementation
23  * is just for fun :)
24  *
25  * steps to perform arithmetic operations:
26  * 1. declare arith object (see RM_arith.hpp)
27  * 2. declare some variables initializing to values
28  * 3. using the declared arith object call the operations,
29  * rm_add, rm_sub, rm_mult
30  * 4. print out the values if you want or manipulate them further
31  */
32 
33  // declare our arithmetic class object, template class keep in mind
34  // numeric datatypes
36 
37  // declare some variables
38  int a = 10;
39  int b = 8;
40  int c = 3;
41  double d = 1.25;
42  float e = 1.85;
43  float f = 2.75;
44  long g = 1.35;
45  float y = 9743298223.945;
46  float z = 34895542235.8854;
47 
48  /*
49  * starting with addition operations with different data types.
50  */
51  int arr[] = {1, 2, 3, 4, 5};
52  int n = sizeof(arr) / sizeof(arr[0]);
53 
54  std::cout << ar.arr_add(arr, n) << '\n';
55  std::cout << ar.arr_sub(arr, n) << '\n';
56  std::cout << ar.arr_mlt(arr, n) << '\n';
57 
58  /*
59  * arithmetic basics
60  */
62  int r10 = 10;
63  int r11 = 3;
64  int r12 = ba.greatest_power(r10, r11);
65  printf("The greatest power of %d that divides %d! = %d\n", r10, r11, r12);
66 
67  int r13 = 7;
68  int r14 = 3;
69  int r15 = ba.greatest_power(r13, r14);
70  printf("The greatest power of %d that divides %d! = %d\n", r13, r14, r15);
71 
72  int r16 = 2;
73  int r17 = 4;
74  int r18 = ba.op_gcd(r16, r17);
75  printf("The GCD of %d & %d = %d\n", r16, r17, r18);
76 
77  int r19 = 232;
78  int r20 = 96;
79  int r21 = ba.op_gcd(r19, r20);
80  printf("The GCD of %d & %d = %d\n", r19, r20, r21);
81 
82  return 0;
83 }
int main()
Definition: arithmetic.cpp:13
User API for openGPMP ARITHMETIC MODULE.
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
gpmp::Basics ba
Definition: prime_test.cpp:55