Method: BigDecimal#-
- Defined in:
- bigdecimal.c
#-(value) ⇒ Object
Returns the BigDecimal difference of self
and value
:
b = BigDecimal('333333.333') # => 0.333333333e6
b - 2 # => 0.333331333e6
b - 2.0 # => 0.333331333e6
b - Rational(2, 1) # => 0.333331333e6
b - Complex(2, 0) # => (0.333331333e6+0i)
See the Note About Precision.
1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 |
# File 'bigdecimal.c', line 1502
static VALUE
BigDecimal_sub(VALUE self, VALUE r)
{
ENTER(5);
Real *c, *a, *b;
size_t mx;
GUARD_OBJ(a, GetVpValue(self,1));
if (RB_TYPE_P(r, T_FLOAT)) {
b = GetVpValueWithPrec(r, 0, 1);
}
else if (RB_TYPE_P(r, T_RATIONAL)) {
b = GetVpValueWithPrec(r, a->Prec*VpBaseFig(), 1);
}
else {
b = GetVpValue(r,0);
}
if (!b) return DoSomeOne(self,r,'-');
SAVE(b);
if (VpIsNaN(b)) return b->obj;
if (VpIsNaN(a)) return a->obj;
mx = GetAddSubPrec(a,b);
if (mx == (size_t)-1L) {
GUARD_OBJ(c, NewZeroWrapLimited(1, VpBaseFig() + 1));
VpAddSub(c, a, b, -1);
}
else {
GUARD_OBJ(c, NewZeroWrapLimited(1, mx *(VpBaseFig() + 1)));
if (!mx) {
VpSetInf(c,VpGetSign(a));
}
else {
VpAddSub(c, a, b, -1);
}
}
return VpCheckGetValue(c);
}
|