git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15803 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
tadf 2008-03-19 09:37:39 +00:00
parent 1ee96f7709
commit 80aa946f91
2 changed files with 39 additions and 43 deletions

View File

@ -202,7 +202,6 @@ nucomp_s_canonicalize_internal(VALUE klass, VALUE real, VALUE image)
} }
} }
#if 0
static VALUE static VALUE
nucomp_s_canonicalize(int argc, VALUE *argv, VALUE klass) nucomp_s_canonicalize(int argc, VALUE *argv, VALUE klass)
{ {
@ -236,7 +235,6 @@ nucomp_s_canonicalize(int argc, VALUE *argv, VALUE klass)
return nucomp_s_canonicalize_internal(klass, real, image); return nucomp_s_canonicalize_internal(klass, real, image);
} }
#endif
static VALUE static VALUE
nucomp_s_new(int argc, VALUE *argv, VALUE klass) nucomp_s_new(int argc, VALUE *argv, VALUE klass)
@ -461,7 +459,6 @@ m_atan2_bang(VALUE y, VALUE x)
return DOUBLE2NUM(atan2(RFLOAT_VALUE(y), RFLOAT_VALUE(x))); return DOUBLE2NUM(atan2(RFLOAT_VALUE(y), RFLOAT_VALUE(x)));
} }
#if 0
static VALUE static VALUE
m_hypot(VALUE x, VALUE y) m_hypot(VALUE x, VALUE y)
{ {
@ -469,7 +466,6 @@ m_hypot(VALUE x, VALUE y)
return DOUBLE2NUM(hypot(RFLOAT_VALUE(x), RFLOAT_VALUE(y))); return DOUBLE2NUM(hypot(RFLOAT_VALUE(x), RFLOAT_VALUE(y)));
} }
#endif #endif
#endif
static VALUE static VALUE
nucomp_s_polar(VALUE klass, VALUE abs, VALUE arg) nucomp_s_polar(VALUE klass, VALUE abs, VALUE arg)
@ -630,7 +626,6 @@ nucomp_rdiv(VALUE self, VALUE other)
f_to_r(dat->image)), other); f_to_r(dat->image)), other);
} }
#if 0
static VALUE static VALUE
nucomp_fdiv(VALUE self, VALUE other) nucomp_fdiv(VALUE self, VALUE other)
{ {
@ -640,7 +635,6 @@ nucomp_fdiv(VALUE self, VALUE other)
f_to_f(dat->real), f_to_f(dat->real),
f_to_f(dat->image)), other); f_to_f(dat->image)), other);
} }
#endif
static VALUE static VALUE
nucomp_expt(VALUE self, VALUE other) nucomp_expt(VALUE self, VALUE other)
@ -794,7 +788,6 @@ nucomp_conjugate(VALUE self)
return f_complex_new2(CLASS_OF(self), dat->real, f_negate(dat->image)); return f_complex_new2(CLASS_OF(self), dat->real, f_negate(dat->image));
} }
#if 0
static VALUE static VALUE
nucomp_real_p(VALUE self) nucomp_real_p(VALUE self)
{ {
@ -819,7 +812,6 @@ nucomp_inexact_p(VALUE self)
{ {
return f_boolcast(!nucomp_exact_p(self)); return f_boolcast(!nucomp_exact_p(self));
} }
#endif
inline static long inline static long
i_gcd(long x, long y) i_gcd(long x, long y)
@ -986,17 +978,17 @@ nucomp_to_s(VALUE self)
s = rb_str_new2(""); s = rb_str_new2("");
else { else {
s = f_to_s(dat->real); s = f_to_s(dat->real);
rb_str_cat2(s, (!impos ? "-" : "+")); rb_str_concat(s, rb_str_new2(!impos ? "-" : "+"));
} }
if (k_rational_p(dat->image) && if (k_rational_p(dat->image) &&
!f_one_p(f_denominator(dat->image))) { !f_one_p(f_denominator(dat->image))) {
rb_str_cat2(s, "("); rb_str_concat(s, rb_str_new2("("));
rb_str_concat(s, f_to_s(rezero ? dat->image : f_abs(dat->image))); rb_str_concat(s, f_to_s(rezero ? dat->image : f_abs(dat->image)));
rb_str_cat2(s, ")i"); rb_str_concat(s, rb_str_new2(")i"));
} else { } else {
rb_str_concat(s, f_to_s(rezero ? dat->image : f_abs(dat->image))); rb_str_concat(s, f_to_s(rezero ? dat->image : f_abs(dat->image)));
rb_str_cat2(s, "i"); rb_str_concat(s, rb_str_new2("i"));
} }
return s; return s;
@ -1011,9 +1003,9 @@ nucomp_inspect(VALUE self)
s = rb_str_new2("Complex("); s = rb_str_new2("Complex(");
rb_str_concat(s, f_inspect(dat->real)); rb_str_concat(s, f_inspect(dat->real));
rb_str_cat2(s, ", "); rb_str_concat(s, rb_str_new2(", "));
rb_str_concat(s, f_inspect(dat->image)); rb_str_concat(s, f_inspect(dat->image));
rb_str_cat2(s, ")"); rb_str_concat(s, rb_str_new2(")"));
return s; return s;
} }
@ -1117,7 +1109,7 @@ numeric_to_c(VALUE self)
} }
static VALUE comp_pat1, comp_pat2, a_slash, a_dot_and_an_e, static VALUE comp_pat1, comp_pat2, a_slash, a_dot_and_an_e,
image_garbages_pat, null_string; image_garbages_pat, null_string, underscores_pat, an_underscore;
#define DIGITS "(?:\\d(?:_\\d|\\d)*)" #define DIGITS "(?:\\d(?:_\\d|\\d)*)"
#define NUMERATOR "(?:" DIGITS "?\\.)?" DIGITS "(?:[eE][-+]?" DIGITS ")?" #define NUMERATOR "(?:" DIGITS "?\\.)?" DIGITS "(?:[eE][-+]?" DIGITS ")?"
@ -1130,15 +1122,15 @@ static VALUE comp_pat1, comp_pat2, a_slash, a_dot_and_an_e,
static void static void
make_patterns(void) make_patterns(void)
{ {
static const char comp_pat1_source[] = PATTERN1; static char *comp_pat1_source = PATTERN1;
static const char comp_pat2_source[] = PATTERN2; static char *comp_pat2_source = PATTERN2;
static const char image_garbages_pat_source[] = "[+\\(\\)iIjJ]"; static char *image_garbages_pat_source = "[+\\(\\)iIjJ]";
#define REG_NEW(s) rb_reg_new(s, sizeof(s) - 1, 0) static char *underscores_pat_source = "_+";
comp_pat1 = REG_NEW(comp_pat1_source); comp_pat1 = rb_reg_new(comp_pat1_source, strlen(comp_pat1_source), 0);
rb_global_variable(&comp_pat1); rb_global_variable(&comp_pat1);
comp_pat2 = REG_NEW(comp_pat2_source); comp_pat2 = rb_reg_new(comp_pat2_source, strlen(comp_pat2_source), 0);
rb_global_variable(&comp_pat2); rb_global_variable(&comp_pat2);
a_slash = rb_str_new2("/"); a_slash = rb_str_new2("/");
@ -1147,13 +1139,19 @@ make_patterns(void)
a_dot_and_an_e = rb_str_new2(".eE"); a_dot_and_an_e = rb_str_new2(".eE");
rb_global_variable(&a_dot_and_an_e); rb_global_variable(&a_dot_and_an_e);
image_garbages_pat = REG_NEW(image_garbages_pat_source); image_garbages_pat = rb_reg_new(image_garbages_pat_source,
strlen(image_garbages_pat_source), 0);
rb_global_variable(&image_garbages_pat); rb_global_variable(&image_garbages_pat);
null_string = rb_str_new2(""); null_string = rb_str_new2("");
rb_global_variable(&null_string); rb_global_variable(&null_string);
#undef REG_NEW underscores_pat = rb_reg_new(underscores_pat_source,
strlen(underscores_pat_source), 0);
rb_global_variable(&underscores_pat);
an_underscore = rb_str_new2("_");
rb_global_variable(&an_underscore);
} }
#define id_strip rb_intern("strip") #define id_strip rb_intern("strip")
@ -1248,7 +1246,8 @@ string_to_c_strict(VALUE self)
static VALUE static VALUE
string_to_c(VALUE self) string_to_c(VALUE self)
{ {
VALUE a = string_to_c_internal(self); VALUE s = f_gsub(self, underscores_pat, an_underscore);
VALUE a = string_to_c_internal(s);
if (!NIL_P(RARRAY_PTR(a)[0])) if (!NIL_P(RARRAY_PTR(a)[0]))
return RARRAY_PTR(a)[0]; return RARRAY_PTR(a)[0];
return rb_complex_new1(INT2FIX(0)); return rb_complex_new1(INT2FIX(0));

View File

@ -230,7 +230,6 @@ nurat_s_canonicalize_internal(VALUE klass, VALUE num, VALUE den)
return nurat_s_new_internal(klass, num, den); return nurat_s_new_internal(klass, num, den);
} }
#if 0
static VALUE static VALUE
nurat_s_canonicalize(int argc, VALUE *argv, VALUE klass) nurat_s_canonicalize(int argc, VALUE *argv, VALUE klass)
{ {
@ -260,7 +259,6 @@ nurat_s_canonicalize(int argc, VALUE *argv, VALUE klass)
return nurat_s_canonicalize_internal(klass, num, den); return nurat_s_canonicalize_internal(klass, num, den);
} }
#endif
static VALUE static VALUE
nurat_s_new(int argc, VALUE *argv, VALUE klass) nurat_s_new(int argc, VALUE *argv, VALUE klass)
@ -586,14 +584,11 @@ nurat_divmod(VALUE self, VALUE other)
return rb_assoc_new(val, f_sub(self, f_mul(other, val))); return rb_assoc_new(val, f_sub(self, f_mul(other, val)));
} }
#if 0
static VALUE static VALUE
nurat_quot(VALUE self, VALUE other) nurat_quot(VALUE self, VALUE other)
{ {
return f_truncate(f_div(self, other)); return f_truncate(f_div(self, other));
} }
#endif
static VALUE static VALUE
nurat_rem(VALUE self, VALUE other) nurat_rem(VALUE self, VALUE other)
{ {
@ -601,14 +596,12 @@ nurat_rem(VALUE self, VALUE other)
return f_sub(self, f_mul(other, val)); return f_sub(self, f_mul(other, val));
} }
#if 0
static VALUE static VALUE
nurat_quotrem(VALUE self, VALUE other) nurat_quotrem(VALUE self, VALUE other)
{ {
VALUE val = f_truncate(f_div(self, other)); VALUE val = f_truncate(f_div(self, other));
return rb_assoc_new(val, f_sub(self, f_mul(other, val))); return rb_assoc_new(val, f_sub(self, f_mul(other, val)));
} }
#endif
static VALUE static VALUE
nurat_abs(VALUE self) nurat_abs(VALUE self)
@ -619,13 +612,11 @@ nurat_abs(VALUE self)
return f_negate(self); return f_negate(self);
} }
#if 0
static VALUE static VALUE
nurat_true(VALUE self) nurat_true(VALUE self)
{ {
return Qtrue; return Qtrue;
} }
#endif
static VALUE static VALUE
nurat_floor(VALUE self) nurat_floor(VALUE self)
@ -783,7 +774,7 @@ float_to_r(VALUE self)
return f_mul(RARRAY_PTR(a)[0], f_expt(INT2FIX(FLT_RADIX), RARRAY_PTR(a)[1])); return f_mul(RARRAY_PTR(a)[0], f_expt(INT2FIX(FLT_RADIX), RARRAY_PTR(a)[1]));
} }
static VALUE rat_pat, an_e_pat, a_dot_pat; static VALUE rat_pat, an_e_pat, a_dot_pat, underscores_pat, an_underscore;
#define DIGITS "(?:\\d(?:_\\d|\\d)*)" #define DIGITS "(?:\\d(?:_\\d|\\d)*)"
#define NUMERATOR "(?:" DIGITS "?\\.)?" DIGITS "(?:[eE][-+]?" DIGITS ")?" #define NUMERATOR "(?:" DIGITS "?\\.)?" DIGITS "(?:[eE][-+]?" DIGITS ")?"
@ -793,21 +784,26 @@ static VALUE rat_pat, an_e_pat, a_dot_pat;
static void static void
make_patterns(void) make_patterns(void)
{ {
static const char rat_pat_source[] = PATTERN; static char *rat_pat_source = PATTERN;
static const char an_e_pat_source[] = "[eE]"; static char *an_e_pat_source = "[eE]";
static const char a_dot_pat_source[] = "\\."; static char *a_dot_pat_source = "\\.";
#define REG_NEW(s) rb_reg_new(s, sizeof(s) - 1, 0) static char *underscores_pat_source = "_+";
rat_pat = REG_NEW(rat_pat_source); rat_pat = rb_reg_new(rat_pat_source, strlen(rat_pat_source), 0);
rb_global_variable(&rat_pat); rb_global_variable(&rat_pat);
an_e_pat = REG_NEW(an_e_pat_source); an_e_pat = rb_reg_new(an_e_pat_source, strlen(an_e_pat_source), 0);
rb_global_variable(&an_e_pat); rb_global_variable(&an_e_pat);
a_dot_pat = REG_NEW(a_dot_pat_source); a_dot_pat = rb_reg_new(a_dot_pat_source, strlen(a_dot_pat_source), 0);
rb_global_variable(&a_dot_pat); rb_global_variable(&a_dot_pat);
#undef REG_NEW underscores_pat = rb_reg_new(underscores_pat_source,
strlen(underscores_pat_source), 0);
rb_global_variable(&underscores_pat);
an_underscore = rb_str_new2("_");
rb_global_variable(&an_underscore);
} }
#define id_strip rb_intern("strip") #define id_strip rb_intern("strip")
@ -912,7 +908,8 @@ string_to_r_strict(VALUE self)
static VALUE static VALUE
string_to_r(VALUE self) string_to_r(VALUE self)
{ {
VALUE a = string_to_r_internal(self); VALUE s = f_gsub(self, underscores_pat, an_underscore);
VALUE a = string_to_r_internal(s);
if (!NIL_P(RARRAY_PTR(a)[0])) if (!NIL_P(RARRAY_PTR(a)[0]))
return RARRAY_PTR(a)[0]; return RARRAY_PTR(a)[0];
return rb_rational_new1(INT2FIX(0)); return rb_rational_new1(INT2FIX(0));