UNPKG

nowjs-core

Version:

NowCanDo Javascript Core [nowjs-core] is a library written by TypeScript code maintains under Apache 2.0 licence

34 lines (33 loc) 951 B
function mathClamp(x, min, max) { return Math.min(max, Math.max(min, x)); } function mathFscale(x, inLow, inHigh, outLow, outHigh) { return Math.fround(Math.scale(x, inLow, inHigh, outLow, outHigh)); } function mathScale(x, inLow, inHigh, outLow, outHigh) { if (arguments.length === 0 || x !== x || inLow !== inLow || inHigh !== inHigh || outLow !== outLow || outHigh !== outHigh) { return NaN; } if (x === Infinity || x === -Infinity) { return x; } return ((x - inLow) * (outHigh - outLow)) / (inHigh - inLow) + outLow; } function mathRadians(degrees) { return degrees * Math.DEG_PER_RAD; } function mathDegrees(radians) { return radians * Math.RAD_PER_DEG; } Math.DEG_PER_RAD = Math.PI / 180; Math.RAD_PER_DEG = 180 / Math.PI; Math.clamp = mathClamp; Math.fscale = mathFscale; Math.scale = mathScale; Math.radians = mathRadians; Math.degrees = mathDegrees;