Skip to content

Instantly share code, notes, and snippets.

@atarpara
Created August 30, 2022 06:53
Show Gist options
  • Save atarpara/9c79ddfe9eab66851b22257ff96395db to your computer and use it in GitHub Desktop.
Save atarpara/9c79ddfe9eab66851b22257ff96395db to your computer and use it in GitHub Desktop.
GCD in solidity
function gcd(uint256 x, uint256 y) internal pure returns(uint256 z){
assembly{
for {} 1 {} {
if eq(y,0) {
z := x
break
}
let temp := mod(x,y)
x := y
y := temp
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment