Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement infix:«<=>»(Num, Num), infix:«cmp»(Num, Num), and infix:«<=…
…>»(Int, Int) along the model of the previous infix:«cmp»(Int, Int).

On the plus side, this knocks about 10% off the execution time of Range iteration on Nums.  (It's still mysteriously about 50% slower than Range iteration on Ints.)  On the minus side, all of these functions are violating the spec by not using the Order enum.
  • Loading branch information
colomon committed Aug 15, 2010
1 parent 6be4293 commit 10041cb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
12 changes: 8 additions & 4 deletions src/core/Int.pm
Expand Up @@ -31,6 +31,14 @@ augment class Int does Real {
}
}

multi sub infixcmp»(Int $a, Int $b) {
pir::cmp__III($a, $b);
}

multi sub infix:«<=>»(Int $a, Int $b) {
pir::cmp__III($a, $b);
}

multi sub infix==»(Int $a, Int $b) {
pir::iseq__III( $a, $b) ?? True !! False
}
Expand All @@ -55,10 +63,6 @@ multi sub infix:«>=»(Int $a, Int $b) {
pir::isge__III( $a, $b) ?? True !! False
}

multi sub infixcmp»(Int $a, Int $b) {
pir::cmp__III($a, $b);
}

# Should pull along the other Int comparison operators at some point,
# but this is a great start.

Expand Down
11 changes: 5 additions & 6 deletions src/core/Num.pm
Expand Up @@ -184,13 +184,12 @@ augment class Num does Real {
}
}

multi sub infixcmp»(Num $a, Num $b) {
pir::cmp__INN($a, $b);
}

multi sub infix:«<=>»(Num $a, Num $b) {
# TODO: should be Order::Same, ::Increase, ::Decrease once they work
if $a == $b {
0;
} else {
$a < $b ?? -1 !! 1;
}
pir::cmp__INN($a, $b);
}

multi sub infix==»(Num $a, Num $b) {
Expand Down

0 comments on commit 10041cb

Please sign in to comment.