Skip to content

Commit

Permalink
A few more native int operators. If anybody fancies doing the num one…
Browse files Browse the repository at this point in the history
…s, dive in!
  • Loading branch information
jnthn committed Sep 29, 2011
1 parent 1f0a570 commit 1cb3f8d
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/core/Int.pm
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,34 @@ multi infix:<+>(int $a, int $b) {
multi infix:<->(Int \$a, Int \$b) {
nqp::p6box_i(nqp::sub_i(nqp::unbox_i($a), nqp::unbox_i($b)))
}
multi infix:<->(int $a, int $b) {
nqp::want(nqp::p6box_i(nqp::sub_i($a, $b)),
'Ii', nqp::sub_i($a, $b))
}

multi infix:<*>(Int \$a, Int \$b) {
nqp::p6box_i(nqp::mul_i(nqp::unbox_i($a), nqp::unbox_i($b)))
}
multi infix:<*>(int $a, int $b) {
nqp::want(nqp::p6box_i(nqp::mul_i($a, $b)),
'Ii', nqp::mul_i($a, $b))
}

multi infix:<div>(Int \$a, Int \$b) {
nqp::p6box_i(nqp::div_i(nqp::unbox_i($a), nqp::unbox_i($b)))
}
multi infix:<div>(int $a, int $b) {
nqp::want(nqp::p6box_i(nqp::div_i($a, $b)),
'Ii', nqp::div_i($a, $b))
}

multi infix:<%>(Int \$a, Int \$b) {
nqp::p6box_i(nqp::mod_i(nqp::unbox_i($a), nqp::unbox_i($b)))
}
multi infix:<%>(int $a, int $b) {
nqp::want(nqp::p6box_i(nqp::mod_i($a, $b)),
'Ii', nqp::mod_i($a, $b))
}

multi infix:<**>(Int \$a, Int \$b) {
if $b >= 0 {
Expand All @@ -115,10 +131,18 @@ multi infix:<**>(Int \$a, Int \$b) {
multi infix:<lcm>(Int:D \$a, Int:D \$b) {
nqp::p6box_i(nqp::lcm_i(nqp::unbox_i($a), nqp::unbox_i($b)))
}
multi infix:<lcm>(int $a, int $b) {
nqp::want(nqp::p6box_i(nqp::lcm_i($a, $b)),
'Ii', nqp::lcm_i($a, $b))
}

multi infix:<gcd>(Int:D \$a, Int:D \$b) {
nqp::p6box_i(nqp::gcd_i(nqp::unbox_i($a), nqp::unbox_i($b)))
}
multi infix:<gcd>(int $a, int $b) {
nqp::want(nqp::p6box_i(nqp::gcd_i($a, $b)),
'Ii', nqp::gcd_i($a, $b))
}

multi infix:<cmp>(Int:D \$a, Int:D \$b) {
nqp::p6box_i(nqp::cmp_i(nqp::unbox_i($a), nqp::unbox_i($b)))
Expand Down

0 comments on commit 1cb3f8d

Please sign in to comment.