ruby-changes:7910
From: tadf <ko1@a...>
Date: Fri, 19 Sep 2008 22:56:09 +0900 (JST)
Subject: [ruby-changes:7910] Ruby:r19431 (trunk): * complex.c: uses f_(in)?exact_p macro.
tadf 2008-09-19 22:55:52 +0900 (Fri, 19 Sep 2008) New Revision: 19431 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19431 Log: * 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. -?\227?\129?\147?\227?\129?\174?\232?\161?\140?\228?\187?\165?\228?\184?\139?\227?\129?\175?\231?\132?\161?\232?\166?\150?\227?\129?\149?\227?\130?\140?\227?\129?\190?\227?\129?\153 -- M complex.c M ChangeLog M lib/mathn.rb M lib/complex.rb M bignum.c M rational.c Modified files: trunk/ChangeLog trunk/bignum.c trunk/complex.c trunk/lib/complex.rb trunk/lib/mathn.rb trunk/rational.c Index: complex.c =================================================================== --- complex.c (revision 19430) +++ complex.c (revision 19431) @@ -247,6 +247,9 @@ 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 @@ #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 @@ { 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 @@ { 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 @@ { 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 @@ 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 @@ { 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 @@ { 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 @@ static VALUE numeric_rect(VALUE self) { - return rb_assoc_new(self, ZERO); + return rb_assoc_new(self, INT2FIX(0)); } static VALUE Index: ChangeLog =================================================================== --- ChangeLog (revision 19430) +++ ChangeLog (revision 19431) @@ -1,3 +1,16 @@ +Fri Sep 19 22:37:25 2008 Tadayoshi Funaba <tadf@d...> + + * 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@y...> * prec.c: removed. Precision will be redesigned and be back again. Index: lib/mathn.rb =================================================================== --- lib/mathn.rb (revision 19430) +++ lib/mathn.rb (revision 19431) @@ -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 Index: lib/complex.rb =================================================================== --- lib/complex.rb (revision 19430) +++ lib/complex.rb (revision 19431) @@ -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) || Index: bignum.c =================================================================== --- bignum.c (revision 19430) +++ bignum.c (revision 19431) @@ -2102,9 +2102,6 @@ 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 @@ 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; Index: rational.c =================================================================== --- rational.c (revision 19430) +++ rational.c (revision 19431) @@ -213,6 +213,9 @@ 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 @@ 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 @@ 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 @@ 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)); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/