Created
August 10, 2013 23:56
-
-
Save samme/6202716 to your computer and use it in GitHub Desktop.
Really simple number methods ☺
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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