libtrbase  1.0.2
Web server and task management solution.
math.c
Go to the documentation of this file.
1 /**
2  * \file
3  * Common reusable definitions.
4  *
5  * \todo All public symbols need to be prefixed to make name clashes
6  * more unlikely.
7  *
8  * \author Georg Hopp
9  *
10  * \copyright
11  * Copyright © 2014 Georg Hopp
12  *
13  * This program is free software: you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation, either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program. If not, see <http://www.gnu.org/licenses/>.
25  */
26 
27 #include "tr/math.h"
28 
29 long
30 TR_euklidGcd(register long val1, register long val2)
31 {
32  register long mod;
33 
34  if(val2 > val1) SWAP_XOR(val1, val2);
35 
36  mod = val1 % val2;
37  while (mod != 0) {
38  val1 = val2;
39  val2 = mod;
40  mod = val1 % val2;
41  }
42 
43  return val2;
44 }
45 
46 long
47 TR_lcm(register long val1, register long val2)
48 {
49  return val1 * val2 / TR_euklidGcd(val1, val2);
50 }
51 
52 // vim: set ts=4 sw=4:
long TR_euklidGcd(register long val1, register long val2)
Definition: math.c:30
long TR_lcm(register long val1, register long val2)
Definition: math.c:47
#define SWAP_XOR(a, b)
Definition: commons.h:52