Here you can find the source of clamp(min, max)
// AngryMob Copyright (c) 2015 Kristian Ignatov /**/* ww w .ja v a2 s .co m*/ * Native class extensions go here. */ /** * Check if the number fits between a minimum and maximum value, and return the min or max if not. * @param {Number} min * @param {Number} max * @returns {Number} */ Number.prototype.clamp = function(min, max) { if (this < min) return min; if (max < this) return max; return this.valueOf(); };
Math.clamp = function(a, min, max) { return a < min ? min : (a > max ? max : a); };
Math.clamp = function(val, min, max) { return Math.min(Math.max(val, min), max); };
Number.prototype.clamp = function( min, max ) return Math.min( Math.max( this, min ), max ); };
Number.prototype.clamp = function(min, max) { return Math.max(min, Math.min(this, max)); };
Number.prototype.clamp = function(min, max) { return Math.min(Math.max(this, min), max); };
"use strict"; var _this = this; Number.prototype.clamp = function (min, max) { return Math.min(Math.max(_this, max), min); };
Number.prototype.clamp = function (min, max) { return Math.min(Math.max(this, min), max); }; function randomFloat(min, max) { return min + Math.random() * (max - min);