log2(p1)
public
static VALUE
math_log2(VALUE obj, VALUE x)
{
double d0, d;
size_t numbits;
if (RB_BIGNUM_TYPE_P(x) && BIGNUM_POSITIVE_P(x) &&
DBL_MAX_EXP <= (numbits = rb_absint_numwords(x, 1, NULL))) {
numbits -= DBL_MANT_DIG;
x = rb_big_rshift(x, SIZET2NUM(numbits));
}
else {
numbits = 0;
}
Need_Float(x);
d0 = RFLOAT_VALUE(x);
/* check for domain error */
if (d0 < 0.0) domain_error("log2");
/* check for pole error */
if (d0 == 0.0) return DBL2NUM(-INFINITY);
d = log2(d0);
d += numbits;
return DBL2NUM(d);
}