Math Fundamentals18 sections · 814 units
Open in Course

GCD with Negative Numbers

Absolute values

GCD is defined for positive integers. If you have negative numbers, take absolute values first: gcd(a, b) = gcd(|a|, |b|).

Example: gcd(-12, 18) = gcd(12, 18) = 6. The sign does not matter because divisibility ignores sign.

Most implementations handle this automatically, but be aware if coding from scratch.