summaryrefslogtreecommitdiff
path: root/math.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-07-13 05:29:30 (GMT)
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-07-13 05:29:30 (GMT)
commit7b59234aaf296c63d389befe0ddd155999191316 (patch)
tree5a83e2ce3342a2b6efc3de698e442c9fc0f017f0 /math.c
parentd8c3672b012ec6eb55e097162c6c638e8d932471 (diff)
* 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
Diffstat (limited to 'math.c')
-rw-r--r--math.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/math.c b/math.c
index 8d36389..9cdf9e5 100644
--- a/math.c
+++ b/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);