X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=node_modules%2Funcss%2Fnode_modules%2Flodash%2Finternal%2FcreateRound.js;fp=node_modules%2Funcss%2Fnode_modules%2Flodash%2Finternal%2FcreateRound.js;h=3431fe02fff0500e9f3f9b9daf6a33dcea051974;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/node_modules/uncss/node_modules/lodash/internal/createRound.js b/node_modules/uncss/node_modules/lodash/internal/createRound.js new file mode 100644 index 000000000..3431fe02f --- /dev/null +++ b/node_modules/uncss/node_modules/lodash/internal/createRound.js @@ -0,0 +1,30 @@ +var toInteger = require('../toInteger'), + toNumber = require('../toNumber'), + toString = require('../toString'); + +/** + * Creates a function like `_.round`. + * + * @private + * @param {string} methodName The name of the `Math` method to use when rounding. + * @returns {Function} Returns the new round function. + */ +function createRound(methodName) { + var func = Math[methodName]; + return function(number, precision) { + number = toNumber(number); + precision = toInteger(precision); + if (precision) { + // Shift with exponential notation to avoid floating-point issues. + // See [MDN](https://mdn.io/round#Examples) for more details. + var pair = (toString(number) + 'e').split('e'), + value = func(pair[0] + 'e' + (+pair[1] + precision)); + + pair = (toString(value) + 'e').split('e'); + return +(pair[0] + 'e' + (+pair[1] - precision)); + } + return func(number); + }; +} + +module.exports = createRound;