Skip to content

Commit

Permalink
sub forms of is-prime and expmod
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz committed Sep 22, 2012
1 parent 2e33656 commit e095de4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/ChangeLog
@@ -1,6 +1,6 @@
New in 2012.10 New in 2012.10


+ Int.is-prime and Int.expmod + is-prime and expmod


New in 2012.09 New in 2012.09
+ class Iterable does not inherit from class Cool anymore + class Iterable does not inherit from class Cool anymore
Expand Down
15 changes: 15 additions & 0 deletions src/core/Int.pm
Expand Up @@ -245,3 +245,18 @@ multi sub chr(Cool \x) returns Str:D { x.Int.chr }
multi sub chr(int $x) returns str { multi sub chr(int $x) returns str {
nqp::chr($x); nqp::chr($x);
} }

proto sub is-prime($, $?) {*}
multi sub is-prime(Int:D \i, Int:D $tries = 100) {
nqp::p6bool(nqp::isprime_I(nqp::p6decont(i), nqp::unbox_i($tries)));
}
multi sub is-prime(\i, $tries = 100) {
nqp::p6bool(nqp::isprime_I(nqp::p6decont(i.Int), nqp::unbox_i($tries.Int)));
}
proto sub expmod($, $, $) {*}
multi sub expmod(Int:D \base, Int:D \exp, Int:D \mod) {
nqp::expmod_I(nqp::p6decont(base), nqp::p6decont(exp), nqp::p6decont(mod), Int);
}
multi sub expmod(\base, \exp, \mod) {
nqp::expmod_I(nqp::p6decont(base.Int), nqp::p6decont(exp.Int), nqp::p6decont(mod.Int), Int);
}

0 comments on commit e095de4

Please sign in to comment.