Restricts a number to falling within a given range.
 Returns the number if it falls within the range,
 or the closest value in the range if it doesn't.

 @param value [Numeric]
 @param range [Range<Numeric>]
 @return [Numeric]
540540
def restrict(value, range)
      [[value, range.first].max, range.last].min
    end
1032182
function range(defaultMin, defaultMax, min, max) {
  if (min === undefined) {
    return integer(defaultMin, defaultMax); // ()
  }

  if (max === undefined) {
    return min; // ( len )
  }

  return integer(min, max); // ( min, max )
}
37319
function range(start, stop) {
  if (arguments.length <= 1) {
    stop = start || 0;
    start = 0;
  }

  var length = Math.max(stop - start, 0);
  var idx = 0;
  var arr = new Array(length);

  while(idx < length) {
    arr[idx++] = start;
    start += 1;
  }

  return arr;
}
74502
def range_values(args):
    
    if len(args) == 1:
        return Interval(0, args[0].high)
    elif len(args) == 2:
        return Interval(args[0].low, args[1].high)
    elif len(args) == 3:
        is_neg = args[2].low < 0
        is_pos = args[2].high > 0
        if is_neg and is_pos:
            return UNKNOWN_RANGE
        elif is_neg:
            return Interval(args[1].low, args[0].high)
        else:
            return Interval(args[0].low, args[1].high)
145554
function range(n,type) {
  n = (typeof n !== 'undefined') ?  n : 0;
  if (!(Number.isInteger(n))) throw Error("Error in range: Value must be an integer");
  let array;
    
  if(type=='Uint8')  array = new Uint8Array(n);
  if(type=='Uint16') array = new Uint16Array(n);
  if(type=='Uint32') array = new Uint32Array(n);
  if(type=='Int8')  array = new Int8Array(n);
  if(type=='Int16') array = new Int16Array(n);
  if(type=='Int32') array = new Int32Array(n);
  if(type=='Float32')  array = new Float32Array(n);
  if((typeof type === 'undefined') || !array)array = new Array(n);
    
  for(let i=0;i<n;i++)array[i]=i;
  return array;
}
57707
public static boolean isValid(Range range) {
        if (range == null) {
            return false;
        }
        
        double min = range.getMinimum().doubleValue();
        double max = range.getMaximum().doubleValue();
        
        return min != max && !Double.isNaN(min) && !Double.isInfinite(min) &&
                !Double.isNaN(max) && !Double.isInfinite(max);
    }
318450
def _range_check(self, value, min_value, max_value):
        '''
        
        '''
        if value < min_value or value > max_value:
            raise ValueError('%s out of range - %s is not between %s and %s' % (self.__class__.__name__, value, min_value, max_value))
587119
public static boolean isBetween( double value, double... ranges ) {
        boolean even = true;
        for( int i = 0; i < ranges.length; i++ ) {
            if (even) {
                // lower bound
                if (value < ranges[i]) {
                    return false;
                }
            } else {
                // higher bound
                if (value > ranges[i]) {
                    return false;
                }
            }
            even = !even;
        }
        return true;
    }
1359724
public static boolean contains(Range range, double value) {
        return value >= range.getMinimum().doubleValue() && value <= range.getMaximum().doubleValue();
    }
1312751
def validate_LESSTHANEQ(value, restriction):
    
    #Sometimes restriction values can accidentally be put in the template <item>100</items>,
    #Making them a list, not a number. Rather than blowing up, just get value 1 from the list.
    if type(restriction) is list:
        restriction = restriction[0]

    value = _get_val(value)
    if type(value) is list:
        for subval in value:
            if type(subval) is tuple:
                subval = subval[1]
            validate_LESSTHANEQ(subval, restriction)
    else:
        try:
            if value > restriction:
                raise ValidationError("LESSTHANEQ: %s" % (restriction))
        except TypeError:
            # Incompatible types for comparison.
            raise ValidationError("LESSTHANEQ: Incompatible types %s"%(restriction))
869512
def sub(self, num):
        
        try:
            val = self.value() - num
        except:
            val = -num
        self.set(max(0, val))
836106
def within_limits(self, value):
        

        if isinstance(value, int) or isinstance(value, float):
            value = value * self.default_unit

        return (self.limits[0] is None or value >= self.limits[0]) and (self.limits[1] is None or value <= self.limits[1])
434212
public boolean inRanges(Instance instance, double[][] ranges) {
    boolean isIn = true;
    
    // updateRangesFirst must have been called on ranges
    for (int j = 0; isIn && (j < ranges.length); j++) {
      if (!instance.isMissing(j)) {
        double value = instance.value(j);
        isIn = value <= ranges[j][R_MAX];
        if (isIn) isIn = value >= ranges[j][R_MIN];
      }
    }
    
    return isIn;
  }
1001682
public static FormValidation validateIntegerInRange(String value, int lower, int upper) {
        try {
            int intValue = Integer.parseInt(value);
            if (intValue < lower) {
                return error(hudson.model.Messages.Hudson_MustBeAtLeast(lower));
            }
            if (intValue > upper) {
                return error(hudson.model.Messages.Hudson_MustBeAtMost(upper));
            }
            return ok();
        } catch (NumberFormatException e) {
            return error(hudson.model.Messages.Hudson_NotANumber());
        }
    }
474502
private float limit(float value, float min, float max) {
    return Math.min(Math.max(min, value), max);
  }
631973
public static float updateFloat(float value, float range) {
		range = range == 0 ? (float) (0.1 * value) : range;
		float min = value - range;
		float max = value + range;
		return nextFloat(min, max);
	}
1094797
def range(self, count):
        
        if count <= 1:
            raise ValueError("Range size must be greater than 1.")
        dom = self._domain
        distance = dom[-1] - dom[0]
        props = [ self(dom[0] + distance * float(x)/(count-1))
            for x in range(count) ]
        return props