Skip to content

Commit

Permalink
* numeric.c (rb_num_coerce_bin): add ID argument to specify
Browse files Browse the repository at this point in the history
  caller's method name.  [ruby-dev:33663]

* numeric.c (rb_num_coerce_cmp): ditto.

* numeric.c (rb_num_coerce_relop): ditto.

* ext/bigdecimal/bigdecimal.c (DoSomeOne): add function name argument.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15437 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
matz committed Feb 12, 2008
1 parent 030a513 commit f3ac3dc
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 52 deletions.
11 changes: 11 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
Tue Feb 12 11:38:57 2008 Yukihiro Matsumoto <matz@ruby-lang.org>

* numeric.c (rb_num_coerce_bin): add ID argument to specify
caller's method name. [ruby-dev:33663]

* numeric.c (rb_num_coerce_cmp): ditto.

* numeric.c (rb_num_coerce_relop): ditto.

* ext/bigdecimal/bigdecimal.c (DoSomeOne): add function name argument.

Tue Feb 12 10:25:02 2008

* lib/rdoc/rdoc.rb: Wrap parse_files' read in version check for
Expand Down
20 changes: 10 additions & 10 deletions bignum.c
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,7 @@ rb_big_cmp(VALUE x, VALUE y)
return rb_dbl_cmp(rb_big2dbl(x), RFLOAT_VALUE(y));

default:
return rb_num_coerce_cmp(x, y);
return rb_num_coerce_cmp(x, y, rb_intern("<=>"));
}

if (RBIGNUM_SIGN(x) > RBIGNUM_SIGN(y)) return INT2FIX(1);
Expand Down Expand Up @@ -1419,7 +1419,7 @@ rb_big_plus(VALUE x, VALUE y)
return DOUBLE2NUM(rb_big2dbl(x) + RFLOAT_VALUE(y));

default:
return rb_num_coerce_bin(x, y);
return rb_num_coerce_bin(x, y, '+');
}
}

Expand All @@ -1444,7 +1444,7 @@ rb_big_minus(VALUE x, VALUE y)
return DOUBLE2NUM(rb_big2dbl(x) - RFLOAT_VALUE(y));

default:
return rb_num_coerce_bin(x, y);
return rb_num_coerce_bin(x, y, '-');
}
}

Expand Down Expand Up @@ -1508,7 +1508,7 @@ rb_big_mul0(VALUE x, VALUE y)
return DOUBLE2NUM(rb_big2dbl(x) * RFLOAT_VALUE(y));

default:
return rb_num_coerce_bin(x, y);
return rb_num_coerce_bin(x, y, '*');
}

bms.x = x;
Expand Down Expand Up @@ -1742,7 +1742,7 @@ rb_big_div(VALUE x, VALUE y)
return DOUBLE2NUM(rb_big2dbl(x) / RFLOAT_VALUE(y));

default:
return rb_num_coerce_bin(x, y);
return rb_num_coerce_bin(x, y, '/');
}
bigdivmod(x, y, &z, 0);

Expand Down Expand Up @@ -1772,7 +1772,7 @@ rb_big_modulo(VALUE x, VALUE y)
break;

default:
return rb_num_coerce_bin(x, y);
return rb_num_coerce_bin(x, y, '%');
}
bigdivmod(x, y, 0, &z);

Expand Down Expand Up @@ -1802,7 +1802,7 @@ rb_big_remainder(VALUE x, VALUE y)
break;

default:
return rb_num_coerce_bin(x, y);
return rb_num_coerce_bin(x, y, rb_intern("remainder"));
}
bigdivrem(x, y, 0, &z);

Expand Down Expand Up @@ -1830,7 +1830,7 @@ rb_big_divmod(VALUE x, VALUE y)
break;

default:
return rb_num_coerce_bin(x, y);
return rb_num_coerce_bin(x, y, rb_intern("divmod"));
}
bigdivmod(x, y, &div, &mod);

Expand Down Expand Up @@ -1931,7 +1931,7 @@ rb_big_quo(VALUE x, VALUE y)
break;

default:
return rb_num_coerce_bin(x, y);
return rb_num_coerce_bin(x, y, rb_intern("quo"));
}
return DOUBLE2NUM(dx / dy);
}
Expand Down Expand Up @@ -2038,7 +2038,7 @@ rb_big_pow(VALUE x, VALUE y)
break;

default:
return rb_num_coerce_bin(x, y);
return rb_num_coerce_bin(x, y, rb_intern("**"));
}
return DOUBLE2NUM(pow(rb_big2dbl(x), d));
}
Expand Down
29 changes: 21 additions & 8 deletions ext/bigdecimal/bigdecimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ VALUE rb_cBigDecimal;
/*
* ================== Ruby Interface part ==========================
*/
#define DoSomeOne(x,y) rb_num_coerce_bin(x,y)
#define DoSomeOne(x,y,f) rb_num_coerce_bin(x,y,f)

