Vcsn  2.3
Be Rational
math.hh
Go to the documentation of this file.
1 #pragma once
2 
4 #include <vcsn/misc/raise.hh>
5 
6 namespace vcsn
7 {
8  namespace detail
9  {
11  ATTRIBUTE_PURE
12  inline
13  unsigned int gcd(unsigned int a, unsigned int b)
14  {
15  require(b, "gcd: rhs cannot be zero");
16  while (b)
17  {
18  unsigned int t = a;
19  a = b;
20  b = t % b;
21  }
22  return a;
23  }
24 
26  ATTRIBUTE_PURE
27  inline
28  unsigned int lcm(unsigned int a, unsigned int b)
29  {
30  return a / gcd(a, b) * b;
31  }
32  }
33 }
ATTRIBUTE_PURE unsigned int lcm(unsigned int a, unsigned int b)
Lowest common multiple.
Definition: math.hh:28
void require(Bool b, Args &&...args)
If b is not verified, raise an error with args as message.
Definition: raise.hh:91
Definition: a-star.hh:8
weightset_mixin< detail::b_impl > b
Definition: fwd.hh:48
ATTRIBUTE_PURE unsigned int gcd(unsigned int a, unsigned int b)
Greatest common divisor.
Definition: math.hh:13
Provide a variadic mul on top of a binary mul(), and one().
Definition: fwd.hh:46