Skip to content
Browse files

fix rounders

Does not handle big ints properly, but this is as good as old master ever got
  • Loading branch information...
1 parent fdba160 commit f5c197569d5521b152b01e25f8adc0f5d5295acc @moritz moritz committed Dec 6, 2011
Showing with 11 additions and 5 deletions.
  1. +4 −0 src/core/Int.pm
  2. +4 −1 src/core/Num.pm
  3. +2 −3 src/core/Real.pm
  4. +1 −1 t/spectest.data
View
4 src/core/Int.pm
@@ -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
View
5 src/core/Num.pm
@@ -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)));
}
View
5 src/core/Real.pm
@@ -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);
}
View
2 t/spectest.data
@@ -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

0 comments on commit f5c1975

Please sign in to comment.
Something went wrong with that request. Please try again.