Talk:Euclidean algorithm (C)

From LiteratePrograms
Jump to: navigation, search

Ensuring a > b is not necessary: If a < b, then a % b == a, and therefore in the next iteration a and b are swapped. The version with the test might be faster, though, but that would have to be tested: In half of the cases (when a > b is already true), it introduces an extra test/branch (branches are generally quite expensive on modern pipelined CPUs), in the other half it saves one modulo operation (the number of branches is the same in that case, because the test-free version needs one more iteration, which includes a branch for the loop condition; however, branch prediction probably works better for that case). --Ce 01:25, 27 March 2009 (MDT)

hijacker
hijacker
hijacker
hijacker