Skip to content

Instantly share code, notes, and snippets.

@tormaroe
Created March 9, 2011 12:48
Show Gist options
  • Save tormaroe/862126 to your computer and use it in GitHub Desktop.
Save tormaroe/862126 to your computer and use it in GitHub Desktop.
Greatest Common Devisor implementation from the Linux source code
#include <linux/kernel.h>
#include <linux/gcd.h>
#include <linux/module.h>
/* Greatest common divisor */
unsigned long gcd(unsigned long a, unsigned long b)
{
unsigned long r;
if (a < b)
swap(a, b);
while ((r = a % b) != 0) {
a = b;
b = r;
}
return b;
}
EXPORT_SYMBOL_GPL(gcd);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment