summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-19 13:55:52 +0000
committertadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-19 13:55:52 +0000
commitf2cb79ffee99c3561503ed7a1c107ca3ec6a48a7 (patch)
tree58ea38242497b45ea49f497d8693123fe508e944
parent396650e0bd353e30b873683f008f92e2aa498971 (diff)
* complex.c: uses f_(in)?exact_p macro.
* rational.c: ditto. * bignum.c (rb_big_pow): bignum**bignum - should calculate without rational. * lib/complex.rb: should override Math module at most once. * lib/mathn.rb: requires 'cmath' directly. -この行以下は無視されます -- M complex.c M ChangeLog M lib/mathn.rb M lib/complex.rb M bignum.c M rational.c git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog13
-rw-r--r--bignum.c5
-rw-r--r--complex.c18
-rw-r--r--lib/complex.rb6
-rw-r--r--lib/mathn.rb8
-rw-r--r--rational.c9
6 files changed, 40 insertions, 19 deletions
diff --git a/ChangeLog b/ChangeLog
index 510322ce77..17d3ce694c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+Fri Sep 19 22:37:25 2008 Tadayoshi Funaba <tadf@dotrb.org>
+
+ * complex.c: uses f_(in)?exact_p macro.
+
+ * rational.c: ditto.
+
+ * bignum.c (rb_big_pow): bignum**bignum - should calculate without
+ rational.
+
+ * lib/complex.rb: should override Math module at most once.
+
+ * lib/mathn.rb: requires 'cmath' directly.
+
Fri Sep 19 20:48:06 2008 Yuki Sonoda <yugui@yugui.jp>
* prec.c: removed. Precision will be redesigned and be back again.
diff --git a/bignum.c b/bignum.c
index dc30519b89..35db091454 100644
--- a/bignum.c
+++ b/bignum.c
@@ -2102,9 +2102,6 @@ rb_big_pow(VALUE x, VALUE y)
break;
case T_BIGNUM:
- if (rb_funcall(y, '<', 1, INT2FIX(0)))
- return rb_funcall(rb_rational_raw1(x), rb_intern("**"), 1, y);
-
rb_warn("in a**b, b may be too big");
d = rb_big2dbl(y);
break;
@@ -2113,7 +2110,7 @@ rb_big_pow(VALUE x, VALUE y)
yy = FIX2LONG(y);
if (yy < 0)
- return rb_funcall(rb_rational_raw1(x), rb_intern("**"), 1, y);
+ return rb_funcall(rb_rational_raw1(x), rb_intern("**"), 1, y);
else {
VALUE z = 0;
SIGNED_VALUE mask;
diff --git a/complex.c b/complex.c
index b7a5c3c436..5bd9f03556 100644
--- a/complex.c
+++ b/complex.c
@@ -247,6 +247,9 @@ k_complex_p(VALUE x)
return f_kind_of_p(x, rb_cComplex);
}
+#define k_exact_p(x) (!k_float_p(x))
+#define k_inexact_p(x) k_float_p(x)
+
#define get_dat1(x) \
struct RComplex *dat;\
dat = ((struct RComplex *)(x))
@@ -334,7 +337,7 @@ nucomp_s_canonicalize_internal(VALUE klass, VALUE real, VALUE image)
#define CL_CANON
#ifdef CL_CANON
if (f_zero_p(image) && f_unify_p(klass) &&
- !k_float_p(real) && !k_float_p(image))
+ k_exact_p(real) && k_exact_p(image))
return real;
#else
if (f_zero_p(image) && f_unify_p(klass))
@@ -986,7 +989,7 @@ nucomp_to_i(VALUE self)
{
get_dat1(self);
- if (k_float_p(dat->image) || !f_zero_p(dat->image)) {
+ if (k_inexact_p(dat->image) || !f_zero_p(dat->image)) {
VALUE s = f_to_s(self);
rb_raise(rb_eRangeError, "can't convert %s into Integer",
StringValuePtr(s));
@@ -999,7 +1002,7 @@ nucomp_to_f(VALUE self)
{
get_dat1(self);
- if (k_float_p(dat->image) || !f_zero_p(dat->image)) {
+ if (k_inexact_p(dat->image) || !f_zero_p(dat->image)) {
VALUE s = f_to_s(self);
rb_raise(rb_eRangeError, "can't convert %s into Float",
StringValuePtr(s));
@@ -1012,7 +1015,7 @@ nucomp_to_r(VALUE self)
{
get_dat1(self);
- if (k_float_p(dat->image) || !f_zero_p(dat->image)) {
+ if (k_inexact_p(dat->image) || !f_zero_p(dat->image)) {
VALUE s = f_to_s(self);
rb_raise(rb_eRangeError, "can't convert %s into Rational",
StringValuePtr(s));
@@ -1183,7 +1186,6 @@ string_to_c_internal(VALUE self)
return rb_assoc_new(rb_complex_polar(r, i), re);
else
return rb_assoc_new(rb_complex_new2(r, i), re);
-
}
}
@@ -1257,7 +1259,7 @@ nucomp_s_convert(int argc, VALUE *argv, VALUE klass)
{
get_dat1(a1);
- if (!k_float_p(dat->image) && f_zero_p(dat->image))
+ if (k_exact_p(dat->image) && f_zero_p(dat->image))
a1 = dat->real;
}
}
@@ -1267,7 +1269,7 @@ nucomp_s_convert(int argc, VALUE *argv, VALUE klass)
{
get_dat1(a2);
- if (!k_float_p(dat->image) && f_zero_p(dat->image))
+ if (k_exact_p(dat->image) && f_zero_p(dat->image))
a2 = dat->real;
}
}
@@ -1338,7 +1340,7 @@ numeric_arg(VALUE self)
static VALUE
numeric_rect(VALUE self)
{
- return rb_assoc_new(self, ZERO);
+ return rb_assoc_new(self, INT2FIX(0));
}
static VALUE
diff --git a/lib/complex.rb b/lib/complex.rb
index 1845f30b1f..70e168e912 100644
--- a/lib/complex.rb
+++ b/lib/complex.rb
@@ -1,7 +1,9 @@
require 'cmath'
-Object.instance_eval{remove_const :Math}
-Math = CMath
+unless defined?(Math.exp!)
+ Object.instance_eval{remove_const :Math}
+ Math = CMath
+end
def Complex.generic? (other)
other.kind_of?(Integer) ||
diff --git a/lib/mathn.rb b/lib/mathn.rb
index 2af2b83da3..b29f994ac9 100644
--- a/lib/mathn.rb
+++ b/lib/mathn.rb
@@ -9,11 +9,15 @@
#
#
-require "complex.rb"
-require "rational.rb"
+require "cmath.rb"
require "matrix.rb"
require "prime.rb"
+unless defined?(Math.exp!)
+ Object.instance_eval{remove_const :Math}
+ Math = CMath
+end
+
class Fixnum
remove_method :/
alias / quo
diff --git a/rational.c b/rational.c
index c6c9b91ead..d8af04c61b 100644
--- a/rational.c
+++ b/rational.c
@@ -213,6 +213,9 @@ k_rational_p(VALUE x)
return f_kind_of_p(x, rb_cRational);
}
+#define k_exact_p(x) (!k_float_p(x))
+#define k_inexact_p(x) k_float_p(x)
+
#ifndef NDEBUG
#define f_gcd f_gcd_orig
#endif
@@ -773,7 +776,7 @@ nurat_fdiv(VALUE self, VALUE other)
static VALUE
nurat_expt(VALUE self, VALUE other)
{
- if (f_zero_p(other))
+ if (k_exact_p(other) && f_zero_p(other))
return f_rational_new_bang1(CLASS_OF(self), ONE);
if (k_rational_p(other)) {
@@ -1403,7 +1406,7 @@ nurat_s_convert(int argc, VALUE *argv, VALUE klass)
switch (TYPE(a1)) {
case T_COMPLEX:
- if (k_float_p(RCOMPLEX(a1)->image) || !f_zero_p(RCOMPLEX(a1)->image)) {
+ if (k_inexact_p(RCOMPLEX(a1)->image) || !f_zero_p(RCOMPLEX(a1)->image)) {
VALUE s = f_to_s(a1);
rb_raise(rb_eRangeError, "can't accept %s",
StringValuePtr(s));
@@ -1413,7 +1416,7 @@ nurat_s_convert(int argc, VALUE *argv, VALUE klass)
switch (TYPE(a2)) {
case T_COMPLEX:
- if (k_float_p(RCOMPLEX(a2)->image) || !f_zero_p(RCOMPLEX(a2)->image)) {
+ if (k_inexact_p(RCOMPLEX(a2)->image) || !f_zero_p(RCOMPLEX(a2)->image)) {
VALUE s = f_to_s(a2);
rb_raise(rb_eRangeError, "can't accept %s",
StringValuePtr(s));