ruby-changes:52687
From: nobu <ko1@a...>
Date: Wed, 3 Oct 2018 03:03:49 +0900 (JST)
Subject: [ruby-changes:52687] nobu:r64899 (trunk): Get rid of calling to_f in rat2dbl_without_to_f
nobu 2018-10-03 03:03:43 +0900 (Wed, 03 Oct 2018) New Revision: 64899 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64899 Log: Get rid of calling to_f in rat2dbl_without_to_f [Bug #15189] Modified files: trunk/object.c Index: object.c =================================================================== --- object.c (revision 64898) +++ object.c (revision 64899) @@ -3421,17 +3421,16 @@ rb_str_to_dbl(VALUE str, int badcheck) https://github.com/ruby/ruby/blob/trunk/object.c#L3421 #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 num2dbl_without_to_f(x) \ + (FIXNUM_P(x) ? fix2dbl_without_to_f(x) : \ + RB_TYPE_P(x, T_BIGNUM) ? big2dbl_without_to_f(x) : \ + (Check_Type(x, T_FLOAT), RFLOAT_VALUE(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); - } + return num2dbl_without_to_f(num) / num2dbl_without_to_f(den); } #define special_const_to_float(val, pre, post) \ -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/