summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-09 12:02:29 +0000
committertadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-09 12:02:29 +0000
commita20cf402cfa15e0f078e2750dc0fc17c44b529f6 (patch)
tree14396e33139bd6f790cbb8392a2aae427352a332
parentf8ef02adc40e364107bb7629cf9eca1e9097309a (diff)
* complex.c (nucomp_s_convert): can accept Complex('i').
[ruby-dev:34991] and some minor changes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17056 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--complex.c28
-rw-r--r--rational.c30
3 files changed, 37 insertions, 26 deletions
diff --git a/ChangeLog b/ChangeLog
index 37273816685..29fe0dc3941 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Mon Jun 9 21:00:32 2008 Tadayoshi Funaba <tadf@dotrb.org>
+
+ * complex.c (nucomp_s_convert): can accept Complex('i').
+ [ruby-dev:34991]
+
Mon Jun 9 18:25:30 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* include/ruby/ruby.h (CONST_ID): constant ID cache for non-gcc.
diff --git a/complex.c b/complex.c
index 6bc004a5d0d..f2f331a040a 100644
--- a/complex.c
+++ b/complex.c
@@ -1125,22 +1125,21 @@ numeric_to_c(VALUE self)
}
static VALUE comp_pat1, comp_pat2, a_slash, a_dot_and_an_e,
- image_garbages_pat, null_string, underscores_pat, an_underscore;
+ null_string, underscores_pat, an_underscore;
#define DIGITS "(?:\\d(?:_\\d|\\d)*)"
#define NUMERATOR "(?:" DIGITS "?\\.)?" DIGITS "(?:[eE][-+]?" DIGITS ")?"
#define DENOMINATOR "[-+]?" DIGITS
#define NUMBER "[-+]?" NUMERATOR "(?:\\/" DENOMINATOR ")?"
#define NUMBERNOS NUMERATOR "(?:\\/" DENOMINATOR ")?"
-#define PATTERN1 "\\A(" NUMBER "|\\(" NUMBER "\\))[iIjJ]"
-#define PATTERN2 "\\A(" NUMBER ")([-+](?:" NUMBERNOS "|\\(" NUMBER "\\))[iIjJ])?"
+#define PATTERN1 "\\A(" NUMBER "|\\(" NUMBER "\\))?[iIjJ]"
+#define PATTERN2 "\\A(" NUMBER ")(([-+])(?:(" NUMBERNOS ")|\\((" NUMBER ")\\))?[iIjJ])?"
static void
make_patterns(void)
{
static const char comp_pat1_source[] = PATTERN1;
static const char comp_pat2_source[] = PATTERN2;
- static const char image_garbages_pat_source[] = "[+\\(\\)iIjJ]";
static const char underscores_pat_source[] = "_+";
if (comp_pat1) return;
@@ -1157,10 +1156,6 @@ make_patterns(void)
a_dot_and_an_e = rb_str_new2(".eE");
rb_global_variable(&a_dot_and_an_e);
- image_garbages_pat = rb_reg_new(image_garbages_pat_source,
- sizeof image_garbages_pat_source - 1, 0);
- rb_global_variable(&image_garbages_pat);
-
null_string = rb_str_new2("");
rb_global_variable(&null_string);
@@ -1213,6 +1208,8 @@ string_to_c_internal(VALUE self)
if (!NIL_P(m)) {
sr = Qnil;
si = f_aref(m, INT2FIX(1));
+ if (NIL_P(si))
+ si = rb_str_new2("1");
re = f_post_match(m);
}
if (NIL_P(m)) {
@@ -1220,7 +1217,19 @@ string_to_c_internal(VALUE self)
if (NIL_P(m))
return rb_assoc_new(Qnil, self);
sr = f_aref(m, INT2FIX(1));
- si = f_aref(m, INT2FIX(2));
+ if (NIL_P(f_aref(m, INT2FIX(2))))
+ si = Qnil;
+ else {
+ VALUE t;
+
+ si = f_aref(m, INT2FIX(3));
+ t = f_aref(m, INT2FIX(4));
+ if (NIL_P(t))
+ t = f_aref(m, INT2FIX(5));
+ if (NIL_P(t))
+ t = rb_str_new2("1");
+ rb_str_concat(si, t);
+ }
re = f_post_match(m);
}
r = INT2FIX(0);
@@ -1234,7 +1243,6 @@ string_to_c_internal(VALUE self)
r = f_to_i(sr);
}
if (!NIL_P(si)) {
- f_gsub_bang(si, image_garbages_pat, null_string);
if (f_include_p(si, a_slash))
i = f_to_r(si);
else if (f_gt_p(f_count(si, a_dot_and_an_e), INT2FIX(0)))
diff --git a/rational.c b/rational.c
index 8bf786a1663..54bca51094e 100644
--- a/rational.c
+++ b/rational.c
@@ -512,25 +512,19 @@ nurat_s_canonicalize(int argc, VALUE *argv, VALUE klass)
#endif
static VALUE
-nurat_s_new(VALUE klass, VALUE num, VALUE den)
+nurat_s_new(int argc, VALUE *argv, VALUE klass)
{
+ VALUE num, den;
+
+ if (rb_scan_args(argc, argv, "11", &num, &den) == 1)
+ den = ONE;
+
nurat_int_check(num);
nurat_int_check(den);
return nurat_s_canonicalize_internal(klass, num, den);
}
-static VALUE
-nurat_s_new_m(int argc, VALUE *argv, VALUE klass)
-{
- VALUE num, den;
-
- if (rb_scan_args(argc, argv, "11", &num, &den) == 1) {
- den = ONE;
- }
- return nurat_s_new(klass, num, den);
-}
-
inline static VALUE
f_rational_new1(VALUE klass, VALUE x)
{
@@ -1428,9 +1422,8 @@ nurat_s_convert(int argc, VALUE *argv, VALUE klass)
{
VALUE a1, a2;
- if (rb_scan_args(argc, argv, "02", &a1, &a2) == 1) {
+ if (rb_scan_args(argc, argv, "02", &a1, &a2) == 1)
a2 = ONE;
- }
switch (TYPE(a1)) {
case T_COMPLEX:
@@ -1489,7 +1482,12 @@ nurat_s_convert(int argc, VALUE *argv, VALUE klass)
return f_div(a1, a2);
}
- return nurat_s_new(klass, a1, a2);
+ {
+ VALUE argv2[2];
+ argv2[0] = a1;
+ argv2[1] = a2;
+ return nurat_s_new(argc, argv2, klass);
+ }
}
static VALUE
@@ -1533,7 +1531,7 @@ Init_Rational(void)
rb_funcall(rb_cRational, rb_intern("private_class_method"), 1,
ID2SYM(rb_intern("new!")));
- rb_define_singleton_method(rb_cRational, "new", nurat_s_new_m, -1);
+ rb_define_singleton_method(rb_cRational, "new", nurat_s_new, -1);
rb_funcall(rb_cRational, rb_intern("private_class_method"), 1,
ID2SYM(rb_intern("new")));