mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* numeric.c (num_quo): should return a Float for a Float argument.
[ruby-dev:44710] [Bug #5515] * test/ruby/test_fixnum.rb: Add an assertion for the above change. * test/ruby/test_bignum.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41099 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b43d6331cb
commit
febc42d05c
4 changed files with 32 additions and 15 deletions
|
@ -1,3 +1,12 @@
|
|||
Thu Jun 6 09:41:00 2013 Kenta Murata <mrkn@cookpad.com>
|
||||
|
||||
* numeric.c (num_quo): should return a Float for a Float argument.
|
||||
[ruby-dev:44710] [Bug #5515]
|
||||
|
||||
* test/ruby/test_fixnum.rb: Add an assertion for the above change.
|
||||
|
||||
* test/ruby/test_bignum.rb: ditto.
|
||||
|
||||
Thu Jun 6 00:59:44 2013 Masaya Tarui <tarui@ruby-lang.org>
|
||||
|
||||
* gc.c (gc_mark): get rid of pushing useless objests.
|
||||
|
|
33
numeric.c
33
numeric.c
|
@ -369,20 +369,6 @@ num_uminus(VALUE num)
|
|||
return rb_funcall(zero, '-', 1, num);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* num.quo(numeric) -> real
|
||||
*
|
||||
* Returns most exact division (rational for integers, float for floats).
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
num_quo(VALUE x, VALUE y)
|
||||
{
|
||||
return rb_funcall(rb_rational_raw1(x), '/', 1, y);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* num.fdiv(numeric) -> float
|
||||
|
@ -397,6 +383,25 @@ num_fdiv(VALUE x, VALUE y)
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* num.quo(int_or_rat) -> rat
|
||||
* num.quo(flo) -> flo
|
||||
*
|
||||
* Returns most exact division (rational for integers, float for floats).
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
num_quo(VALUE x, VALUE y)
|
||||
{
|
||||
if (RB_TYPE_P(y, T_FLOAT)) {
|
||||
return num_fdiv(x, y);
|
||||
}
|
||||
|
||||
return rb_funcall(rb_rational_raw1(x), '/', 1, y);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* num.div(numeric) -> integer
|
||||
|
|
|
@ -413,6 +413,8 @@ class TestBignum < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_quo
|
||||
assert_kind_of(Float, T32.quo(1.0))
|
||||
|
||||
assert_equal(T32.to_f, T32.quo(1))
|
||||
assert_equal(T32.to_f, T32.quo(1.0))
|
||||
assert_equal(T32.to_f, T32.quo(T_ONE))
|
||||
|
@ -420,7 +422,7 @@ class TestBignum < Test::Unit::TestCase
|
|||
assert_raise(TypeError) { T32.quo("foo") }
|
||||
|
||||
assert_equal(1024**1024, (1024**1024).quo(1))
|
||||
assert_equal(1024**1024, (1024**1024).quo(1.0))
|
||||
assert_equal(Float::INFINITY, (1024**1024).quo(1.0))
|
||||
assert_equal(1024**1024*2, (1024**1024*2).quo(1))
|
||||
inf = 1 / 0.0; nan = inf / inf
|
||||
|
||||
|
|
|
@ -157,6 +157,7 @@ class TestFixnum < Test::Unit::TestCase
|
|||
assert_equal(0, 1 / (2**32))
|
||||
assert_equal(0, 1.div(2**32))
|
||||
|
||||
assert_kind_of(Float, 1.quo(2.0))
|
||||
assert_equal(0.5, 1.quo(2.0))
|
||||
assert_equal(0.5, 1 / 2.0)
|
||||
assert_equal(0, 1.div(2.0))
|
||||
|
|
Loading…
Reference in a new issue