mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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/trunk@58523 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
55e99ef5eb
commit
fbb38d6d6a
1 changed files with 12 additions and 2 deletions
14
rational.c
14
rational.c
|
@ -2073,9 +2073,14 @@ static VALUE
|
||||||
float_numerator(VALUE self)
|
float_numerator(VALUE self)
|
||||||
{
|
{
|
||||||
double d = RFLOAT_VALUE(self);
|
double d = RFLOAT_VALUE(self);
|
||||||
|
VALUE r;
|
||||||
if (isinf(d) || isnan(d))
|
if (isinf(d) || isnan(d))
|
||||||
return self;
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -2091,9 +2096,14 @@ static VALUE
|
||||||
float_denominator(VALUE self)
|
float_denominator(VALUE self)
|
||||||
{
|
{
|
||||||
double d = RFLOAT_VALUE(self);
|
double d = RFLOAT_VALUE(self);
|
||||||
|
VALUE r;
|
||||||
if (isinf(d) || isnan(d))
|
if (isinf(d) || isnan(d))
|
||||||
return INT2FIX(1);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Add table
Reference in a new issue