export var clamp = function clamp(val, min, max) {
  if (val < min) {
    return min;
  }
  if (val > max) {
    return max;
  }
  return val;
};
export var getDecimalPrecision = function getDecimalPrecision(num) {
  if (Math.abs(num) < 1) {
    var parts = num.toExponential().split('e-');
    var matissaDecimalPart = parts[0].split('.')[1];
    return (matissaDecimalPart ? matissaDecimalPart.length : 0) + parseInt(parts[1], 10);
  }
  var decimalPart = num.toString().split('.')[1];
  return decimalPart ? decimalPart.length : 0;
};
export var roundValueToStep = function roundValueToStep(value, step, oldValue) {
  var nearest = Math.round((value - oldValue) / step) * step + oldValue;
  return Number(nearest.toFixed(getDecimalPrecision(step)));
};
export var percentToValue = function percentToValue(percent, min, max) {
  return (max - min) * percent + min;
};
export var valueToPercent = function valueToPercent(value, min, max) {
  var percent = (value - min) * 100 / (max - min);
  if (percent < 0) {
    return 0;
  }
  if (percent > 100) {
    return 100;
  }
  return percent;
};