Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move Int candidates from Numeric.pm6 to Int.pm6
  • Loading branch information
MasterDuke17 committed Oct 4, 2020
1 parent e679775 commit bf799ba
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
21 changes: 21 additions & 0 deletions src/core.c/Int.pm6
Expand Up @@ -395,6 +395,25 @@ multi sub infix:<%>(int $a, int $b --> int) {
nqp::mod_i(nqp::add_i(nqp::mod_i($a,$b),$b),$b) # quick fix https://github.com/Raku/old-issue-tracker/issues/4999
}

multi sub infix:<%%>(Int:D \a, Int:D \b) {
nqp::if(
nqp::isbig_I(nqp::decont(a)) || nqp::isbig_I(nqp::decont(b)),
nqp::if(
b,
!nqp::mod_I(nqp::decont(a),nqp::decont(b),Int),
Failure.new(
X::Numeric::DivideByZero.new(using => 'infix:<%%>', numerator => a)
)
),
nqp::if(
nqp::isne_i(b,0),
nqp::hllbool(nqp::not_i(nqp::mod_i(nqp::decont(a),nqp::decont(b)))),
Failure.new(
X::Numeric::DivideByZero.new(using => 'infix:<%%>', numerator => a)
)
)
)
}
multi sub infix:<%%>(int $a, int $b --> Bool:D) {
nqp::hllbool(nqp::iseq_i(nqp::mod_i($a, $b), 0))
}
Expand All @@ -415,13 +434,15 @@ multi sub infix:<**>(int $a, int $b --> int) {
nqp::pow_i($a, $b);
}

multi sub infix:<lcm>(Int:D $x = 1) { $x }
multi sub infix:<lcm>(Int:D \a, Int:D \b --> Int:D) {
nqp::lcm_I(nqp::decont(a), nqp::decont(b), Int);
}
multi sub infix:<lcm>(int $a, int $b --> int) {
nqp::lcm_i($a, $b)
}

multi sub infix:<gcd>(Int:D $x) { $x }
multi sub infix:<gcd>(Int:D \a, Int:D \b --> Int:D) {
nqp::gcd_I(nqp::decont(a), nqp::decont(b), Int);
}
Expand Down
21 changes: 0 additions & 21 deletions src/core.c/Numeric.pm6
Expand Up @@ -239,25 +239,6 @@ multi sub infix:<%>(\a, \b) { a.Real % b.Real }
proto sub infix:<%%>($?, $?, *%) is pure {*}
multi sub infix:<%%>() { Failure.new("No zero-arg meaning for infix:<%%>") }
multi sub infix:<%%>($) { Bool::True }
multi sub infix:<%%>(Int:D \a, Int:D \b) {
nqp::if(
nqp::isbig_I(nqp::decont(a)) || nqp::isbig_I(nqp::decont(b)),
nqp::if(
b,
!nqp::mod_I(nqp::decont(a),nqp::decont(b),Int),
Failure.new(
X::Numeric::DivideByZero.new(using => 'infix:<%%>', numerator => a)
)
),
nqp::if(
nqp::isne_i(b,0),
nqp::hllbool(nqp::not_i(nqp::mod_i(nqp::decont(a),nqp::decont(b)))),
Failure.new(
X::Numeric::DivideByZero.new(using => 'infix:<%%>', numerator => a)
)
)
)
}
multi sub infix:<%%>(\a, \b) {
nqp::if(
b,
Expand All @@ -269,12 +250,10 @@ multi sub infix:<%%>(\a, \b) {
}

proto sub infix:<lcm>($?, $?, *%) is pure {*}
multi sub infix:<lcm>(Int:D $x = 1) { $x }
multi sub infix:<lcm>(\a, \b) { a.Int lcm b.Int }

proto sub infix:<gcd>($?, $?, *%) is pure {*}
multi sub infix:<gcd>() { Failure.new('No zero-arg meaning for infix:<gcd>') }
multi sub infix:<gcd>(Int:D $x) { $x }
multi sub infix:<gcd>(\a, \b) { a.Int gcd b.Int }

proto sub infix:<**>($?, $?, *%) is pure {*}
Expand Down

0 comments on commit bf799ba

Please sign in to comment.