diff options
author | etheisen <etheisen@cvs.openbsd.org> | 1996-09-14 19:02:02 +0000 |
---|---|---|
committer | etheisen <etheisen@cvs.openbsd.org> | 1996-09-14 19:02:02 +0000 |
commit | 6a4f3d0fd940c1e7052ddf23907f0e297dc42f4b (patch) | |
tree | 712fd665d6b150ef04906975a7493d87d38a1a8a /gnu/usr.bin/groff/libgroff/prime.cc | |
parent | 9cf27152dae9dbf80b167732c78c47baee90ddc5 (diff) |
Third time because import sucks.
Diffstat (limited to 'gnu/usr.bin/groff/libgroff/prime.cc')
-rw-r--r-- | gnu/usr.bin/groff/libgroff/prime.cc | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/gnu/usr.bin/groff/libgroff/prime.cc b/gnu/usr.bin/groff/libgroff/prime.cc new file mode 100644 index 00000000000..f0b1eadcc68 --- /dev/null +++ b/gnu/usr.bin/groff/libgroff/prime.cc @@ -0,0 +1,26 @@ +#include <math.h> + +int is_prime(unsigned n) +{ + if (n <= 3) + return 1; + if (!(n & 1)) + return 0; + if (n % 3 == 0) + return 0; + unsigned lim = unsigned(sqrt((double)n)); + unsigned d = 5; + for (;;) { + if (d > lim) + break; + if (n % d == 0) + return 0; + d += 2; + if (d > lim) + break; + if (n % d == 0) + return 0; + d += 4; + } + return 1; +} |