UNPKG

hypertune

Version:

[Hypertune](https://www.hypertune.com/) is the most flexible platform for feature flags, A/B testing, analytics and app configuration. Built with full end-to-end type-safety, Git-style version control and local, synchronous, in-memory flag evaluation. Opt

32 lines 1.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = logbeta; function logbeta(a, b) { // Log Beta Function using the relationship with Gamma function // ln(Beta(a,b)) = ln(Gamma(a)) + ln(Gamma(b)) - ln(Gamma(a+b)) return lnGamma(a) + lnGamma(b) - lnGamma(a + b); } // Efficient implementation of ln(Gamma(x)) using Lanczos approximation function lnGamma(x) { const p = [ 676.5203681218851, -1259.1392167224028, 771.32342877765313, -176.61502916214059, 12.507343278686905, -0.13857109526572012, 9.9843695780195716e-6, 1.5056327351493116e-7, ]; if (x < 0.5) { return Math.log(Math.PI) - Math.log(Math.sin(Math.PI * x)) - lnGamma(1 - x); } // eslint-disable-next-line no-param-reassign x -= 1; const y = x + 7.5; let sum = 0.99999999999980993; // eslint-disable-next-line no-plusplus for (let i = 0; i < p.length; i++) { sum += p[i] / (x + i + 1); } return (Math.log(Math.sqrt(2 * Math.PI)) + (x + 0.5) * Math.log(y) - y + Math.log(sum)); } //# sourceMappingURL=logbeta.js.map