Loading [MathJax]/extensions/TeX/AMSsymbols.js
PSCF
v1.2
Toggle main menu visibility
Main Page
Topics
Namespaces
Namespace List
Namespace Members
All
a
b
c
d
e
f
g
h
i
m
n
o
p
r
s
t
w
Functions
a
b
c
d
e
f
g
h
i
m
n
o
p
r
s
t
w
Variables
Typedefs
Enumerations
Classes
Class List
Class Index
Class Hierarchy
Class Members
All
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
~
Functions
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
~
Variables
a
b
c
d
e
f
h
i
k
l
m
n
o
p
q
r
s
t
w
z
Typedefs
b
c
e
f
i
m
o
p
q
r
s
t
w
Enumerations
Related Symbols
o
r
s
w
Files
File List
File Members
All
Functions
Macros
src
util
math
gcd.h
1
#ifndef UTIL_GCD_H
2
#define UTIL_GCD_H
3
4
/*
5
* Util Package - C++ Utilities for Scientific Computation
6
*
7
* Copyright 2010 - 2017, The Regents of the University of Minnesota
8
* Distributed under the terms of the GNU General Public License.
9
*/
10
11
#include <stdlib.h>
12
13
namespace
Util
14
{
15
30
inline
int
gcd
(
int
a,
int
b)
31
{
32
a = abs(a);
33
b = abs(b);
34
if
(a == 0)
return
b;
35
if
(b == 0)
return
a;
36
int
c;
37
// If b > a, swap such that b < a
38
if
(b > a) {
39
c = a;
40
a = b;
41
b = c;
42
}
43
// Euclid's algorithm, for a > b > 0
44
while
(b !=0) {
45
c = a % b;
46
a = b;
47
b = c;
48
}
49
return
a;
50
}
30
inline
int
gcd
(
int
a,
int
b) {
…
}
51
52
}
53
#endif
Util::gcd
int gcd(int a, int b)
Compute greatest common divisor (gcd) of two integers.
Definition
gcd.h:30
Util
Utility classes for scientific computation.
Definition
accumulators.mod:1
Generated on Fri Mar 28 2025 00:57:29 for PSCF by
1.12.0