GreatestCommonDivisor.hpp
Go to the documentation of this file.
00001 // ========================================================================================
00002 //  ApproxMVBB
00003 //  Copyright (C) 2014 by Gabriel Nützi <nuetzig (at) imes (d0t) mavt (d0t) ethz (døt) ch>
00004 //
00005 //  This Source Code Form is subject to the terms of the Mozilla Public
00006 //  License, v. 2.0. If a copy of the MPL was not distributed with this
00007 //  file, You can obtain one at http://mozilla.org/MPL/2.0/.
00008 // ========================================================================================
00009 
00010 #ifndef ApproxMVBB_GreatestCommonDivisor_hpp
00011 #define ApproxMVBB_GreatestCommonDivisor_hpp
00012 namespace ApproxMVBB{
00013     namespace MathFunctions {
00014 
00016         template<bool argsPositive = false,
00017                  typename T>
00018         typename std::enable_if<std::is_integral<T>::value,T >::type
00019         gcd2( T  a, T  b ) {
00020 
00021             if(!argsPositive) {
00022                 a = std::abs( a );
00023                 b = std::abs( b );
00024             }
00025 
00026             if( a == 0  ||  a == b ) {
00027                 return  b;
00028             }
00029             if( b == 0 ) {
00030                 return  a;
00031             }
00032             if( a > b ) {
00033                 return  gcd2<true,T>( a % b, b );
00034             } else {
00035                 return  gcd2<true,T>( a, b % a );
00036             }
00037         }
00038 
00040         template<bool argsPositive = false,
00041                  typename T>
00042         typename std::enable_if<std::is_integral<T>::value,T>::type
00043         gcd3( T  a, T  b, T  c ) {
00044 
00045             if(!argsPositive) {
00046                 a = std::abs( a );
00047                 b = std::abs( b );
00048                 c = std::abs( c );
00049             }
00050 
00051             if   ( a == 0 )
00052                 return  gcd2<true,T>( b, c );
00053             if   ( b == 0 )
00054                 return  gcd2<true,T>( a, c );
00055             if   ( c == 0 )
00056                 return  gcd2<true,T>( a, b );
00057 
00058             return  gcd2<true,T>( a, gcd2<true,T>( b, c ) );
00059         }
00060     }
00061 }
00062 #endif


asr_approx_mvbb
Author(s): Gassner Nikolai
autogenerated on Sat Jun 8 2019 20:21:49