aboutsummaryrefslogtreecommitdiffstats
path: root/numeric.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-12-28 04:40:58 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-12-28 04:40:58 +0000
commitf9a8bf4d13024520c1c84a62cc50e2b20af6ed16 (patch)
treefe67be8cec29a6a9148b0804a3f8882baaef6126 /numeric.c
parent621c12da8cf131ea3ba9024131b1e125b55862cd (diff)
downloadruby-f9a8bf4d13024520c1c84a62cc50e2b20af6ed16.tar.gz
numeric.c: reduce fdiv
* numeric.c (rb_int_fdiv_double): reduce first for more precise result. [ruby-core:78886] [Bug #13078] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57227 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/numeric.c b/numeric.c
index 01f9f45420..28ad30d764 100644
--- a/numeric.c
+++ b/numeric.c
@@ -3614,6 +3614,13 @@ fix_fdiv_double(VALUE x, VALUE y)
double
rb_int_fdiv_double(VALUE x, VALUE y)
{
+ if (RB_INTEGER_TYPE_P(y) && !FIXNUM_ZERO_P(y)) {
+ VALUE gcd = rb_gcd(x, y);
+ if (!FIXNUM_ZERO_P(gcd)) {
+ x = rb_int_idiv(x, gcd);
+ y = rb_int_idiv(y, gcd);
+ }
+ }
if (FIXNUM_P(x)) {
return fix_fdiv_double(x, y);
}