Class: Numeric

Inherits:
Object show all
Defined in:
(unknown)

Instance Method Summary collapse

Instance Method Details

#nan?false

The #nan? method for primitive. Always return false.

Examples:

1.nan? #=> false

Returns:

  • (false)

    Whether self is Not a Number(NaN).



19
20
21
22
23
# File 'ext/bigdecimal/math_r/overrides.c', line 19

static VALUE
numeric_nan_p(VALUE self)
{
	return Qfalse;
}

#reciprocal(prec) ⇒ BigDecimal, Complex

Returns the reciprocal of itself with prec as decimal precision.
If it is a complex number, computes (x / ||w||) - (y / ||w||) * i).
Where ||w|| = x^2 + y^2.

Examples:

3.reciprocal(20) #=> 0.33333333333333333333e0
-0.0.reciprocal(20) #=> -Infinity
1/3r.reciprocal(20) #=> 0.300000000000000000003e1
(3.5r+1.5ri).reciprocal(20) #=> (0.24137931034482758621e0-0.10344827586206896552e0i)

Parameters:

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Real solution

  • (Complex)

    Complex solution



75
76
77
78
79
80
81
82
# File 'ext/bigdecimal/math_r/overrides.c', line 75

static VALUE
__impl_numeric_reciprocal(VALUE self, VALUE prec)
{
	if (rb_num_real_p(self))
		return rb_num_canonicalize(self, prec, ARG_REAL, ARG_RECIPROCAL);
	else
		return rb_num_canonicalize(self, prec, ARG_COMPLEX, ARG_RECIPROCAL);
}