mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Fix: coerce in comparisons.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4323 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5f7be2983b
commit
73b86b2f8e
1 changed files with 27 additions and 38 deletions
|
@ -540,16 +540,32 @@ BigDecimal_sub(VALUE self, VALUE r)
|
||||||
return ToValue(c);
|
return ToValue(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
static S_INT
|
static VALUE
|
||||||
BigDecimalCmp(VALUE self, VALUE r)
|
BigDecimalCmp(VALUE self, VALUE r,char op)
|
||||||
|
/*
|
||||||
|
* op: '='
|
||||||
|
*/
|
||||||
{
|
{
|
||||||
ENTER(5);
|
ENTER(5);
|
||||||
|
S_INT e;
|
||||||
Real *a, *b;
|
Real *a, *b;
|
||||||
GUARD_OBJ(a,GetVpValue(self,1));
|
GUARD_OBJ(a,GetVpValue(self,1));
|
||||||
b = GetVpValue(r,0);
|
b = GetVpValue(r,0);
|
||||||
if(!b) return DoSomeOne(self,r);
|
if(!b) return DoSomeOne(self,r);
|
||||||
SAVE(b);
|
SAVE(b);
|
||||||
return VpComp(a, b);
|
e = VpComp(a, b);
|
||||||
|
if(e==999) return rb_float_new(VpGetDoubleNaN());
|
||||||
|
switch(op)
|
||||||
|
{
|
||||||
|
case '*': return INT2FIX(e); /* any op */
|
||||||
|
case '=': if(e==0) return Qtrue ; return Qfalse;
|
||||||
|
case '!': if(e!=0) return Qtrue ; return Qfalse;
|
||||||
|
case 'G': if(e>=0) return Qtrue ; return Qfalse;
|
||||||
|
case '>': if(e> 0) return Qtrue ; return Qfalse;
|
||||||
|
case 'L': if(e<=0) return Qtrue ; return Qfalse;
|
||||||
|
case '<': if(e< 0) return Qtrue ; return Qfalse;
|
||||||
|
}
|
||||||
|
rb_bug("Undefined operation in BigDecimalCmp()");
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
|
@ -569,70 +585,43 @@ BigDecimal_nonzero(VALUE self)
|
||||||
static VALUE
|
static VALUE
|
||||||
BigDecimal_comp(VALUE self, VALUE r)
|
BigDecimal_comp(VALUE self, VALUE r)
|
||||||
{
|
{
|
||||||
S_INT e;
|
return BigDecimalCmp(self, r, '*');
|
||||||
e = BigDecimalCmp(self, r);
|
|
||||||
if(e==999) return rb_float_new(VpGetDoubleNaN());
|
|
||||||
return INT2FIX(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
BigDecimal_eq(VALUE self, VALUE r)
|
BigDecimal_eq(VALUE self, VALUE r)
|
||||||
{
|
{
|
||||||
ENTER(5);
|
return BigDecimalCmp(self, r, '=');
|
||||||
Real *a, *b;
|
|
||||||
GUARD_OBJ(a,GetVpValue(self,1));
|
|
||||||
b = GetVpValue(r,0);
|
|
||||||
if(!b) return Qfalse; /* Not comparable */
|
|
||||||
SAVE(b);
|
|
||||||
return VpComp(a, b)? Qfalse:Qtrue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
BigDecimal_ne(VALUE self, VALUE r)
|
BigDecimal_ne(VALUE self, VALUE r)
|
||||||
{
|
{
|
||||||
ENTER(5);
|
return BigDecimalCmp(self, r, '!');
|
||||||
Real *a, *b;
|
|
||||||
GUARD_OBJ(a,GetVpValue(self,1));
|
|
||||||
b = GetVpValue(r,0);
|
|
||||||
if(!b) return Qtrue; /* Not comparable */
|
|
||||||
SAVE(b);
|
|
||||||
return VpComp(a, b) ? Qtrue : Qfalse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
BigDecimal_lt(VALUE self, VALUE r)
|
BigDecimal_lt(VALUE self, VALUE r)
|
||||||
{
|
{
|
||||||
S_INT e;
|
return BigDecimalCmp(self, r, '<');
|
||||||
e = BigDecimalCmp(self, r);
|
|
||||||
if(e==999) return Qfalse;
|
|
||||||
return(e < 0) ? Qtrue : Qfalse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
BigDecimal_le(VALUE self, VALUE r)
|
BigDecimal_le(VALUE self, VALUE r)
|
||||||
{
|
{
|
||||||
S_INT e;
|
return BigDecimalCmp(self, r, 'L');
|
||||||
e = BigDecimalCmp(self, r);
|
|
||||||
if(e==999) return Qfalse;
|
|
||||||
return(e <= 0) ? Qtrue : Qfalse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
BigDecimal_gt(VALUE self, VALUE r)
|
BigDecimal_gt(VALUE self, VALUE r)
|
||||||
{
|
{
|
||||||
S_INT e;
|
return BigDecimalCmp(self, r, '>');
|
||||||
e = BigDecimalCmp(self, r);
|
|
||||||
if(e==999) return Qfalse;
|
|
||||||
return(e > 0) ? Qtrue : Qfalse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
BigDecimal_ge(VALUE self, VALUE r)
|
BigDecimal_ge(VALUE self, VALUE r)
|
||||||
{
|
{
|
||||||
S_INT e;
|
return BigDecimalCmp(self, r, 'G');
|
||||||
e = BigDecimalCmp(self, r);
|
|
||||||
if(e==999) return Qfalse;
|
|
||||||
return(e >= 0) ? Qtrue : Qfalse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue