mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* numeric.c (num_div): use floor rather than rb_Integer().
[ruby-dev:28589] * numeric.c (flo_divmod): the first element of Float#divmod should be an integer. [ruby-dev:28589] * test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder. * util.c (ruby_strtod): fixed wrong conversion. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@10123 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a6fdf0bbcd
commit
9466848db3
4 changed files with 81 additions and 71 deletions
|
|
@ -87,4 +87,32 @@ class TestFloat < Test::Unit::TestCase
|
|||
assert_raise(ArgumentError){Float("1e")}
|
||||
# add expected behaviour here.
|
||||
end
|
||||
|
||||
def test_divmod
|
||||
assert_equal([2, 3.5], 11.5.divmod(4))
|
||||
assert_equal([-3, -0.5], 11.5.divmod(-4))
|
||||
assert_equal([-3, 0.5], (-11.5).divmod(4))
|
||||
assert_equal([2, -3.5], (-11.5).divmod(-4))
|
||||
end
|
||||
|
||||
def test_div
|
||||
assert_equal(2, 11.5.div(4))
|
||||
assert_equal(-3, 11.5.div(-4))
|
||||
assert_equal(-3, (-11.5).div(4))
|
||||
assert_equal(2, (-11.5).div(-4))
|
||||
end
|
||||
|
||||
def test_modulo
|
||||
assert_equal(3.5, 11.5.modulo(4))
|
||||
assert_equal(-0.5, 11.5.modulo(-4))
|
||||
assert_equal(0.5, (-11.5).modulo(4))
|
||||
assert_equal(-3.5, (-11.5).modulo(-4))
|
||||
end
|
||||
|
||||
def test_remainder
|
||||
assert_equal(3.5, 11.5.remainder(4))
|
||||
assert_equal(3.5, 11.5.remainder(-4))
|
||||
assert_equal(-3.5, (-11.5).remainder(4))
|
||||
assert_equal(-3.5, (-11.5).remainder(-4))
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue