Awali
Another Weighted Automata library
arith.hh
Go to the documentation of this file.
1 // This file is part of Awali.
2 // Copyright 2016-2022 Sylvain Lombardy, Victor Marsault, Jacques Sakarovitch
3 //
4 // Awali is a free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef UTILS_ARITH_HH
18 #define UTILS_ARITH_HH
19 
21 
22 namespace awali { namespace utils {
23  // Greatest common divisor.
24 
25  ATTRIBUTE_CONST
26  inline
27  unsigned int gcd(unsigned int a, unsigned int b)
28  {
29  while (b)
30  {
31  unsigned int t = a;
32  a = b;
33  b = t % b;
34  }
35  return a;
36  }
37 
38  // Lowest common multiple
39  ATTRIBUTE_CONST
40  inline
41  unsigned int lcm(unsigned int a, unsigned int b)
42  {
43  return a / gcd(a, b) * b;
44  }
45 
46  ATTRIBUTE_CONST
47  inline
48  int min(int a, int b) {
49  return (a<b?a:b);
50  }
51 
52  ATTRIBUTE_CONST
53  inline
54  int max(int a, int b) {
55  return (a>b?a:b);
56  }
57 
58 }}//end of ns awali::utils
59 
60 
61 
62 #endif
ATTRIBUTE_CONST unsigned int gcd(unsigned int a, unsigned int b)
Definition: arith.hh:27
ATTRIBUTE_CONST unsigned int lcm(unsigned int a, unsigned int b)
Definition: arith.hh:41
ATTRIBUTE_CONST int max(int a, int b)
Definition: arith.hh:54
ATTRIBUTE_CONST int min(int a, int b)
Definition: arith.hh:48
Main namespace of Awali.
Definition: ato.hh:22