ruby-changes:7713
From: tadf <ko1@a...>
Date: Mon, 8 Sep 2008 07:10:55 +0900 (JST)
Subject: [ruby-changes:7713] Ruby:r19234 (trunk): * complex.c: some adjustments.
tadf 2008-09-08 07:10:38 +0900 (Mon, 08 Sep 2008) New Revision: 19234 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19234 Log: * complex.c: some adjustments. * rational.c: ditto. Modified files: trunk/ChangeLog trunk/complex.c trunk/rational.c Index: complex.c =================================================================== --- complex.c (revision 19233) +++ complex.c (revision 19234) @@ -21,12 +21,11 @@ VALUE rb_cComplex; -static ID id_Unify, id_abs, id_abs2, id_arg, id_atan2_bang, id_cmp, - 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, - id_to_i, id_to_r, id_to_s, id_truncate; +static ID id_Unify, id_abs, id_abs2, id_arg, id_cmp, id_conjugate, + id_convert, id_denominator, id_divmod, id_equal_p, id_exact_p, id_expt, + id_floor, id_format, id_idiv, id_inspect, id_negate, id_new, id_new_bang, + id_numerator, id_polar, id_quo, id_scalar_p, id_to_f, id_to_i, id_to_r, + id_to_s, id_truncate; #define f_boolcast(x) ((x) ? Qtrue : Qfalse) @@ -1334,23 +1333,18 @@ id_abs = rb_intern("abs"); id_abs2 = rb_intern("abs2"); id_arg = rb_intern("arg"); - id_atan2_bang = rb_intern("atan2!"); id_cmp = rb_intern("<=>"); id_conjugate = rb_intern("conjugate"); id_convert = rb_intern("convert"); - id_cos = rb_intern("cos"); id_denominator = rb_intern("denominator"); id_divmod = rb_intern("divmod"); id_equal_p = rb_intern("=="); id_exact_p = rb_intern("exact?"); - id_exp_bang = rb_intern("exp!"); id_expt = rb_intern("**"); id_floor = rb_intern("floor"); id_format = rb_intern("format"); - id_hypot = rb_intern("hypot"); id_idiv = rb_intern("div"); id_inspect = rb_intern("inspect"); - id_log_bang = rb_intern("log!"); id_negate = rb_intern("-@"); id_new = rb_intern("new"); id_new_bang = rb_intern("new!"); @@ -1358,8 +1352,6 @@ id_polar = rb_intern("polar"); id_quo = rb_intern("quo"); id_scalar_p = rb_intern("scalar?"); - id_sin = rb_intern("sin"); - id_sqrt = rb_intern("sqrt"); id_to_f = rb_intern("to_f"); id_to_i = rb_intern("to_i"); id_to_r = rb_intern("to_r"); Index: ChangeLog =================================================================== --- ChangeLog (revision 19233) +++ ChangeLog (revision 19234) @@ -1,3 +1,9 @@ +Mon Sep 8 07:09:42 2008 Tadayoshi Funaba <tadf@d...> + + * complex.c: some adjustments. + + * rational.c: ditto. + Mon Sep 8 06:50:29 2008 Nobuyoshi Nakada <nobu@r...> * configure.in (XLDFLAGS): added --enable-auto-import for cygwin and Index: rational.c =================================================================== --- rational.c (revision 19233) +++ rational.c (revision 19234) @@ -26,9 +26,9 @@ VALUE rb_cRational; -static ID id_Unify, id_abs, id_cmp, id_convert, id_equal_p, - id_expt, id_floor, id_format, id_idiv, id_inspect, id_negate, id_new, - id_new_bang, id_to_f, id_to_i, id_to_s, id_truncate; +static ID id_Unify, id_abs, id_cmp, id_convert, id_equal_p, id_expt, + id_floor, id_format, id_idiv, id_inspect, id_negate, id_new, id_new_bang, + id_to_f, id_to_i, id_to_s, id_truncate; #define f_boolcast(x) ((x) ? Qtrue : Qfalse) @@ -327,6 +327,8 @@ return nurat_s_new_internal(klass, ZERO, ONE); } +#define rb_raise_zerodiv() rb_raise(rb_eZeroDivError, "divided by zero") + static VALUE nurat_s_new_bang(int argc, VALUE *argv, VALUE klass) { @@ -350,7 +352,7 @@ den = f_negate(den); break; case 0: - rb_raise(rb_eZeroDivError, "devided by zero"); + rb_raise_zerodiv(); break; } break; @@ -398,7 +400,7 @@ den = f_negate(den); break; case 0: - rb_raise(rb_eZeroDivError, "devided by zero"); + rb_raise_zerodiv(); break; } @@ -420,7 +422,7 @@ den = f_negate(den); break; case 0: - rb_raise(rb_eZeroDivError, "devided by zero"); + rb_raise_zerodiv(); break; } @@ -725,7 +727,7 @@ case T_FIXNUM: case T_BIGNUM: if (f_zero_p(other)) - rb_raise(rb_eZeroDivError, "devided by zero"); + rb_raise_zerodiv(); { get_dat1(self); @@ -737,7 +739,7 @@ return rb_funcall(f_to_f(self), '/', 1, other); case T_RATIONAL: if (f_zero_p(other)) - rb_raise(rb_eZeroDivError, "devided by zero"); + rb_raise_zerodiv(); { get_dat2(self, other); @@ -1123,7 +1125,7 @@ dat->den = RARRAY_PTR(a)[1]; if (f_zero_p(dat->den)) - rb_raise(rb_eZeroDivError, "devided by zero"); + rb_raise_zerodiv(); return self; } @@ -1186,8 +1188,8 @@ return rb_rational_new1(self); } -static VALUE -float_decode(VALUE self) +static void +float_decode_internal(VALUE self, VALUE *rf, VALUE *rn) { double f; int n; @@ -1195,15 +1197,28 @@ f = frexp(RFLOAT_VALUE(self), &n); f = ldexp(f, DBL_MANT_DIG); n -= DBL_MANT_DIG; - return rb_assoc_new(f_to_i(rb_float_new(f)), INT2FIX(n)); + *rf = rb_dbl2big(f); + *rn = INT2FIX(n); } +#if 0 static VALUE +float_decode(VALUE self) +{ + VALUE f, n; + + float_decode_internal(self, &f, &n); + return rb_assoc_new(f, n); +} +#endif + +static VALUE float_to_r(VALUE self) { - VALUE a = float_decode(self); - return f_mul(RARRAY_PTR(a)[0], - f_expt(INT2FIX(FLT_RADIX), RARRAY_PTR(a)[1])); + VALUE f, n; + + float_decode_internal(self, &f, &n); + return f_mul(f, f_expt(INT2FIX(FLT_RADIX), n)); } static VALUE rat_pat, an_e_pat, a_dot_pat, underscores_pat, an_underscore; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/