panthrMath/basicFunc/gratio.js
function findx0SmallA(a, p, q) {
      var B, u, temp;

      B = q * gamma(a);
      if (B > 0.6 || B >= 0.45 && a >= 0.3) {
         // use 21
         u = B * q > 1e-8 ? Math.pow(p * gamma(a + 1), 1 / a)
                          : Math.exp(-q / a - eulerGamma);
         return u / (1 - u / (a + 1));
      }
      if (a < 0.3 && B >= 0.35 && B <= 0.6) {
         // use 22
         temp = Math.exp(-eulerGamma - B);
         u = temp * Math.exp(temp);
         return temp * Math.exp(u);
      }
      temp = -Math.log(B);
      u = temp - (1 - a) * Math.log(temp);
      if (B >= 0.15) {
         // use 23, with temp for y and u for v
         return temp - (1 - a) * Math.log(u) -
                  Math.log(1 + (1 - a) / (1 + u));
      }
      if (B > 0.01) {
         // use 24, with temp for y and u for v
         return temp - (1 - a) * Math.log(u) - Math.log(
            (u * u + 2 * (3 - a) * u + (2 - a) * (3 - a)) /
            (u * u + (5 - a) * u + 2));
      }
      // use 25, where c1 + ... + c5/y^4 is treated as a polynomial in y^-1
      // using u for c1, temp for y
      return findx0TinyB(a, temp);
   }
function findx0SmallA(a, p, q) {
      var B, u, temp;

      B = q * gamma(a);
      if (B > 0.6 || B >= 0.45 && a >= 0.3) {
         // use 21
         u = B * q > 1e-8 ? Math.pow(p * gamma(a + 1), 1 / a)
                          : Math.exp(-q / a - eulerGamma);
         return u / (1 - u / (a + 1));
      }
      if (a < 0.3 && B >= 0.35 && B <= 0.6) {
         // use 22
         temp = Math.exp(-eulerGamma - B);
         u = temp * Math.exp(temp);
         return temp * Math.exp(u);
      }
      temp = -Math.log(B);
      u = temp - (1 - a) * Math.log(temp);
      if (B >= 0.15) {
         // use 23, with temp for y and u for v
         return temp - (1 - a) * Math.log(u) -
                  Math.log(1 + (1 - a) / (1 + u));
      }
      if (B > 0.01) {
         // use 24, with temp for y and u for v
         return temp - (1 - a) * Math.log(u) - Math.log(
            (u * u + 2 * (3 - a) * u + (2 - a) * (3 - a)) /
            (u * u + (5 - a) * u + 2));
      }
      // use 25, where c1 + ... + c5/y^4 is treated as a polynomial in y^-1
      // using u for c1, temp for y
      return findx0TinyB(a, temp);
   }
function findx0SmallA ( a , p , q ) { var B , u , temp ; B = q * gamma ( a ) ; if ( B > 0.6 || B >= 0.45 && a >= 0.3 ) { // use 21 u = B * q > 1e-8 ? Math . pow ( p * gamma ( a + 1 ) , 1 / a ) : Math . exp ( - q / a - eulerGamma ) ; return u / ( 1 - u / ( a + 1 ) ) ; } if ( a < 0.3 && B >= 0.35 && B <= 0.6 ) { // use 22 temp = Math . exp ( - eulerGamma - B ) ; u = temp * Math . exp ( temp ) ; return temp * Math . exp ( u ) ; } temp = - Math . log ( B ) ; u = temp - ( 1 - a ) * Math . log ( temp ) ; if ( B >= 0.15 ) { // use 23, with temp for y and u for v return temp - ( 1 - a ) * Math . log ( u ) - Math . log ( 1 + ( 1 - a ) / ( 1 + u ) ) ; } if ( B > 0.01 ) { // use 24, with temp for y and u for v return temp - ( 1 - a ) * Math . log ( u ) - Math . log ( ( u * u + 2 * ( 3 - a ) * u + ( 2 - a ) * ( 3 - a ) ) / ( u * u + ( 5 - a ) * u + 2 ) ) ; } // use 25, where c1 + ... + c5/y^4 is treated as a polynomial in y^-1 // using u for c1, temp for y return findx0TinyB ( a , temp ) ; }
Use formulas 21 through 25 from DiDonato to get initial estimate for x when a < 1.
Use formulas 21 through 25 from DiDonato to get initial estimate for x when a < 1 .