ruby-changes:43584
From: naruse <ko1@a...>
Date: Wed, 13 Jul 2016 14:29:34 +0900 (JST)
Subject: [ruby-changes:43584] naruse:r55657 (trunk): * math.c (rb_math_sqrt): r55646 must use f_signbit.
naruse 2016-07-13 14:29:30 +0900 (Wed, 13 Jul 2016) New Revision: 55657 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55657 Log: * math.c (rb_math_sqrt): r55646 must use f_signbit. Modified files: trunk/ChangeLog trunk/math.c Index: math.c =================================================================== --- math.c (revision 55656) +++ math.c (revision 55657) @@ -591,13 +591,31 @@ math_sqrt(VALUE obj, VALUE x) https://github.com/ruby/ruby/blob/trunk/math.c#L591 return rb_math_sqrt(x); } +#define f_boolcast(x) ((x) ? Qtrue : Qfalse) +inline static VALUE +f_negative_p(VALUE x) +{ + if (FIXNUM_P(x)) + return f_boolcast(FIX2LONG(x) < 0); + return rb_funcall(x, '<', 1, INT2FIX(0)); +} +inline static VALUE +f_signbit(VALUE x) +{ + if (RB_TYPE_P(x, T_FLOAT)) { + double f = RFLOAT_VALUE(x); + return f_boolcast(!isnan(f) && signbit(f)); + } + return f_negative_p(x); +} + VALUE rb_math_sqrt(VALUE x) { double d; if (RB_TYPE_P(x, T_COMPLEX)) { - int neg = signbit(RCOMPLEX(x)->imag); + int neg = f_signbit(RCOMPLEX(x)->imag); double re = Get_Double(RCOMPLEX(x)->real), im; d = Get_Double(rb_complex_abs(x)); im = sqrt((d - re) / 2.0); Index: ChangeLog =================================================================== --- ChangeLog (revision 55656) +++ ChangeLog (revision 55657) @@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Jul 13 14:28:33 2016 NARUSE, Yui <naruse@r...> + + * math.c (rb_math_sqrt): r55646 must use f_signbit. + Wed Jul 13 14:22:50 2016 Koichi Sasada <ko1@a...> * iseq.c (Init_ISeq): undef ISeq.translate and ISeq.load_iseq -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/