docs: function gratR(a, x, logr) {
        var ser, z, l, h, rinv;
  
        rinv = Math.exp(-logr);
        /* R's TOMS code handles this slightly differently (1214 in toms708.c) */
        if (x === 0) { return rinv; }
        if (a === 0) { return 0; }
        if (a === 0.5) {
           return x < 0.25 ? (1 - erf(Math.sqrt(x))) * rinv
                           : Math.exp(x) * erfc(Math.sqrt(x)) / Math.sqrt(x) * Math.sqrt(Math.PI);
        }
        z = a * Math.log(x);
        l = expm1(z);
        h = gam1(a);
        if (x < 1.1) {
           ser = a * x * series((function(c, v) {
                 return function(i) {
                    c += 1;
                    if (i > 0) { v = v * -x / (i + 1); }
                    return v / c;
                 };
              }(a, 1))
           );
           if (x >= 0.25 && a < x / 2.59 || z > -0.13394) {
              return Math.max(0, ((Math.exp(z) * ser - l) * (1 + h) - h) * rinv);
           }
           return (1 - Math.exp(z) * (1 + h) * (1 - ser)) * rinv;
        }
        return cf(a, x);
     }