summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-12 12:09:21 +0000
committertadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-12 12:09:21 +0000
commit898bb1cbe3391dd69093edbbc00f2f164c8457b6 (patch)
tree44e4c746d7fb0198a4b93ae01fe04a55b9c7a545
parentfff1183ffefc1cc29860672eb39992a942c33dfb (diff)
* complex.c: use k_exact_{zero,one}_p macro.
* rational.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24036 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--complex.c21
-rw-r--r--rational.c13
3 files changed, 24 insertions, 16 deletions
diff --git a/ChangeLog b/ChangeLog
index 546fad954b..a9032efddc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Sun Jul 12 21:07:46 2009 Tadayoshi Funaba <tadf@dotrb.org>
+
+ * complex.c: use k_exact_{zero,one}_p macro.
+
+ * rational.c: ditto.
+
Sun Jul 12 20:42:58 2009 Tadayoshi Funaba <tadf@dotrb.org>
* numeric.c (fix_divide): added an entry to rational.
diff --git a/complex.c b/complex.c
index f8c0ecd1c2..691ffc6cff 100644
--- a/complex.c
+++ b/complex.c
@@ -261,6 +261,9 @@ k_complex_p(VALUE x)
#define k_exact_p(x) (!k_float_p(x))
#define k_inexact_p(x) k_float_p(x)
+#define k_exact_zero_p(x) (k_exact_p(x) && f_zero_p(x))
+#define k_exact_one_p(x) (k_exact_p(x) && f_one_p(x))
+
#define get_dat1(x) \
struct RComplex *dat;\
dat = ((struct RComplex *)(x))
@@ -362,7 +365,7 @@ nucomp_s_canonicalize_internal(VALUE klass, VALUE real, VALUE imag)
#ifdef CANON
#define CL_CANON
#ifdef CL_CANON
- if (f_zero_p(imag) && k_exact_p(imag) && canonicalization)
+ if (k_exact_zero_p(imag) && canonicalization)
return real;
#else
if (f_zero_p(imag) && canonicalization)
@@ -758,10 +761,6 @@ f_divide(VALUE self, VALUE other,
static VALUE
nucomp_div(VALUE self, VALUE other)
{
-#if 0 /* too much cost */
- if (f_zero_p(other) && k_exact_p(self) && k_exact_p(other))
- rb_raise_zerodiv();
-#endif
return f_divide(self, other, f_quo, id_quo);
}
@@ -832,7 +831,7 @@ f_reciprocal(VALUE x)
static VALUE
nucomp_expt(VALUE self, VALUE other)
{
- if (f_zero_p(other) && k_exact_p(other))
+ if (k_exact_zero_p(other))
return f_complex_new_bang1(CLASS_OF(self), ONE);
if (k_rational_p(other) && f_one_p(f_denominator(other)))
@@ -841,7 +840,7 @@ nucomp_expt(VALUE self, VALUE other)
if (k_complex_p(other)) {
get_dat1(other);
- if (k_exact_p(dat->imag) && f_zero_p(dat->imag))
+ if (k_exact_zero_p(dat->imag))
other = dat->real; /* c14n */
}
@@ -1062,7 +1061,7 @@ static VALUE
nucomp_exact_p(VALUE self)
{
get_dat1(self);
- return f_boolcast(f_exact_p(dat->real) && f_exact_p(dat->imag));
+ return f_boolcast(k_exact_p(dat->real) && k_exact_p(dat->imag));
}
/* :nodoc: */
@@ -1625,7 +1624,7 @@ nucomp_s_convert(int argc, VALUE *argv, VALUE klass)
{
get_dat1(a1);
- if (k_exact_p(dat->imag) && f_zero_p(dat->imag))
+ if (k_exact_zero_p(dat->imag))
a1 = dat->real;
}
}
@@ -1635,14 +1634,14 @@ nucomp_s_convert(int argc, VALUE *argv, VALUE klass)
{
get_dat1(a2);
- if (k_exact_p(dat->imag) && f_zero_p(dat->imag))
+ if (k_exact_zero_p(dat->imag))
a2 = dat->real;
}
}
switch (TYPE(a1)) {
case T_COMPLEX:
- if (argc == 1 || (k_exact_p(a2) && f_zero_p(a2)))
+ if (argc == 1 || (k_exact_zero_p(a2)))
return a1;
}
diff --git a/rational.c b/rational.c
index 632dc90117..d5a87f6b36 100644
--- a/rational.c
+++ b/rational.c
@@ -214,6 +214,9 @@ k_rational_p(VALUE x)
#define k_exact_p(x) (!k_float_p(x))
#define k_inexact_p(x) k_float_p(x)
+#define k_exact_zero_p(x) (k_exact_p(x) && f_zero_p(x))
+#define k_exact_one_p(x) (k_exact_p(x) && f_one_p(x))
+
#ifndef NDEBUG
#define f_gcd f_gcd_orig
#endif
@@ -892,7 +895,7 @@ extern VALUE rb_fexpt(VALUE x, VALUE y);
static VALUE
nurat_expt(VALUE self, VALUE other)
{
- if (k_exact_p(other) && f_zero_p(other))
+ if (k_exact_zero_p(other))
return f_rational_new_bang1(CLASS_OF(self), ONE);
if (k_rational_p(other)) {
@@ -1051,7 +1054,7 @@ nurat_coerce(VALUE self, VALUE other)
case T_RATIONAL:
return rb_assoc_new(other, self);
case T_COMPLEX:
- if (k_exact_p(RCOMPLEX(other)->imag) && f_zero_p(RCOMPLEX(other)->imag))
+ if (k_exact_zero_p(RCOMPLEX(other)->imag))
return rb_assoc_new(f_rational_new_bang1
(CLASS_OF(self), RCOMPLEX(other)->real), self);
}
@@ -1882,13 +1885,13 @@ nurat_s_convert(int argc, VALUE *argv, VALUE klass)
switch (TYPE(a1)) {
case T_COMPLEX:
- if (k_exact_p(RCOMPLEX(a1)->imag) && f_zero_p(RCOMPLEX(a1)->imag))
+ if (k_exact_zero_p(RCOMPLEX(a1)->imag))
a1 = RCOMPLEX(a1)->real;
}
switch (TYPE(a2)) {
case T_COMPLEX:
- if (k_exact_p(RCOMPLEX(a2)->imag) && f_zero_p(RCOMPLEX(a2)->imag))
+ if (k_exact_zero_p(RCOMPLEX(a2)->imag))
a2 = RCOMPLEX(a2)->real;
}
@@ -1923,7 +1926,7 @@ nurat_s_convert(int argc, VALUE *argv, VALUE klass)
switch (TYPE(a1)) {
case T_RATIONAL:
- if (argc == 1 || (k_exact_p(a2) && f_one_p(a2)))
+ if (argc == 1 || (k_exact_one_p(a2)))
return a1;
}