* complex.c, rational.c: omitted some method calls.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31330 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
bedb18f282
commit
14491f13d7
@ -1,3 +1,7 @@
|
|||||||
|
Sun Apr 24 22:19:05 2011 Tadayoshi Funaba <tadf@dotrb.org>
|
||||||
|
|
||||||
|
* complex.c, rational.c: omitted some method calls.
|
||||||
|
|
||||||
Sun Apr 24 02:57:27 2011 Tadayoshi Funaba <tadf@dotrb.org>
|
Sun Apr 24 02:57:27 2011 Tadayoshi Funaba <tadf@dotrb.org>
|
||||||
|
|
||||||
* ext/date/date_parse.c (n2i): takes long.
|
* ext/date/date_parse.c (n2i): takes long.
|
||||||
|
36
complex.c
36
complex.c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
complex.c: Coded by Tadayoshi Funaba 2008-2010
|
complex.c: Coded by Tadayoshi Funaba 2008-2011
|
||||||
|
|
||||||
This implementation is based on Keiju Ishitsuka's Complex library
|
This implementation is based on Keiju Ishitsuka's Complex library
|
||||||
which is written in ruby.
|
which is written in ruby.
|
||||||
@ -162,8 +162,21 @@ fun1(numerator)
|
|||||||
fun1(real)
|
fun1(real)
|
||||||
fun1(real_p)
|
fun1(real_p)
|
||||||
|
|
||||||
fun1(to_f)
|
inline static VALUE
|
||||||
fun1(to_i)
|
f_to_i(VALUE x)
|
||||||
|
{
|
||||||
|
if (TYPE(x) == T_STRING)
|
||||||
|
return rb_str_to_inum(x, 10, 0);
|
||||||
|
return rb_funcall(x, id_to_i, 0);
|
||||||
|
}
|
||||||
|
inline static VALUE
|
||||||
|
f_to_f(VALUE x)
|
||||||
|
{
|
||||||
|
if (TYPE(x) == T_STRING)
|
||||||
|
return DBL2NUM(rb_str_to_dbl(x, 0));
|
||||||
|
return rb_funcall(x, id_to_f, 0);
|
||||||
|
}
|
||||||
|
|
||||||
fun1(to_r)
|
fun1(to_r)
|
||||||
fun1(to_s)
|
fun1(to_s)
|
||||||
|
|
||||||
@ -1438,15 +1451,6 @@ make_patterns(void)
|
|||||||
#define id_post_match rb_intern("post_match")
|
#define id_post_match rb_intern("post_match")
|
||||||
#define f_post_match(x) rb_funcall((x), id_post_match, 0)
|
#define f_post_match(x) rb_funcall((x), id_post_match, 0)
|
||||||
|
|
||||||
#define id_split rb_intern("split")
|
|
||||||
#define f_split(x,y) rb_funcall((x), id_split, 1, (y))
|
|
||||||
|
|
||||||
#define id_include_p rb_intern("include?")
|
|
||||||
#define f_include_p(x,y) rb_funcall((x), id_include_p, 1, (y))
|
|
||||||
|
|
||||||
#define id_count rb_intern("count")
|
|
||||||
#define f_count(x,y) rb_funcall((x), id_count, 1, (y))
|
|
||||||
|
|
||||||
#define id_gsub_bang rb_intern("gsub!")
|
#define id_gsub_bang rb_intern("gsub!")
|
||||||
#define f_gsub_bang(x,y,z) rb_funcall((x), id_gsub_bang, 2, (y), (z))
|
#define f_gsub_bang(x,y,z) rb_funcall((x), id_gsub_bang, 2, (y), (z))
|
||||||
|
|
||||||
@ -1512,17 +1516,17 @@ string_to_c_internal(VALUE self)
|
|||||||
r = INT2FIX(0);
|
r = INT2FIX(0);
|
||||||
i = INT2FIX(0);
|
i = INT2FIX(0);
|
||||||
if (!NIL_P(sr)) {
|
if (!NIL_P(sr)) {
|
||||||
if (f_include_p(sr, a_slash))
|
if (strchr(RSTRING_PTR(sr), '/'))
|
||||||
r = f_to_r(sr);
|
r = f_to_r(sr);
|
||||||
else if (f_gt_p(f_count(sr, a_dot_and_an_e), INT2FIX(0)))
|
else if (strchr(RSTRING_PTR(sr), '.'))
|
||||||
r = f_to_f(sr);
|
r = f_to_f(sr);
|
||||||
else
|
else
|
||||||
r = f_to_i(sr);
|
r = f_to_i(sr);
|
||||||
}
|
}
|
||||||
if (!NIL_P(si)) {
|
if (!NIL_P(si)) {
|
||||||
if (f_include_p(si, a_slash))
|
if (strchr(RSTRING_PTR(si), '/'))
|
||||||
i = f_to_r(si);
|
i = f_to_r(si);
|
||||||
else if (f_gt_p(f_count(si, a_dot_and_an_e), INT2FIX(0)))
|
else if (strchr(RSTRING_PTR(si), '.'))
|
||||||
i = f_to_f(si);
|
i = f_to_f(si);
|
||||||
else
|
else
|
||||||
i = f_to_i(si);
|
i = f_to_i(si);
|
||||||
|
65
rational.c
65
rational.c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
rational.c: Coded by Tadayoshi Funaba 2008-2010
|
rational.c: Coded by Tadayoshi Funaba 2008-2011
|
||||||
|
|
||||||
This implementation is based on Keiju Ishitsuka's Rational library
|
This implementation is based on Keiju Ishitsuka's Rational library
|
||||||
which is written in ruby.
|
which is written in ruby.
|
||||||
@ -136,8 +136,22 @@ fun1(floor)
|
|||||||
fun1(inspect)
|
fun1(inspect)
|
||||||
fun1(integer_p)
|
fun1(integer_p)
|
||||||
fun1(negate)
|
fun1(negate)
|
||||||
fun1(to_f)
|
|
||||||
fun1(to_i)
|
inline static VALUE
|
||||||
|
f_to_i(VALUE x)
|
||||||
|
{
|
||||||
|
if (TYPE(x) == T_STRING)
|
||||||
|
return rb_str_to_inum(x, 10, 0);
|
||||||
|
return rb_funcall(x, id_to_i, 0);
|
||||||
|
}
|
||||||
|
inline static VALUE
|
||||||
|
f_to_f(VALUE x)
|
||||||
|
{
|
||||||
|
if (TYPE(x) == T_STRING)
|
||||||
|
return DBL2NUM(rb_str_to_dbl(x, 0));
|
||||||
|
return rb_funcall(x, id_to_f, 0);
|
||||||
|
}
|
||||||
|
|
||||||
fun1(to_s)
|
fun1(to_s)
|
||||||
fun1(truncate)
|
fun1(truncate)
|
||||||
|
|
||||||
@ -153,6 +167,8 @@ fun2(expt)
|
|||||||
fun2(fdiv)
|
fun2(fdiv)
|
||||||
fun2(idiv)
|
fun2(idiv)
|
||||||
|
|
||||||
|
#define f_expt10(x) f_expt(INT2FIX(10), x)
|
||||||
|
|
||||||
inline static VALUE
|
inline static VALUE
|
||||||
f_negative_p(VALUE x)
|
f_negative_p(VALUE x)
|
||||||
{
|
{
|
||||||
@ -1208,7 +1224,7 @@ f_round_common(int argc, VALUE *argv, VALUE self, VALUE (*func)(VALUE))
|
|||||||
if (!k_integer_p(n))
|
if (!k_integer_p(n))
|
||||||
rb_raise(rb_eTypeError, "not an integer");
|
rb_raise(rb_eTypeError, "not an integer");
|
||||||
|
|
||||||
b = f_expt(INT2FIX(10), n);
|
b = f_expt10(n);
|
||||||
s = f_mul(self, b);
|
s = f_mul(self, b);
|
||||||
|
|
||||||
s = (*func)(s);
|
s = (*func)(s);
|
||||||
@ -2035,25 +2051,37 @@ string_to_r_internal(VALUE self)
|
|||||||
{
|
{
|
||||||
VALUE a;
|
VALUE a;
|
||||||
|
|
||||||
a = f_split(nu, an_e_pat);
|
if (!strpbrk(RSTRING_PTR(nu), "eE")) {
|
||||||
ifp = RARRAY_PTR(a)[0];
|
ifp = nu; /* not a copy */
|
||||||
if (RARRAY_LEN(a) != 2)
|
|
||||||
exp = Qnil;
|
exp = Qnil;
|
||||||
else
|
}
|
||||||
exp = RARRAY_PTR(a)[1];
|
else {
|
||||||
|
a = f_split(nu, an_e_pat);
|
||||||
|
ifp = RARRAY_PTR(a)[0];
|
||||||
|
if (RARRAY_LEN(a) != 2)
|
||||||
|
exp = Qnil;
|
||||||
|
else
|
||||||
|
exp = RARRAY_PTR(a)[1];
|
||||||
|
}
|
||||||
|
|
||||||
a = f_split(ifp, a_dot_pat);
|
if (!strchr(RSTRING_PTR(ifp), '.')) {
|
||||||
ip = RARRAY_PTR(a)[0];
|
ip = ifp; /* not a copy */
|
||||||
if (RARRAY_LEN(a) != 2)
|
|
||||||
fp = Qnil;
|
fp = Qnil;
|
||||||
else
|
}
|
||||||
fp = RARRAY_PTR(a)[1];
|
else {
|
||||||
|
a = f_split(ifp, a_dot_pat);
|
||||||
|
ip = RARRAY_PTR(a)[0];
|
||||||
|
if (RARRAY_LEN(a) != 2)
|
||||||
|
fp = Qnil;
|
||||||
|
else
|
||||||
|
fp = RARRAY_PTR(a)[1];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
v = rb_rational_new1(f_to_i(ip));
|
v = rb_rational_new1(f_to_i(ip));
|
||||||
|
|
||||||
if (!NIL_P(fp)) {
|
if (!NIL_P(fp)) {
|
||||||
char *p = StringValuePtr(fp);
|
char *p = RSTRING_PTR(fp);
|
||||||
long count = 0;
|
long count = 0;
|
||||||
VALUE l;
|
VALUE l;
|
||||||
|
|
||||||
@ -2062,16 +2090,15 @@ string_to_r_internal(VALUE self)
|
|||||||
count++;
|
count++;
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
|
l = f_expt10(LONG2NUM(count));
|
||||||
l = f_expt(INT2FIX(10), LONG2NUM(count));
|
|
||||||
v = f_mul(v, l);
|
v = f_mul(v, l);
|
||||||
v = f_add(v, f_to_i(fp));
|
v = f_add(v, f_to_i(fp));
|
||||||
v = f_div(v, l);
|
v = f_div(v, l);
|
||||||
}
|
}
|
||||||
if (!NIL_P(si) && *StringValuePtr(si) == '-')
|
if (!NIL_P(si) && *RSTRING_PTR(si) == '-')
|
||||||
v = f_negate(v);
|
v = f_negate(v);
|
||||||
if (!NIL_P(exp))
|
if (!NIL_P(exp))
|
||||||
v = f_mul(v, f_expt(INT2FIX(10), f_to_i(exp)));
|
v = f_mul(v, f_expt10(f_to_i(exp)));
|
||||||
#if 0
|
#if 0
|
||||||
if (!NIL_P(de) && (!NIL_P(fp) || !NIL_P(exp)))
|
if (!NIL_P(de) && (!NIL_P(fp) || !NIL_P(exp)))
|
||||||
return rb_assoc_new(v, rb_usascii_str_new2("dummy"));
|
return rb_assoc_new(v, rb_usascii_str_new2("dummy"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user