Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

sub forms of is-prime and expmod

  • Loading branch information...
commit e095de4ec2ed968c3fc3bcac0376336890ab1c1c 1 parent 2e33656
@moritz moritz authored
Showing with 16 additions and 1 deletion.
  1. +1 −1  docs/ChangeLog
  2. +15 −0 src/core/Int.pm
View
2  docs/ChangeLog
@@ -1,6 +1,6 @@
New in 2012.10
-+ Int.is-prime and Int.expmod
++ is-prime and expmod
New in 2012.09
+ class Iterable does not inherit from class Cool anymore
View
15 src/core/Int.pm
@@ -245,3 +245,18 @@ multi sub chr(Cool \x) returns Str:D { x.Int.chr }
multi sub chr(int $x) returns str {
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.
Something went wrong with that request. Please try again.