Skip to content

Instantly share code, notes, and snippets.

@samme
Created August 10, 2013 23:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samme/6202716 to your computer and use it in GitHub Desktop.
Save samme/6202716 to your computer and use it in GitHub Desktop.
Really simple number methods ☺
define(function (){
'use strict';
var math = Math,
abs = math.abs,
max = math.max,
min = math.min;
return {
absMax: function (a, b){
return abs(a) > abs(b) ? a : b;
},
absMin: function (a, b){
return abs(a) < abs(b) ? a : b;
},
clip: function (n, low, high){
return max(low, min(high, n));
},
sign: function (n){
return n > 0 ? 1 : (n < 0 ? -1 : (n === 0 ? 0 : NaN));
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment