Module: BigMathR::Const::EulerGamma

Defined in:
lib/bigdecimal/math_r/const/EulerGamma_engel.rb,
ext/bigdecimal/math_r/math_r.c

Class Method Summary collapse

Class Method Details

.borwein_bailey(prec) ⇒ BigDecimal

Implement by Borwein-Bailey’s formula (Brent-McMillan type formula)

Examples:

BigMathR::Const::EulerGamma.borwein_bailey(20)
#=>

Parameters:

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Natural logarithm of 2

Raises:

  • (TypeError)

    not an Integer

  • (RangeError)

    Zero or negative precision



177
178
179
180
181
# File 'ext/bigdecimal/math_r/const.c', line 177

static VALUE
__impl_const_euler_gamma_borwein_bailey(VALUE unused_obj, VALUE prec)
{
	return EulerGamma_borwein_bailey(prec);
}

.brent_mcmillan(prec) ⇒ BigDecimal

Implement by Borwein-Bailey’s formula (Brent-McMillan type formula)

Examples:

BigMathR::Const::EulerGamma.borwein_bailey(20)
#=>

Parameters:

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Natural logarithm of 2

Raises:

  • (TypeError)

    not an Integer

  • (RangeError)

    Zero or negative precision



177
178
179
180
181
# File 'ext/bigdecimal/math_r/const.c', line 177

static VALUE
__impl_const_euler_gamma_borwein_bailey(VALUE unused_obj, VALUE prec)
{
	return EulerGamma_borwein_bailey(prec);
}

.engel(prec) ⇒ BigDecimal

Implement by Engel expansion.

Examples:

BigMathR::Const::EulerGamma.engel(20)
#=> 0.57721566490153286061e0

Parameters:

  • prec (Integer)

    Arbitrary precision

Returns:

  • (BigDecimal)

    Euler-Mascheroni constant gamma

Raises:

  • (TypeError)

    not an Integer

  • (RangeError)

    Zero or negative precision

See Also:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/bigdecimal/math_r/const/EulerGamma_engel.rb', line 19

def engel(prec)
  raise TypeError, "precision must be an Integer" unless prec.class == Integer
  raise RangeError, "Zero or negative precision" if prec <= 0
  n = BigDecimal.double_fig + prec

  f = File.open(__dir__ + '/b053977/b053977.txt', 'r')
  g = 1
  fread = -> do
    raise "there is no more list" if f.eof?
    _, coef = f.readline.chomp.split(' ');
    raise "expansion maximum reached" if coef.nil?
    g *= coef.to_i
  end

  d = BigDecimal(1)
  y = BigDecimal(0)

  while d.nonzero? && ((m = n - (y.exponent - d.exponent).abs) > 0)
    m = BigDecimal.double_fig if m < BigDecimal.double_fig
    d = BigDecimal(Rational(1, fread.call), m)
    y += d
  end
  y.round(prec)
end