1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

merge revision(s) 58523: [Backport #13528]

rational.c: canonicalization case

	* rational.c (float_numerator, float_denominator): fix for
	  canonicalization case where `Float#to_r` could return an Integer
	  not a Rational.  although mathn.rb has been removed in the
	  trunk, fix for the backport purpose.
	  [ruby-core:80942] [Bug #13528]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_4@59510 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nagachika 2017-08-05 01:45:39 +00:00
parent f7bd8a08ec
commit 61277d473c
2 changed files with 13 additions and 3 deletions

View file

@ -2022,9 +2022,14 @@ static VALUE
float_numerator(VALUE self)
{
double d = RFLOAT_VALUE(self);
VALUE r;
if (isinf(d) || isnan(d))
return self;
return nurat_numerator(float_to_r(self));
r = float_to_r(self);
if (canonicalization && k_integer_p(r)) {
return r;
}
return nurat_numerator(r);
}
/*
@ -2040,9 +2045,14 @@ static VALUE
float_denominator(VALUE self)
{
double d = RFLOAT_VALUE(self);
VALUE r;
if (isinf(d) || isnan(d))
return INT2FIX(1);
return nurat_denominator(float_to_r(self));
r = float_to_r(self);
if (canonicalization && k_integer_p(r)) {
return ONE;
}
return nurat_denominator(r);
}
/*

View file

@ -1,6 +1,6 @@
#define RUBY_VERSION "2.4.2"
#define RUBY_RELEASE_DATE "2017-08-05"
#define RUBY_PATCHLEVEL 173
#define RUBY_PATCHLEVEL 174
#define RUBY_RELEASE_YEAR 2017
#define RUBY_RELEASE_MONTH 8