GreatestCommonDivisor.hpp
Go to the documentation of this file.
1 // ========================================================================================
2 // ApproxMVBB
3 // Copyright (C) 2014 by Gabriel Nützi <nuetzig (at) imes (d0t) mavt (d0t) ethz (døt) ch>
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 // ========================================================================================
9 
10 #ifndef ApproxMVBB_GreatestCommonDivisor_hpp
11 #define ApproxMVBB_GreatestCommonDivisor_hpp
12 namespace ApproxMVBB{
13  namespace MathFunctions {
14 
16  template<bool argsPositive = false,
17  typename T>
18  typename std::enable_if<std::is_integral<T>::value,T >::type
19  gcd2( T a, T b ) {
20 
21  if(!argsPositive) {
22  a = std::abs( a );
23  b = std::abs( b );
24  }
25 
26  if( a == 0 || a == b ) {
27  return b;
28  }
29  if( b == 0 ) {
30  return a;
31  }
32  if( a > b ) {
33  return gcd2<true,T>( a % b, b );
34  } else {
35  return gcd2<true,T>( a, b % a );
36  }
37  }
38 
40  template<bool argsPositive = false,
41  typename T>
42  typename std::enable_if<std::is_integral<T>::value,T>::type
43  gcd3( T a, T b, T c ) {
44 
45  if(!argsPositive) {
46  a = std::abs( a );
47  b = std::abs( b );
48  c = std::abs( c );
49  }
50 
51  if ( a == 0 )
52  return gcd2<true,T>( b, c );
53  if ( b == 0 )
54  return gcd2<true,T>( a, c );
55  if ( c == 0 )
56  return gcd2<true,T>( a, b );
57 
58  return gcd2<true,T>( a, gcd2<true,T>( b, c ) );
59  }
60  }
61 }
62 #endif
std::enable_if< std::is_integral< T >::value, T >::type gcd3(T a, T b, T c)
These are some container definitions.
std::enable_if< std::is_integral< T >::value, T >::type gcd2(T a, T b)


asr_approx_mvbb
Author(s): Gassner Nikolai
autogenerated on Mon Jun 10 2019 12:38:08