Sha256: e144886d20995c29dbe41b7825a9a740ba3848484a4d8ce7d56a2d5ba51498da

Contents?: true

Size: 314 Bytes

Versions: 2

Compression:

Stored size: 314 Bytes

Contents

# coding: utf-8
class Integer
  # TODO: Consider http://cims.nyu.edu/~harvey/bernmm/
  def bernoulli
    return -0.5.to_r if self == 1
    return 0.to_r if odd?
    a = []
    0.upto(self) do |m|
      a[m] = Rational(1, m + 1)
      m.downto(1){|j| a[j - 1] = j * (a[j - 1] - a[j])}
    end
    a.first
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
numb-0.152.0 lib/numb/bernoulli.rb
numb-0.138.0 lib/numb/bernoulli.rb