diff options
author | shigek <shigek@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-08-06 15:16:37 +0000 |
---|---|---|
committer | shigek <shigek@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-08-06 15:16:37 +0000 |
commit | 3d9f4a7c771e9d388e1096c4aa19c031cbfb548e (patch) | |
tree | 0f454317b224b2441ed2cd8aecffc5b9e3c442fe /ext | |
parent | 7ba3a706f2d3ea3f99b60c34ec5f7b45c5957644 (diff) | |
download | ruby-3d9f4a7c771e9d388e1096c4aa19c031cbfb548e.tar.gz |
Comparison results adjusted to Float's.
Use rb_num_coerce_xxxxx(x,y) instead of own.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4343 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r-- | ext/bigdecimal/bigdecimal.c | 50 |
1 files changed, 6 insertions, 44 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index 166e01e2d2..3af7ec9c8d 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -58,7 +58,7 @@ VALUE rb_cBigDecimal; /* * ================== Ruby Interface part ========================== */ -static ID coerce; +# define DoSomeOne(x,y) rb_num_coerce_bin(x,y) /* * **** BigDecimal version **** @@ -79,44 +79,6 @@ static int VpInternalRound(Real *c,int ixDigit,U_LONG vPrev,U_LONG v); /* * **** BigDecimal part **** */ -/* Following functions borrowed from numeric.c */ -static VALUE -coerce_body(VALUE *x) -{ - return rb_funcall(x[1], coerce, 1, x[0]); -} - -static VALUE -coerce_rescue(VALUE *x) -{ - rb_raise(rb_eTypeError, "%s can't be coerced into %s", - rb_special_const_p(x[1])? - rb_str2cstr(rb_inspect(x[1]),0): - rb_class2name(CLASS_OF(x[1])), - rb_class2name(CLASS_OF(x[0]))); - return (VALUE)0; -} - -static void -do_coerce(VALUE *x, VALUE *y) -{ - VALUE ary; - VALUE a[2]; - a[0] = *x; a[1] = *y; - ary = rb_rescue(coerce_body, (VALUE)a, coerce_rescue, (VALUE)a); - if (TYPE(ary) != T_ARRAY || RARRAY(ary)->len != 2) { - rb_raise(rb_eTypeError, "coerce must return [x, y]"); - } - *x = RARRAY(ary)->ptr[0]; - *y = RARRAY(ary)->ptr[1]; -} - -static VALUE -DoSomeOne(VALUE x, VALUE y) -{ - do_coerce(&x, &y); - return rb_funcall(x, rb_frame_last_func(), 1, y); -} static void BigDecimal_delete(Real *pv) @@ -177,8 +139,8 @@ SomeOneMayDoIt: if(must) { rb_raise(rb_eTypeError, "%s can't be coerced into BigDecimal", rb_special_const_p(v)? - rb_str2cstr(rb_inspect(v),0): - rb_class2name(CLASS_OF(v)) + RSTRING(rb_inspect(v))->ptr: + rb_obj_classname(v) ); } return NULL; /* NULL means to coerce */ @@ -548,10 +510,10 @@ BigDecimalCmp(VALUE self, VALUE r,char op) Real *a, *b; GUARD_OBJ(a,GetVpValue(self,1)); b = GetVpValue(r,0); - if(!b) return DoSomeOne(self,r); + if(!b) return rb_num_coerce_cmp(self,r); SAVE(b); e = VpComp(a, b); - if(e==999) return rb_float_new(VpGetDoubleNaN()); + if(e==999) return Qnil; switch(op) { case '*': return INT2FIX(e); /* any op */ @@ -1289,7 +1251,7 @@ Init_bigdecimal(void) { /* Initialize VP routines */ VpInit((U_LONG)0); - coerce = rb_intern("coerce"); + /* Class and method registration */ rb_cBigDecimal = rb_define_class("BigDecimal",rb_cNumeric); |