Skip to content

Commit

Permalink
fix rounders
Browse files Browse the repository at this point in the history
Does not handle big ints properly, but this is as good as old master ever got
  • Loading branch information
moritz committed Dec 6, 2011
1 parent fdba160 commit f5c1975
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/core/Int.pm
Expand Up @@ -45,6 +45,10 @@ my class Int {
my int $b = nqp::unbox_i($base.Int);
nqp::p6box_s(nqp::base_I(self, $b));
}

method floor(Int:D:) { self }
method round(Int:D:) { self }
method ceiling(Int:D:) { self }
}

multi prefix:<++>(Int:D \$a is rw) { # XXX
Expand Down
5 changes: 4 additions & 1 deletion src/core/Num.pm
Expand Up @@ -94,9 +94,12 @@ my class Num {
}

method ceiling(Num:D: ) {
nqp::p6box_n(pir::ceil__NN(nqp::unbox_n(self)));
# TODO: should check if self is -Inf/Inf/NaN, and otherwise
# use nqp::fromnum_I
nqp::p6bigint(pir::ceil__NN(nqp::unbox_n(self)));
}
method floor(Num:D: ) {
# TODO same as in ceiling()
nqp::p6bigint(pir::floor__NN(nqp::unbox_n(self)));
}

Expand Down
5 changes: 2 additions & 3 deletions src/core/Real.pm
Expand Up @@ -38,9 +38,8 @@ my class Real {
method acotanh() { self.Bridge.acotanh }
method floor() { self.Bridge.floor }
method ceiling() { self.Bridge.ceiling }
# causes "get_string() not implemented in class 'Int'"
# if commented out, but should be there
# method round($scale = 1) { (self / $scale + 0.5).floor * $scale }
# cannot use '0.5' here, because Rat isn't initialized yet
method round($scale = 1) { (self / $scale + 1/2).floor * $scale }
method unpolar(Real $angle) {
Complex.new(self * $angle.cos, self * $angle.sin);
}
Expand Down
2 changes: 1 addition & 1 deletion t/spectest.data
Expand Up @@ -539,7 +539,7 @@ S32-num/rand.t
S32-num/rat.t
# S32-num/real-bridge.t # err: Fixed2 cannot compose Real because it is not composable
S32-num/roots.t
# S32-num/rounders.t # err: Undefined routine '&round' called
S32-num/rounders.t
S32-num/sign.t
S32-num/sqrt.t
S32-num/unpolar.t
Expand Down

0 comments on commit f5c1975

Please sign in to comment.