~()
public
Inverts the bits in big. As Bignums are conceptually infinite length, the
result acts as if it had an infinite number of one bits to the left. In hex
representations, this is displayed as two periods to the left of the
digits.
sprintf("%X", ~0x1122334455)
Show source
static VALUE
rb_big_neg(VALUE x)
{
VALUE z = rb_big_clone(x);
BDIGIT *ds = BDIGITS(z);
long n = BIGNUM_LEN(z);
if (!n) return INT2FIX(-1);
if (BIGNUM_POSITIVE_P(z)) {
if (bary_add_one(ds, n)) {
big_extend_carry(z);
}
BIGNUM_SET_NEGATIVE_SIGN(z);
}
else {
bary_neg(ds, n);
if (bary_add_one(ds, n))
return INT2FIX(-1);
bary_neg(ds, n);
BIGNUM_SET_POSITIVE_SIGN(z);
}
return bignorm(z);
}