Approximates the limiting distribution to about 5 decimal digits.
541344
def ad_unif_inf(statistic):
    
    z = statistic
    if z < 2:
        return (exp(-1.2337141 / z) / sqrt(z) *
                                (2.00012 + (.247105 - (.0649821 - (.0347962 -
                                (.011672 - .00168691 * z) * z) * z) * z) * z))
    else:
        return exp(-exp(1.0776 - (2.30695 - (.43424 - (.082433 -
                                (.008056 - .0003146 * z) * z) * z) * z) * z))
847917
def _format_number(number, initial_value_sig_digits, number_of_significant_digits, max_digits_after_decimal, isToAlign,
                   format_target):
    
    assert format_target in POSSIBLE_FORMAT_TARGETS, "Invalid format " + format_target

    # Round to the given amount of significant digits
    intended_digits = min(initial_value_sig_digits, number_of_significant_digits)
    if number == 0:
        formatted_value = '0'
        if max_digits_after_decimal > 0 and initial_value_sig_digits > 0:
            formatted_value += '.' + '0' * min(max_digits_after_decimal, initial_value_sig_digits)

    else:
        float_value = round(number, - int(floor(log10(abs(number)))) + (number_of_significant_digits - 1))

        if not format_target.startswith('tooltip'):
            max_digits_to_display = max_digits_after_decimal
        else:
            max_digits_to_display = len(
                str(float_value))  # This value may be too big, but extra digits will be cut below
        formatted_value = "{0:.{1}f}".format(float_value, max_digits_to_display)

        # Get the number of intended significant digits and the number of current significant digits.
        # If we have not enough digits due to rounding, 0's have to be re-added.
        # If we have too many digits due to conversion of integers to float (e.g. 1234.0), the decimals have to be cut
        current_sig_digits = _get_significant_digits(formatted_value)

        digits_to_add = intended_digits - current_sig_digits

        if digits_to_add > 0:
            if '.' not in formatted_value:
                raise AssertionError(
                    "Unexpected string '{}' after rounding '{}' to '{}' with {} significant digits and {} decimal digits for format '{}'"
                        .format(formatted_value, number, float_value, intended_digits, max_digits_to_display,
                                format_target))
            formatted_value += "".join(['0'] * digits_to_add)
        elif digits_to_add < 0:
            if '.' in formatted_value[:digits_to_add]:
                formatted_value = formatted_value[:digits_to_add]
            else:
                formatted_value = str(round(float_value))

            if formatted_value.endswith('.'):
                formatted_value = formatted_value[:-1]

    # Cut the 0 in front of the decimal point for values < 1.
    # Example: 0.002 => .002
    if _is_to_cut(formatted_value, format_target, isToAlign):
        assert formatted_value[0] == '0'
        formatted_value = formatted_value[1:]

    # Alignment
    if isToAlign:
        formatted_value = _format_number_align(formatted_value, max_digits_after_decimal, format_target)
    return formatted_value
515297
public static int discretize(double value, double min, double max, int binCount) {
        int discreteValue = (int) (binCount * normalize(value, min, max));
        return clamp(discreteValue, 0, binCount - 1);
    }
474502
private float limit(float value, float min, float max) {
    return Math.min(Math.max(min, value), max);
  }
56903
def decimal_to_ratio(d):
    
    sign, digits, exp = d.as_tuple()
    if exp in ('F', 'n', 'N'):  # INF, NAN, sNAN
        assert not d.is_finite()
        raise ValueError
    num = 0
    for digit in digits:
        num = num * 10 + digit
    if sign:
        num = -num
    den = 10 ** -exp
    return (num, den)
361955
def drange(start: Decimal, stop: Decimal, num: int):
    '''
    
    '''
    delta = stop - start
    step = delta / (num - 1)
    yield from (start + step * Decimal(tick) for tick in range(0, num))
384209
function randomIntInRange(low, high) {
    return Math.round(low + (Math.random() * (high - low)));
  }
