Hello! I have found this GCD (Greatest Common Divisor) algorithm and wonder if someone knows an even more efficient one? The faster the better.![]()
P.S. I indent with a tab length of 4 spaces in my environment, but here a tab is 8 spacesCode:int gcd( int a, int b ) { int t; if ( a < 0 ) a = -a; if ( ! b ) return a; if ( b < 0 ) b = -b; if ( ! a ) return b; t = 0; while ( ! ( ( a | b ) & 1 ) ) { a >>= 1; b >>= 1; ++t; } while ( ! ( a & 1 ) ) a >>= 1; while ( ! ( b & 1 ) ) b >>= 1; while ( a != b ) { if ( a > b ) { a -= b; do { a >>= 1; } while ( ! ( a & 1 ) ); } else { b -= a; do { b >>= 1; } while ( ! ( b & 1 ) ); } } return a << t; }. Can I fix this with some setting? Would be nice. Thanks!!



LinkBack URL
About LinkBacks
. Can I fix this with some setting? Would be nice. Thanks!! 



No this is not homework. I have programmed in C for more than 15 years now. And about the tabs I was wondering if a tab length can be set here on this forum.. not in my Metrowerks CodeWarrior environment.