Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add Real and Num versions of the numeric comparison operators.
  • Loading branch information
colomon committed May 8, 2010
1 parent ab01a92 commit f8ca417
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/core/Real.pm
Expand Up @@ -54,6 +54,8 @@ role Real does Numeric {
}
}

# Comparison operators

multi sub infix:«<=>»(Real $a, Real $b) {
$a.Bridge <=> $b.Bridge;
}
Expand All @@ -70,6 +72,14 @@ multi sub infix:«==»(Num $a, Num $b) {
pir::iseq__INN( $a, $b) ?? True !! False
}

multi sub infix!=»(Real $a, Real $b) {
$a.Bridge != $b.Bridge;
}

multi sub infix!=»(Num $a, Num $b) {
pir::iseq__INN( $a, $b) ?? False !! True # note reversed
}

multi sub infix<»(Real $a, Real $b) {
$a.Bridge < $b.Bridge;
}
Expand All @@ -78,6 +88,32 @@ multi sub infix:«<»(Num $a, Num $b) {
pir::islt__INN( $a, $b) ?? True !! False
}

multi sub infix>»(Real $a, Real $b) {
$a.Bridge > $b.Bridge;
}

multi sub infix>»(Num $a, Num $b) {
pir::isgt__INN( $a, $b) ?? True !! False
}

multi sub infix<=»(Real $a, Real $b) {
$a.Bridge <= $b.Bridge;
}

multi sub infix<=»(Num $a, Num $b) {
pir::isgt__INN( $a, $b) ?? False !! True # note reversed
}

multi sub infix>=»(Real $a, Real $b) {
$a.Bridge >= $b.Bridge;
}

multi sub infix>=»(Num $a, Num $b) {
pir::islt__INN( $a, $b) ?? False !! True # note reversed
}

# Arithmetic operators

multi sub prefix:<->(Real $a) {
-($a.Bridge);
}
Expand Down

0 comments on commit f8ca417

Please sign in to comment.