Skip to content
Permalink
Browse files

Merge pull request #764 from kachick/fix-integer-round

Fix Integer#round
  • Loading branch information
alex committed Jun 24, 2013
2 parents f481d57 + 705811d commit 95db3a34a99badbb7a8037622fae8931caa8fde1
Showing with 6 additions and 7 deletions.
  1. +6 −6 lib-topaz/integer.rb
  2. +0 −1 spec/tags/core/integer/round_tags.txt
@@ -53,11 +53,11 @@ def odd?
!even?
end

def round(ndigits = nil)
if ndigits.nil?
def round(*ndigits)
if ndigits.empty?
return self
end
ndigits = Topaz.convert_type(ndigits, Fixnum, :to_int)
ndigits = Topaz.convert_type(ndigits[0], Fixnum, :to_int)
if ndigits == 0
return self
end
@@ -73,9 +73,9 @@ def round(ndigits = nil)
return 0
end
h = f / 2
r = num % f
n = num - r
if ((num < 0 && r <= h) || r < h)
r = bytes % f
n = bytes - r
if ((bytes < 0 && r <= h) || r < h)
n = f + 1
end
return n
@@ -1,4 +1,3 @@
fails:Integer#round returns itself rounded if passed a negative value
fails:Integer#round raises a RangeError when passed Float::INFINITY
fails:Integer#round raises a RangeError when passed a beyond signed int
fails:Integer#round raises a TypeError when its argument cannot be converted to an Integer

0 comments on commit 95db3a3

Please sign in to comment.
You can’t perform that action at this time.