 Think there is a mistake in the algorithm implemented. By definition, gcd (a,b) = gcd (a,-b) = gcd (-a,b) = gcd (-a,-b) So for a = 1, b = 4, the gcd is 1. eqn1: 0(4) + 1(1) = 1 (correct) eqn2: 0(4) + 1(-1) = -1 (sign incorrect) eqn3: -1(1) + 1(-4) = -5 (sign and value incorrect) eqn4: 1(-1) + 0(-4) = -1 (sign incorrect)