Skip to content

Commit

Permalink
fix: Coerce some denominators to rational when calculating inverse beta.
Browse files Browse the repository at this point in the history
This change fixes a segmentation error produced by BigDecimal gem on
ruby 3.1.2, where it fails to calculate a big float. It was "fixed"
in BigDecimal 3.1.2, but this version might not be compatible with older
ruby versions.

Reported here: https://bugs.ruby-lang.org/issues/18604 & here: ruby/bigdecimal#220
Potential fix here: ruby/bigdecimal@e236c2e
  • Loading branch information
estebanz01 committed Oct 31, 2022
1 parent ffe0969 commit 9f2e6a1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/math.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ def self.incomplete_beta_function(x, alp, bet)

d = 1.0 + numerator * d
d = tiny if d.abs < tiny
d = 1.0 / d
d = 1.0 / d.to_r

c = 1.0 + numerator / c
c = 1.0 + numerator / c.to_r
c = tiny if c.abs < tiny

cd = (c*d).freeze
Expand Down

0 comments on commit 9f2e6a1

Please sign in to comment.