Skip to content

Conversation

@tompng
Copy link
Member

@tompng tompng commented Oct 29, 2025

Implement gamma and lgamma with Spouge's approximation
https://en.wikipedia.org/wiki/Spouge%27s_approximation

It's relatively simple compared to other algorithm.
It's designed to converges in wide range of x without special care. This characteristic is important to calculate gamma for huge number: BigMath.gamma(BigDecimal(10000000), 100)

Other algorithms that I tried:

  • Lanczos approximation(https://en.wikipedia.org/wiki/Lanczos_approximation)
    • Cost of calculating coefficient is high
  • Polynomial approximation of gamma(x)*f(x) with various f(x)
    • Sometimes faster than Spouge's approximation
    • gamma(small_digits_x, prec) can be extremely fast
    • gamma(huge_number, prec) is slow, so Lanczos or Spouge is necessary anyway

@tompng tompng force-pushed the bigmath_gamma branch 2 times, most recently from 3be6cd0 to 21185ce Compare December 3, 2025 19:21
@tompng tompng marked this pull request as ready for review December 3, 2025 19:39
Implement gamma and lgamma with Spouge's approximation
@mrkn mrkn added this to the v4.0 milestone Dec 10, 2025
@mrkn mrkn merged commit 2c18610 into ruby:master Dec 10, 2025
81 checks passed
@tompng tompng deleted the bigmath_gamma branch December 10, 2025 16:15
ksss added a commit to ksss/rbs that referenced this pull request Dec 17, 2025
ksss added a commit to ksss/rbs that referenced this pull request Dec 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants