зеркало из https://github.com/github/ruby.git
numeric.c: 0 % Float::NAN returns Float::NAN
* numeric.c (flodivmod): all results are NaN if divisor is NaN. [fix GH-692] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
528ef3ca93
Коммит
52b59fc9d9
|
@ -1,3 +1,8 @@
|
||||||
|
Fri Aug 1 16:35:32 2014 Evan Miller <evan@squareup.com>
|
||||||
|
|
||||||
|
* numeric.c (flodivmod): all results are NaN if divisor is NaN.
|
||||||
|
[fix GH-692]
|
||||||
|
|
||||||
Thu Aug 01 07:28:12 2014 Kenta Murata <mrkn@mrkn.jp>
|
Thu Aug 01 07:28:12 2014 Kenta Murata <mrkn@mrkn.jp>
|
||||||
|
|
||||||
* ext/bigdecimal/bigdecimal.c: [DOC] Add description of
|
* ext/bigdecimal/bigdecimal.c: [DOC] Add description of
|
||||||
|
|
|
@ -890,6 +890,12 @@ flodivmod(double x, double y, double *divp, double *modp)
|
||||||
{
|
{
|
||||||
double div, mod;
|
double div, mod;
|
||||||
|
|
||||||
|
if (isnan(y)) {
|
||||||
|
/* y is NaN so all results are NaN */
|
||||||
|
if (modp) *modp = y;
|
||||||
|
if (divp) *divp = y;
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (y == 0.0) rb_num_zerodiv();
|
if (y == 0.0) rb_num_zerodiv();
|
||||||
if ((x == 0.0) || (isinf(y) && !isinf(x)))
|
if ((x == 0.0) || (isinf(y) && !isinf(x)))
|
||||||
mod = x;
|
mod = x;
|
||||||
|
@ -903,7 +909,7 @@ flodivmod(double x, double y, double *divp, double *modp)
|
||||||
mod = x - z * y;
|
mod = x - z * y;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (isinf(x) && !isinf(y) && !isnan(y))
|
if (isinf(x) && !isinf(y))
|
||||||
div = x;
|
div = x;
|
||||||
else
|
else
|
||||||
div = (x - mod) / y;
|
div = (x - mod) / y;
|
||||||
|
|
|
@ -271,6 +271,12 @@ class TestFloat < Test::Unit::TestCase
|
||||||
assert_raise(ZeroDivisionError, bug6048) { 42 % 0 }
|
assert_raise(ZeroDivisionError, bug6048) { 42 % 0 }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_modulo4
|
||||||
|
assert_predicate((0.0).modulo(Float::NAN), :nan?)
|
||||||
|
assert_predicate((1.0).modulo(Float::NAN), :nan?)
|
||||||
|
assert_predicate(Float::INFINITY.modulo(1), :nan?)
|
||||||
|
end
|
||||||
|
|
||||||
def test_divmod2
|
def test_divmod2
|
||||||
assert_equal([1.0, 0.0], 2.0.divmod(2))
|
assert_equal([1.0, 0.0], 2.0.divmod(2))
|
||||||
assert_equal([1.0, 0.0], 2.0.divmod((2**32).coerce(2).first))
|
assert_equal([1.0, 0.0], 2.0.divmod((2**32).coerce(2).first))
|
||||||
|
|
Загрузка…
Ссылка в новой задаче