Created
March 29, 2023 09:16
-
-
Save KolevDarko/686334ecfc50c1d6b285fd54b712a24e to your computer and use it in GitHub Desktop.
Yul prime number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isPrime(uint256 x) external pure returns (bool ret) { | |
ret = true; | |
assembly { | |
let halfX := add(div(x, 2), 1) | |
for {let i := 1} lt(i, halfX) {i := add(i, 1)} { | |
if iszero(mod(x, i)) { | |
ret := 0 | |
break | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment