openGPMP
Open Source Mathematics Package
modules
arithmetic
arith.cpp
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.
25
*
26
*
27
*
28
* This software is distributed on an AS IS basis, WITHOUT
29
* WARRANTY OF ANY KIND, either express or implied.
30
*
31
************************************************************************/
32
33
/*
34
* stubbed out implementation file for arithmetic operations
35
*/
36
#include <cstdint>
37
#include <
openGPMP/arithmetic.hpp
>
38
39
int64_t
gpmp::Basics::greatest_power
(int64_t n, int64_t p) {
40
int64_t result = 0;
41
42
// Calculate x = n/p + n/(p^2) + n/(p^3) + ....
43
while
(n) {
44
n /= p;
45
result += n;
46
}
47
return
result;
48
}
49
50
int64_t
gpmp::Basics::op_gcd
(int64_t x, int64_t y) {
51
if
(x < y)
52
return
op_gcd(y, x);
53
54
else
if
(x % y == 0)
55
return
y;
56
57
else
58
return
op_gcd(y, x % y);
59
}
arithmetic.hpp
User API for openGPMP ARITHMETIC MODULE.
gpmp::Basics::greatest_power
int64_t greatest_power(int64_t n, int64_t p)
Find greatest power of 2 itegers.
Definition:
arith.cpp:39
gpmp::Basics::op_gcd
int64_t op_gcd(int64_t x, int64_t y)
Find Greatest Common Divisor of 2 integers.
Definition:
arith.cpp:50
Generated by
1.9.1