ruby-changes:4405
From: ko1@a...
Date: Thu, 3 Apr 2008 21:55:42 +0900 (JST)
Subject: [ruby-changes:4405] tadf - Ruby:r15896 (trunk): * complex.c (nucomp_int_check): function for DRY real check.
tadf 2008-04-03 21:55:27 +0900 (Thu, 03 Apr 2008)
New Revision: 15896
Modified files:
trunk/ChangeLog
trunk/complex.c
trunk/rational.c
Log:
* complex.c (nucomp_int_check): function for DRY real check.
* complex.c (nucomp_{add,sub,mul,div,expt}): use rb_num_coerce_bin().
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/complex.c?r1=15896&r2=15895&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=15896&r2=15895&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/rational.c?r1=15896&r2=15895&diff_format=u
Index: complex.c
===================================================================
--- complex.c (revision 15895)
+++ complex.c (revision 15896)
@@ -22,7 +22,7 @@
VALUE rb_cComplex;
static ID id_Unify, id_abs, id_abs2, id_arg, id_atan2_bang, id_cmp,
- id_coerce, id_conjugate, id_convert, id_cos, id_denominator, id_divmod,
+ id_conjugate, id_convert, id_cos, id_denominator, id_divmod,
id_equal_p, id_exact_p, id_exp_bang, id_expt, id_floor, id_format,
id_hypot, id_idiv, id_inspect, id_log_bang, id_negate, id_new, id_new_bang,
id_numerator, id_polar, id_quo, id_scalar_p, id_sin, id_sqrt, id_to_f,
@@ -200,7 +200,6 @@
fun1(to_s)
fun1(truncate)
-fun2(coerce)
fun2(divmod)
inline static VALUE
@@ -370,6 +369,20 @@
#define f_unify_p(klass) rb_const_defined(klass, id_Unify)
+inline static void
+nucomp_real_check(VALUE num)
+{
+ switch (TYPE(num)) {
+ case T_FIXNUM:
+ case T_BIGNUM:
+ case T_FLOAT:
+ case T_RATIONAL:
+ break;
+ default:
+ rb_raise(rb_eArgError, "not a real");
+ }
+}
+
inline static VALUE
nucomp_s_canonicalize_internal(VALUE klass, VALUE real, VALUE image)
{
@@ -417,26 +430,9 @@
break;
}
- switch (TYPE(real)) {
- case T_FIXNUM:
- case T_BIGNUM:
- case T_FLOAT:
- break;
- default:
- if (!k_rational_p(real))
- rb_raise(rb_eArgError, "not a real");
- }
+ nucomp_real_check(real);
+ nucomp_real_check(image);
- switch (TYPE(image)) {
- case T_FIXNUM:
- case T_BIGNUM:
- case T_FLOAT:
- break;
- default:
- if (!k_rational_p(image))
- rb_raise(rb_eArgError, "not a real");
- }
-
return nucomp_s_canonicalize_internal(klass, real, image);
}
#endif
@@ -452,26 +448,9 @@
break;
}
- switch (TYPE(real)) {
- case T_FIXNUM:
- case T_BIGNUM:
- case T_FLOAT:
- break;
- default:
- if (!k_rational_p(real))
- rb_raise(rb_eArgError, "not a real");
- }
+ nucomp_real_check(real);
+ nucomp_real_check(image);
- switch (TYPE(image)) {
- case T_FIXNUM:
- case T_BIGNUM:
- case T_FLOAT:
- break;
- default:
- if (!k_rational_p(image))
- rb_raise(rb_eArgError, "not a real");
- }
-
return nucomp_s_canonicalize_internal(klass, real, image);
}
@@ -722,10 +701,7 @@
return f_complex_new2(CLASS_OF(self), real, image);
}
default:
- {
- VALUE a = f_coerce(other, self);
- return f_add(RARRAY_PTR(a)[0], RARRAY_PTR(a)[1]);
- }
+ return rb_num_coerce_bin(self, other, '+');
}
}
@@ -755,10 +731,7 @@
return f_complex_new2(CLASS_OF(self), real, image);
}
default:
- {
- VALUE a = f_coerce(other, self);
- return f_sub(RARRAY_PTR(a)[0], RARRAY_PTR(a)[1]);
- }
+ return rb_num_coerce_bin(self, other, '-');
}
}
@@ -791,10 +764,7 @@
return f_complex_new2(CLASS_OF(self), real, image);
}
default:
- {
- VALUE a = f_coerce(other, self);
- return f_mul(RARRAY_PTR(a)[0], RARRAY_PTR(a)[1]);
- }
+ return rb_num_coerce_bin(self, other, '*');
}
}
@@ -816,10 +786,7 @@
case T_COMPLEX:
return f_div(f_mul(self, f_conjugate(other)), f_abs2(other));
default:
- {
- VALUE a = f_coerce(other, self);
- return f_div(RARRAY_PTR(a)[0], RARRAY_PTR(a)[1]);
- }
+ return rb_num_coerce_bin(self, other, '/');
}
}
@@ -913,10 +880,7 @@
return nucomp_s_polar(CLASS_OF(self), nr, ntheta);
}
default:
- {
- VALUE a = f_coerce(other, self);
- return f_expt(RARRAY_PTR(a)[0], RARRAY_PTR(a)[1]);
- }
+ return rb_num_coerce_bin(self, other, id_expt);
}
}
@@ -1506,7 +1470,6 @@
id_arg = rb_intern("arg");
id_atan2_bang = rb_intern("atan2!");
id_cmp = rb_intern("<=>");
- id_coerce = rb_intern("coerce");
id_conjugate = rb_intern("conjugate");
id_convert = rb_intern("convert");
id_cos = rb_intern("cos");
Index: ChangeLog
===================================================================
--- ChangeLog (revision 15895)
+++ ChangeLog (revision 15896)
@@ -1,3 +1,9 @@
+Thu Apr 3 21:51:45 2008 Tadayoshi Funaba <tadf@d...>
+
+ * complex.c (nucomp_int_check): function for DRY real check.
+
+ * complex.c (nucomp_{add,sub,mul,div,expt}): use rb_num_coerce_bin().
+
Thu Apr 3 19:59:42 2008 Nobuyoshi Nakada <nobu@r...>
* insns.def (defineclass): check if cbase is a class or a module.
Index: rational.c
===================================================================
--- rational.c (revision 15895)
+++ rational.c (revision 15896)
@@ -425,7 +425,7 @@
#define f_unify_p(klass) rb_const_defined(klass, id_Unify)
-static inline void
+inline static void
nurat_int_check(VALUE num)
{
switch (TYPE(num)) {
@@ -880,7 +880,7 @@
case T_RATIONAL:
return f_expt(f_to_f(self), other);
default:
- return rb_num_coerce_bin(self, other, rb_intern("**"));
+ return rb_num_coerce_bin(self, other, id_expt);
}
}
@@ -917,7 +917,7 @@
return f_cmp(f_sub(num1, num2), ZERO);
}
default:
- return rb_num_coerce_bin(self, other, rb_intern("<=>"));
+ return rb_num_coerce_bin(self, other, id_cmp);
}
}
--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/