Nodejs Number Clamp clamp( min, max )

Here you can find the source of clamp( min, max )

Method Source Code

/**/*from   w w w. j  a v a 2s  .c  o m*/
 * Returns a number whose value is limited to the given range.
 *
 * Example: limit the output of this computation to between 0 and 255
 * (x * 255).clamp(0, 255)
 *
 * @param {Number} min The lower boundary of the output range
 * @param {Number} max The upper boundary of the output range
 * @returns A number in the range [min, max]
 * @type Number
 */
Number.prototype.clamp = function( min, max ) 
{
   return Math.min( Math.max( this, min ), max );
};

Related

  1. clamp(a, min, max)
    Math.clamp = function(a, min, max) {
        return a < min ? min : (a > max ? max : a);
    };
    
  2. clamp(val, min, max)
    Math.clamp = function(val, min, max) {
      return Math.min(Math.max(val, min), max);
    };
    
  3. clamp(min, max)
    Number.prototype.clamp = function(min, max) {
      if (this < min) return min;
      if (max < this) return max;
      return this.valueOf();
    };
    
  4. clamp(min, max)
    Number.prototype.clamp = function(min, max) {
      return Math.max(min, Math.min(this, max));
    };
    
  5. clamp(min, max)
    Number.prototype.clamp = function(min, max) {
      return Math.min(Math.max(this, min), max);
    };
    
  6. clamp(min, max)
    "use strict";
    var _this = this;
    Number.prototype.clamp = function (min, max) { 
      return Math.min(Math.max(_this, max), min); 
    };