mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* math.c (rb_math_sqrt): r55646 must use f_signbit.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55657 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d8c3672b01
commit
7b59234aaf
2 changed files with 23 additions and 1 deletions
|
@ -1,3 +1,7 @@
|
|||
Wed Jul 13 14:28:33 2016 NARUSE, Yui <naruse@ruby-lang.org>
|
||||
|
||||
* math.c (rb_math_sqrt): r55646 must use f_signbit.
|
||||
|
||||
Wed Jul 13 14:22:50 2016 Koichi Sasada <ko1@atdot.net>
|
||||
|
||||
* iseq.c (Init_ISeq): undef ISeq.translate and ISeq.load_iseq
|
||||
|
|
20
math.c
20
math.c
|
@ -591,13 +591,31 @@ math_sqrt(VALUE obj, VALUE x)
|
|||
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);
|
||||
|
|
Loading…
Reference in a new issue