
GCD calculator
Calculate gcd calculator with clear inputs and assumptions.
Your inputs stay in your browser. Displayed results are rounded to a maximum of 12 significant digits.
Method and assumptions
Method version 1.0.0 · Updated
Calculate
Formula: Calculate gcd calculator with clear inputs and assumptions.
Calculate gcd calculator with clear inputs and assumptions.
- a
- Integer A
- b
- Integer B
Results are estimates where noted and depend on the entered assumptions.
Calculate with code
These short examples use the same inputs and core calculation as this tool. Adapt validation and formatting to your application.
JavaScript
function gcd(a, b) { return b === 0 ? Math.abs(a) : gcd(b, a % b); }
console.log(gcd(48, 18)); // 6TypeScript
function gcd(a: number, b: number): number { return b === 0 ? Math.abs(a) : gcd(b, a % b); }
console.log(gcd(48, 18)); // 6Python
def gcd(a, b):
return abs(a) if b == 0 else gcd(b, a % b)
print(gcd(48, 18)) # 6Java
static long gcd(long a, long b) { return b == 0 ? Math.abs(a) : gcd(b, a % b); }
System.out.println(gcd(48, 18)); // 6C#
static long Gcd(long a, long b) => b == 0 ? Math.Abs(a) : Gcd(b, a % b);
Console.WriteLine(Gcd(48, 18)); // 6