1231773
function(value, precision, base){
    var sizes =         ['Y','Z','E','P','T','G','M','k',''],
        fractionSizes = ['y','z','a','f','p','n','µ','m',''],
        total = sizes.length;

    base = base || 1000;
    precision = Math.pow(10, precision || 2);

    if (value === 0) return 0;

    if (value > 1) {
      while (total-- && (value >= base)) value /= base;
    }
    else {
      sizes = fractionSizes;
      total = sizes.length;
      while (total-- && (value < 1)) value *= base;
    }

    return (Math.round(value * precision) / precision) + sizes[total];
  }
505403
def percentage(value, digits=2):
    '''
    

    '''

    value = float(value) * 100.0
    return u'' + '%s %%' % (_format(value, digits),)
1336809
def distribution(self, limit=1024):
        
        res = self._qexec("%s, count(*) as __cnt" % self.name(), group="%s" % self.name(),
                          order="__cnt DESC LIMIT %d" % limit)
        dist = []
        cnt = self._table.size()
        for i, r in enumerate(res):
            dist.append(list(r) + [i, r[1] / float(cnt)])

        self._distribution = pd.DataFrame(dist, columns=["value", "cnt", "r", "fraction"])
        self._distribution.index = self._distribution.r

        return self._distribution
365589
def adapt_decimalfield_value(self, value, max_digits, decimal_places):
        
        if value is None:
            return None
        if isinstance(value, decimal.Decimal):
            context = decimal.getcontext().copy()
            context.prec = max_digits
            #context.rounding = ROUND_FLOOR
            return "%.*f" % (decimal_places + 1, value.quantize(decimal.Decimal(".1") ** decimal_places, context=context))
        else:
            return "%.*f" % (decimal_places + 1, value)
29917
def round(self, x):
        
        fraction, scaled_x, scale = self._get_fraction(x)
        rounddown = fraction < .5
        if rounddown:
            result = math.floor(scaled_x) / scale
        else:
            result = math.ceil(scaled_x) / scale
        self._record_roundoff_error(x, result)
        return result
519523
def rounddown(ctx, number, num_digits):
    
    number = conversions.to_decimal(number, ctx)
    num_digits = conversions.to_integer(num_digits, ctx)

    return decimal_round(number, num_digits, ROUND_DOWN)
1067738
function(x) {
    var limit = Math.PI/4;
    if (x < -limit || x > limit) {
      return (Math.cos(x) - 1.0);
    }

    var xx = x * x;
    return xx *
      (-0.5 + xx *
        (1/24 + xx *
          (-1/720 + xx *
            (1/40320 + xx *
              (-1/3628800 + xx *
                (1/4790014600 + xx *
                  (-1/87178291200 + xx *
                    (1/20922789888000)
                  )
                )
              )
            )
          )
        )
      )
  }
1127289
def round(value)
      # If the number is within epsilon of X.5, round up (or down for negative
      # numbers).
      mod = value % 1
      mod_is_half = (mod - 0.5).abs < Script::Value::Number.epsilon
      if value > 0
        !mod_is_half && mod < 0.5 ? value.floor : value.ceil
      else
        mod_is_half || mod < 0.5 ? value.floor : value.ceil
      end
    end
223444
def calc_limits(data, dist=None, padding=0.25):
    
    dmin = sys.float_info.max if dist is None else dist.get('min',
                                                            sys.float_info.max)
    dmax = sys.float_info.min if dist is None else dist.get('max',
                                                            sys.float_info.min)
    _min = min(min(data), dmin)
    _max = max(max(data), dmax)

    padding = padding * (_max - _min)
    return _min - padding, _max + padding
111217
def _generate_limit_items(lower, upper):
    
    # Use value + 0 to convert any -0.0 to 0.0 which looks better.
    if lower is not None and upper is not None and lower == upper:
        yield 'fixed', upper + 0
    else:
        if lower is not None:
            yield 'lower', lower + 0
        if upper is not None:
            yield 'upper', upper + 0