#if 0
/* BigDecimal provides arbitrary-precision floating point decimal arithmetic.
Expand Down Expand Up @@ -657,7 +657,7 @@ BigDecimal_add(VALUE self, VALUE r)
U_LONG mx;
GUARD_OBJ(a,GetVpValue(self,1));
b = GetVpValue(r,0);
if(!b) return DoSomeOne(self,r);
if(!b) return DoSomeOne(self,r,'+');
SAVE(b);
if(VpIsNaN(b)) return b->obj;
if(VpIsNaN(a)) return a->obj;
Expand Down Expand Up @@ -696,7 +696,7 @@ BigDecimal_sub(VALUE self, VALUE r)

GUARD_OBJ(a,GetVpValue(self,1));
b = GetVpValue(r,0);
if(!b) return DoSomeOne(self,r);
if(!b) return DoSomeOne(self,r,'-');
SAVE(b);

if(VpIsNaN(b)) return b->obj;
Expand Down Expand Up @@ -725,7 +725,20 @@ BigDecimalCmp(VALUE self, VALUE r,char op)
Real *a, *b;
GUARD_OBJ(a,GetVpValue(self,1));
b = GetVpValue(r,0);
if(!b) return rb_num_coerce_cmp(self,r);
if(!b) {
ID f;

switch(op)
{
case '*': return INT2FIX(e); /* any op */
case '=': f = rb_intern("=="); break;
case '!': f = rb_intern("!="); break;
case 'G': f = rb_intern(">="); break;
case 'L': f = rb_intern("<="); break;
case '>': case '<': f = (ID)op; break;
}
return rb_num_coerce_cmp(self,r,f);
}
SAVE(b);
e = VpComp(a, b);
if(e==999) return Qnil;
Expand Down Expand Up @@ -862,7 +875,7 @@ BigDecimal_mult(VALUE self, VALUE r)

GUARD_OBJ(a,GetVpValue(self,1));
b = GetVpValue(r,0);
if(!b) return DoSomeOne(self,r);
if(!b) return DoSomeOne(self,r,'*');
SAVE(b);

mx = a->Prec + b->Prec;
Expand All @@ -881,7 +894,7 @@ BigDecimal_divide(Real **c, Real **res, Real **div, VALUE self, VALUE r)

GUARD_OBJ(a,GetVpValue(self,1));
b = GetVpValue(r,0);
if(!b) return DoSomeOne(self,r);
if(!b) return DoSomeOne(self,r,'/');
SAVE(b);
*div = b;
mx =(a->MaxPrec + b->MaxPrec + 1) * VpBaseFig();
Expand Down Expand Up @@ -942,7 +955,7 @@ BigDecimal_DoDivmod(VALUE self, VALUE r, Real **div, Real **mod)

GUARD_OBJ(a,GetVpValue(self,1));
b = GetVpValue(r,0);
if(!b) return DoSomeOne(self,r);
if(!b) return DoSomeOne(self,r,rb_intern("divmod"));
SAVE(b);

if(VpIsNaN(a) || VpIsNaN(b)) goto NaN;
Expand Down Expand Up @@ -1015,7 +1028,7 @@ BigDecimal_divremain(VALUE self, VALUE r, Real **dv, Real **rv)

GUARD_OBJ(a,GetVpValue(self,1));
b = GetVpValue(r,0);
if(!b) return DoSomeOne(self,r);
if(!b) return DoSomeOne(self,r,rb_intern("remainder"));
SAVE(b);

mx =(a->MaxPrec + b->MaxPrec) *VpBaseFig();
Expand Down
6 changes: 3 additions & 3 deletions include/ruby/intern.h
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,9 @@ VALUE rb_marshal_load(VALUE);
void rb_marshal_define_compat(VALUE newclass, VALUE oldclass, VALUE (*dumper)(VALUE), VALUE (*loader)(VALUE, VALUE));
/* numeric.c */
void rb_num_zerodiv(void);
VALUE rb_num_coerce_bin(VALUE, VALUE);
VALUE rb_num_coerce_cmp(VALUE, VALUE);
VALUE rb_num_coerce_relop(VALUE, VALUE);
VALUE rb_num_coerce_bin(VALUE, VALUE, ID);
VALUE rb_num_coerce_cmp(VALUE, VALUE, ID);
VALUE rb_num_coerce_relop(VALUE, VALUE, ID);
VALUE rb_float_new(double);
VALUE rb_num2fix(VALUE);
VALUE rb_fix2str(VALUE, int);
Expand Down
Loading

0 comments on commit f3ac3dc

Please sign in to comment.