summaryrefslogtreecommitdiff
path: root/complex.c
diff options
context:
space:
mode:
Diffstat (limited to 'complex.c')
-rw-r--r--complex.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/complex.c b/complex.c
index 9419ea98186..fc6ecbb0e09 100644
--- a/complex.c
+++ b/complex.c
@@ -535,6 +535,21 @@ m_sin(VALUE x)
#if 0
imp1(sqrt)
+VALUE
+rb_complex_sqrt(VALUE x)
+{
+ int pos;
+ VALUE a, re, im;
+ get_dat1(x);
+
+ pos = f_positive_p(dat->imag);
+ a = f_abs(x);
+ re = m_sqrt_bang(f_div(f_add(a, dat->real), TWO));
+ im = m_sqrt_bang(f_div(f_sub(a, dat->real), TWO));
+ if (!pos) im = f_negate(im);
+ return f_complex_new2(rb_cComplex, re, im);
+}
+
static VALUE
m_sqrt(VALUE x)
{
@@ -543,18 +558,7 @@ m_sqrt(VALUE x)
return m_sqrt_bang(x);
return f_complex_new2(rb_cComplex, ZERO, m_sqrt_bang(f_negate(x)));
}
- else {
- get_dat1(x);
-
- if (f_negative_p(dat->imag))
- return f_conj(m_sqrt(f_conj(x)));
- else {
- VALUE a = f_abs(x);
- return f_complex_new2(rb_cComplex,
- m_sqrt_bang(f_div(f_add(a, dat->real), TWO)),
- m_sqrt_bang(f_div(f_sub(a, dat->real), TWO)));
- }
- }
+ return rb_complex_sqrt(x);
}
#endif
@@ -1415,6 +1419,12 @@ rb_complex_set_imag(VALUE cmp, VALUE i)
return cmp;
}
+VALUE
+rb_complex_abs(VALUE cmp)
+{
+ return nucomp_abs(cmp);
+}
+
/*
* call-seq:
* cmp.to_i -> integer