summaryrefslogtreecommitdiff
path: root/complex.c
diff options
context:
space:
mode:
Diffstat (limited to 'complex.c')
-rw-r--r--complex.c37
1 files changed, 25 insertions, 12 deletions
diff --git a/complex.c b/complex.c
index da8945ea9f..39e8ad2f85 100644
--- a/complex.c
+++ b/complex.c
@@ -758,6 +758,13 @@ nucomp_arg(VALUE self)
}
static VALUE
+nucomp_rect(VALUE self)
+{
+ get_dat1(self);
+ return rb_assoc_new(dat->real, dat->image);
+}
+
+static VALUE
nucomp_polar(VALUE self)
{
return rb_assoc_new(f_abs(self), f_arg(self));
@@ -1004,14 +1011,15 @@ numeric_to_c(VALUE self)
static VALUE comp_pat0, comp_pat1, comp_pat2, a_slash, a_dot_and_an_e,
null_string, underscores_pat, an_underscore;
+#define WS "\\s*"
#define DIGITS "(?:\\d(?:_\\d|\\d)*)"
#define NUMERATOR "(?:" DIGITS "?\\.)?" DIGITS "(?:[eE][-+]?" DIGITS ")?"
#define DENOMINATOR DIGITS
#define NUMBER "[-+]?" NUMERATOR "(?:\\/" DENOMINATOR ")?"
#define NUMBERNOS NUMERATOR "(?:\\/" DENOMINATOR ")?"
-#define PATTERN0 "\\A(" NUMBER ")@(" NUMBER ")"
-#define PATTERN1 "\\A([-+])?(" NUMBER ")?[iIjJ]"
-#define PATTERN2 "\\A(" NUMBER ")(([-+])(" NUMBERNOS ")?[iIjJ])?"
+#define PATTERN0 "\\A" WS "(" NUMBER ")@(" NUMBER ")" WS
+#define PATTERN1 "\\A" WS "([-+])?(" NUMBER ")?[iIjJ]" WS
+#define PATTERN2 "\\A" WS "(" NUMBER ")(([-+])(" NUMBERNOS ")?[iIjJ])?" WS
static void
make_patterns(void)
@@ -1049,9 +1057,6 @@ make_patterns(void)
rb_global_variable(&an_underscore);
}
-#define id_strip rb_intern("strip")
-#define f_strip(x) rb_funcall(x, id_strip, 0)
-
#define id_match rb_intern("match")
#define f_match(x,y) rb_funcall(x, id_match, 1, y)
@@ -1078,7 +1083,7 @@ string_to_c_internal(VALUE self)
{
VALUE s;
- s = f_strip(self);
+ s = self;
if (RSTRING_LEN(s) == 0)
return rb_assoc_new(Qnil, self);
@@ -1297,6 +1302,12 @@ numeric_arg(VALUE self)
}
static VALUE
+numeric_rect(VALUE self)
+{
+ return rb_assoc_new(self, ZERO);
+}
+
+static VALUE
numeric_polar(VALUE self)
{
return rb_assoc_new(f_abs(self), f_arg(self));
@@ -1366,10 +1377,8 @@ Init_Complex(void)
rb_funcall(rb_cComplex, rb_intern("private_class_method"), 1,
ID2SYM(rb_intern("new")));
-#if 0
- rb_define_singleton_method(rb_cComplex, "rect", nucomp_s_new, -1);
rb_define_singleton_method(rb_cComplex, "rectangular", nucomp_s_new, -1);
-#endif
+ rb_define_singleton_method(rb_cComplex, "rect", nucomp_s_new, -1);
rb_define_singleton_method(rb_cComplex, "polar", nucomp_s_polar, 2);
rb_define_global_function(COMPLEX_NAME, nucomp_f_complex, -1);
@@ -1408,12 +1417,13 @@ Init_Complex(void)
rb_define_method(rb_cComplex, "coerce", nucomp_coerce, 1);
rb_define_method(rb_cComplex, "abs", nucomp_abs, 0);
-#if 0
rb_define_method(rb_cComplex, "magnitude", nucomp_abs, 0);
-#endif
rb_define_method(rb_cComplex, "abs2", nucomp_abs2, 0);
rb_define_method(rb_cComplex, "arg", nucomp_arg, 0);
rb_define_method(rb_cComplex, "angle", nucomp_arg, 0);
+ rb_define_method(rb_cComplex, "phase", nucomp_arg, 0);
+ rb_define_method(rb_cComplex, "rectangular", nucomp_rect, 0);
+ rb_define_method(rb_cComplex, "rect", nucomp_rect, 0);
rb_define_method(rb_cComplex, "polar", nucomp_polar, 0);
rb_define_method(rb_cComplex, "conjugate", nucomp_conjugate, 0);
rb_define_method(rb_cComplex, "conj", nucomp_conjugate, 0);
@@ -1465,6 +1475,9 @@ Init_Complex(void)
rb_define_method(rb_cNumeric, "imag", numeric_image, 0);
rb_define_method(rb_cNumeric, "arg", numeric_arg, 0);
rb_define_method(rb_cNumeric, "angle", numeric_arg, 0);
+ rb_define_method(rb_cNumeric, "phase", numeric_arg, 0);
+ rb_define_method(rb_cNumeric, "rectangular", numeric_rect, 0);
+ rb_define_method(rb_cNumeric, "rect", numeric_rect, 0);
rb_define_method(rb_cNumeric, "polar", numeric_polar, 0);
rb_define_method(rb_cNumeric, "conjugate", numeric_conjugate, 0);
rb_define_method(rb_cNumeric, "conj", numeric_conjugate, 0);