diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-10-02 16:42:21 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-10-02 16:42:21 +0000 |
commit | 603f95a0ed37d90854f80393881fb38ab29128a7 (patch) | |
tree | 2f76d289cf541c53cb29dff917569d0846a12613 /object.c | |
parent | 25ea4dc6230f3141dcb3b9d04c9124bc07146bca (diff) | |
download | ruby-603f95a0ed37d90854f80393881fb38ab29128a7.tar.gz |
Fix Rational of Float
[ruby-core:89239] [Bug #15189]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64897 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'object.c')
-rw-r--r-- | object.c | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -3421,9 +3421,18 @@ rb_str_to_dbl(VALUE str, int badcheck) #define big2dbl_without_to_f(x) rb_big2dbl(x) #define int2dbl_without_to_f(x) \ (FIXNUM_P(x) ? fix2dbl_without_to_f(x) : big2dbl_without_to_f(x)) -#define rat2dbl_without_to_f(x) \ - (int2dbl_without_to_f(rb_rational_num(x)) / \ - int2dbl_without_to_f(rb_rational_den(x))) +static inline double +rat2dbl_without_to_f(VALUE x) +{ + VALUE num = rb_rational_num(x); + VALUE den = rb_rational_den(x); + if (RB_INTEGER_TYPE_P(num) && RB_INTEGER_TYPE_P(den)) { + return int2dbl_without_to_f(num) / int2dbl_without_to_f(den); + } + else { + return NUM2DBL(num) / NUM2DBL(den); + } +} #define special_const_to_float(val, pre, post) \ switch (val) { \ |