diff --git a/ChangeLog b/ChangeLog index 10656e709f..5e06e8e2ef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Mon Sep 8 07:09:42 2008 Tadayoshi Funaba + + * complex.c: some adjustments. + + * rational.c: ditto. + Mon Sep 8 06:50:29 2008 Nobuyoshi Nakada * configure.in (XLDFLAGS): added --enable-auto-import for cygwin and diff --git a/complex.c b/complex.c index 925ad9abf0..98541ba607 100644 --- a/complex.c +++ b/complex.c @@ -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 @@ Init_Complex(void) 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 @@ Init_Complex(void) 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"); diff --git a/rational.c b/rational.c index e35b4792d9..f44e52c247 100644 --- a/rational.c +++ b/rational.c @@ -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 @@ nurat_s_alloc(VALUE klass) 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 @@ nurat_s_new_bang(int argc, VALUE *argv, VALUE klass) den = f_negate(den); break; case 0: - rb_raise(rb_eZeroDivError, "devided by zero"); + rb_raise_zerodiv(); break; } break; @@ -398,7 +400,7 @@ nurat_s_canonicalize_internal(VALUE klass, VALUE num, VALUE den) den = f_negate(den); break; case 0: - rb_raise(rb_eZeroDivError, "devided by zero"); + rb_raise_zerodiv(); break; } @@ -420,7 +422,7 @@ nurat_s_canonicalize_internal_no_reduce(VALUE klass, VALUE num, VALUE den) den = f_negate(den); break; case 0: - rb_raise(rb_eZeroDivError, "devided by zero"); + rb_raise_zerodiv(); break; } @@ -725,7 +727,7 @@ nurat_div(VALUE self, VALUE other) 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 @@ nurat_div(VALUE self, VALUE other) 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 @@ nurat_marshal_load(VALUE self, VALUE a) 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 @@ integer_to_r(VALUE self) 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 @@ float_decode(VALUE self) 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;