From 3880070ba0c7e2307e25bbac505bb543022311fc Mon Sep 17 00:00:00 2001 From: "n.hefti" Date: Fri, 5 Aug 2016 17:53:12 +0200 Subject: [PATCH] Update config and readme for JsDeliver --- .gitignore | 4 +- README.md | 17 +- dist/formula.js | 7719 +++++++++++++++++++++++++++++++++++++++++++ dist/formula.min.js | 13 + package.json | 2 +- webpack.config.js | 5 + 6 files changed, 7755 insertions(+), 5 deletions(-) create mode 100644 dist/formula.js create mode 100644 dist/formula.min.js diff --git a/.gitignore b/.gitignore index 9f34d960..dc8e9e90 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,8 @@ build -dist +dist/*.standalone.* node_modules coverage-report.html *.tgz test/generated .idea -tmp \ No newline at end of file +tmp diff --git a/README.md b/README.md index 5e905d91..d0aba116 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,22 @@ formula.js JavaScript implementation of most Microsoft Excel formula functions -This library is under development. +USAGE +----- -Documentation available at [stoic.com/formula](http://stoic.com/formula) +Formulas depends on the following Open source Javascript libraries: Numeric, NumeralJs and jStats. + +Include them as follow to use formula.js in your browser: + + + + + + + + + + LICENSE ------- diff --git a/dist/formula.js b/dist/formula.js new file mode 100644 index 00000000..b57a2160 --- /dev/null +++ b/dist/formula.js @@ -0,0 +1,7719 @@ +(function webpackUniversalModuleDefinition(root, factory) { + if(typeof exports === 'object' && typeof module === 'object') + module.exports = factory(require("numeric"), require("numeral"), require("jStat")); + else if(typeof define === 'function' && define.amd) + define(["numeric", "numeral", "jStat"], factory); + else if(typeof exports === 'object') + exports["formulajs"] = factory(require("numeric"), require("numeral"), require("jStat")); + else + root["formulajs"] = factory(root["numeric"], root["numeral"], root["jStat"]); +})(this, function(__WEBPACK_EXTERNAL_MODULE_3__, __WEBPACK_EXTERNAL_MODULE_8__, __WEBPACK_EXTERNAL_MODULE_9__) { +return /******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; + +/******/ // The require function +/******/ function __webpack_require__(moduleId) { + +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) +/******/ return installedModules[moduleId].exports; + +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ exports: {}, +/******/ id: moduleId, +/******/ loaded: false +/******/ }; + +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); + +/******/ // Flag the module as loaded +/******/ module.loaded = true; + +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } + + +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; + +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; + +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; + +/******/ // Load entry module and return exports +/******/ return __webpack_require__(0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ function(module, exports, __webpack_require__) { + + var categories = [ + __webpack_require__(1), + __webpack_require__(15), + __webpack_require__(12), + __webpack_require__(16), + __webpack_require__(2), + __webpack_require__(7), + __webpack_require__(14), + __webpack_require__(17), + __webpack_require__(11), + __webpack_require__(18), + __webpack_require__(6), + __webpack_require__(10) + ]; + + for (var c in categories) { + var category = categories[c]; + for (var f in category) { + exports[f] = exports[f] || category[f]; + } + } + + +/***/ }, +/* 1 */ +/***/ function(module, exports, __webpack_require__) { + + var mathTrig = __webpack_require__(2); + var statistical = __webpack_require__(6); + var engineering = __webpack_require__(12); + var dateTime = __webpack_require__(14); + + function set(fn, root) { + if (root) { + for (var i in root) { + fn[i] = root[i]; + } + } + return fn; + } + + exports.BETADIST = statistical.BETA.DIST; + exports.BETAINV = statistical.BETA.INV; + exports.BINOMDIST = statistical.BINOM.DIST; + exports.CEILING = exports.ISOCEILING = set(mathTrig.CEILING.MATH, mathTrig.CEILING); + exports.CEILINGMATH = mathTrig.CEILING.MATH; + exports.CEILINGPRECISE = mathTrig.CEILING.PRECISE; + exports.CHIDIST = statistical.CHISQ.DIST; + exports.CHIDISTRT = statistical.CHISQ.DIST.RT; + exports.CHIINV = statistical.CHISQ.INV; + exports.CHIINVRT = statistical.CHISQ.INV.RT; + exports.CHITEST = statistical.CHISQ.TEST; + exports.CONFIDENCE = set(statistical.CONFIDENCE.NORM, statistical.CONFIDENCE); + exports.COVAR = statistical.COVARIANCE.P; + exports.COVARIANCEP = statistical.COVARIANCE.P; + exports.COVARIANCES = statistical.COVARIANCE.S; + exports.CRITBINOM = statistical.BINOM.INV; + exports.EXPONDIST = statistical.EXPON.DIST; + exports.ERFCPRECISE = engineering.ERFC.PRECISE; + exports.ERFPRECISE = engineering.ERF.PRECISE; + exports.FDIST = statistical.F.DIST; + exports.FDISTRT = statistical.F.DIST.RT; + exports.FINVRT = statistical.F.INV.RT; + exports.FINV = statistical.F.INV; + exports.FLOOR = set(mathTrig.FLOOR.MATH, mathTrig.FLOOR); + exports.FLOORMATH = mathTrig.FLOOR.MATH; + exports.FLOORPRECISE = mathTrig.FLOOR.PRECISE; + exports.FTEST = statistical.F.TEST; + exports.GAMMADIST = statistical.GAMMA.DIST; + exports.GAMMAINV = statistical.GAMMA.INV; + exports.GAMMALNPRECISE = statistical.GAMMALN.PRECISE; + exports.HYPGEOMDIST = statistical.HYPGEOM.DIST; + exports.LOGINV = statistical.LOGNORM.INV; + exports.LOGNORMINV = statistical.LOGNORM.INV; + exports.LOGNORMDIST = statistical.LOGNORM.DIST; + exports.MODE = set(statistical.MODE.SNGL, statistical.MODE); + exports.MODEMULT = statistical.MODE.MULT; + exports.MODESNGL = statistical.MODE.SNGL; + exports.NEGBINOMDIST = statistical.NEGBINOM.DIST; + exports.NETWORKDAYSINTL = dateTime.NETWORKDAYS.INTL; + exports.NORMDIST = statistical.NORM.DIST; + exports.NORMINV = statistical.NORM.INV; + exports.NORMSDIST = statistical.NORM.S.DIST; + exports.NORMSINV = statistical.NORM.S.INV; + exports.PERCENTILE = set(statistical.PERCENTILE.EXC, statistical.PERCENTILE); + exports.PERCENTILEEXC = statistical.PERCENTILE.EXC; + exports.PERCENTILEINC = statistical.PERCENTILE.INC; + exports.PERCENTRANK = set(statistical.PERCENTRANK.INC, statistical.PERCENTRANK); + exports.PERCENTRANKEXC = statistical.PERCENTRANK.EXC; + exports.PERCENTRANKINC = statistical.PERCENTRANK.INC; + exports.POISSON = set(statistical.POISSON.DIST, statistical.POISSON); + exports.POISSONDIST = statistical.POISSON.DIST; + exports.QUARTILE = set(statistical.QUARTILE.INC, statistical.QUARTILE); + exports.QUARTILEEXC = statistical.QUARTILE.EXC; + exports.QUARTILEINC = statistical.QUARTILE.INC; + exports.RANK = set(statistical.RANK.EQ, statistical.RANK); + exports.RANKAVG = statistical.RANK.AVG; + exports.RANKEQ = statistical.RANK.EQ; + exports.SKEWP = statistical.SKEW.P; + exports.STDEV = set(statistical.STDEV.S, statistical.STDEV); + exports.STDEVP = statistical.STDEV.P; + exports.STDEVS = statistical.STDEV.S; + exports.TDIST = statistical.T.DIST; + exports.TDISTRT = statistical.T.DIST.RT; + exports.TINV = statistical.T.INV; + exports.TTEST = statistical.T.TEST; + exports.VAR = set(statistical.VAR.S, statistical.VAR); + exports.VARP = statistical.VAR.P; + exports.VARS = statistical.VAR.S; + exports.WEIBULL = set(statistical.WEIBULL.DIST, statistical.WEIBULL); + exports.WEIBULLDIST = statistical.WEIBULL.DIST; + exports.WORKDAYINTL = dateTime.WORKDAY.INTL; + exports.ZTEST = statistical.Z.TEST; + + +/***/ }, +/* 2 */ +/***/ function(module, exports, __webpack_require__) { + + var numeric = __webpack_require__(3); + var utils = __webpack_require__(4); + var error = __webpack_require__(5); + var statistical = __webpack_require__(6); + var information = __webpack_require__(11); + + exports.ABS = function(number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + return Math.abs(utils.parseNumber(number)); + }; + + exports.ACOS = function(number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + return Math.acos(number); + }; + + exports.ACOSH = function(number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + return Math.log(number + Math.sqrt(number * number - 1)); + }; + + exports.ACOT = function(number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + return Math.atan(1 / number); + }; + + exports.ACOTH = function(number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + return 0.5 * Math.log((number + 1) / (number - 1)); + }; + + //TODO: use options + exports.AGGREGATE = function(function_num, options, ref1, ref2) { + function_num = utils.parseNumber(function_num); + options = utils.parseNumber(function_num); + if (utils.anyIsError(function_num, options)) { + return error.value; + } + switch (function_num) { + case 1: + return statistical.AVERAGE(ref1); + case 2: + return statistical.COUNT(ref1); + case 3: + return statistical.COUNTA(ref1); + case 4: + return statistical.MAX(ref1); + case 5: + return statistical.MIN(ref1); + case 6: + return exports.PRODUCT(ref1); + case 7: + return statistical.STDEV.S(ref1); + case 8: + return statistical.STDEV.P(ref1); + case 9: + return exports.SUM(ref1); + case 10: + return statistical.VAR.S(ref1); + case 11: + return statistical.VAR.P(ref1); + case 12: + return statistical.MEDIAN(ref1); + case 13: + return statistical.MODE.SNGL(ref1); + case 14: + return statistical.LARGE(ref1, ref2); + case 15: + return statistical.SMALL(ref1, ref2); + case 16: + return statistical.PERCENTILE.INC(ref1, ref2); + case 17: + return statistical.QUARTILE.INC(ref1, ref2); + case 18: + return statistical.PERCENTILE.EXC(ref1, ref2); + case 19: + return statistical.QUARTILE.EXC(ref1, ref2); + } + }; + + exports.ARABIC = function(text) { + // Credits: Rafa? Kukawski + if (!/^M*(?:D?C{0,3}|C[MD])(?:L?X{0,3}|X[CL])(?:V?I{0,3}|I[XV])$/.test(text)) { + return error.value; + } + var r = 0; + text.replace(/[MDLV]|C[MD]?|X[CL]?|I[XV]?/g, function(i) { + r += { + M: 1000, + CM: 900, + D: 500, + CD: 400, + C: 100, + XC: 90, + L: 50, + XL: 40, + X: 10, + IX: 9, + V: 5, + IV: 4, + I: 1 + }[i]; + }); + return r; + }; + + exports.ASIN = function(number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + return Math.asin(number); + }; + + exports.ASINH = function(number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + return Math.log(number + Math.sqrt(number * number + 1)); + }; + + exports.ATAN = function(number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + return Math.atan(number); + }; + + exports.ATAN2 = function(number_x, number_y) { + number_x = utils.parseNumber(number_x); + number_y = utils.parseNumber(number_y); + if (utils.anyIsError(number_x, number_y)) { + return error.value; + } + return Math.atan2(number_x, number_y); + }; + + exports.ATANH = function(number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + return Math.log((1 + number) / (1 - number)) / 2; + }; + + exports.BASE = function(number, radix, min_length) { + min_length = min_length || 0; + + number = utils.parseNumber(number); + radix = utils.parseNumber(radix); + min_length = utils.parseNumber(min_length); + if (utils.anyIsError(number, radix, min_length)) { + return error.value; + } + min_length = (min_length === undefined) ? 0 : min_length; + var result = number.toString(radix); + return new Array(Math.max(min_length + 1 - result.length, 0)).join('0') + result; + }; + + exports.CEILING = function(number, significance, mode) { + significance = (significance === undefined) ? 1 : Math.abs(significance); + mode = mode || 0; + + number = utils.parseNumber(number); + significance = utils.parseNumber(significance); + mode = utils.parseNumber(mode); + if (utils.anyIsError(number, significance, mode)) { + return error.value; + } + if (significance === 0) { + return 0; + } + var precision = -Math.floor(Math.log(significance) / Math.log(10)); + if (number >= 0) { + return exports.ROUND(Math.ceil(number / significance) * significance, precision); + } else { + if (mode === 0) { + return -exports.ROUND(Math.floor(Math.abs(number) / significance) * significance, precision); + } else { + return -exports.ROUND(Math.ceil(Math.abs(number) / significance) * significance, precision); + } + } + }; + + exports.CEILING.MATH = exports.CEILING; + + exports.CEILING.PRECISE = exports.CEILING; + + exports.COMBIN = function(number, number_chosen) { + number = utils.parseNumber(number); + number_chosen = utils.parseNumber(number_chosen); + if (utils.anyIsError(number, number_chosen)) { + return error.value; + } + return exports.FACT(number) / (exports.FACT(number_chosen) * exports.FACT(number - number_chosen)); + }; + + exports.COMBINA = function(number, number_chosen) { + number = utils.parseNumber(number); + number_chosen = utils.parseNumber(number_chosen); + if (utils.anyIsError(number, number_chosen)) { + return error.value; + } + return (number === 0 && number_chosen === 0) ? 1 : exports.COMBIN(number + number_chosen - 1, number - 1); + }; + + exports.COS = function(number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + return Math.cos(number); + }; + + exports.COSH = function(number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + return (Math.exp(number) + Math.exp(-number)) / 2; + }; + + exports.COT = function(number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + return 1 / Math.tan(number); + }; + + exports.COTH = function(number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + var e2 = Math.exp(2 * number); + return (e2 + 1) / (e2 - 1); + }; + + exports.CSC = function(number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + return 1 / Math.sin(number); + }; + + exports.CSCH = function(number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + return 2 / (Math.exp(number) - Math.exp(-number)); + }; + + exports.DECIMAL = function(number, radix) { + if (arguments.length < 1) { + return error.value; + } + + + return parseInt(number, radix); + }; + + exports.DEGREES = function(number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + return number * 180 / Math.PI; + }; + + exports.EVEN = function(number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + return exports.CEILING(number, -2, -1); + }; + + exports.EXP = Math.exp; + + var MEMOIZED_FACT = []; + exports.FACT = function(number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + var n = Math.floor(number); + if (n === 0 || n === 1) { + return 1; + } else if (MEMOIZED_FACT[n] > 0) { + return MEMOIZED_FACT[n]; + } else { + MEMOIZED_FACT[n] = exports.FACT(n - 1) * n; + return MEMOIZED_FACT[n]; + } + }; + + exports.FACTDOUBLE = function(number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + var n = Math.floor(number); + if (n <= 0) { + return 1; + } else { + return n * exports.FACTDOUBLE(n - 2); + } + }; + + exports.FLOOR = function(number, significance) { + number = utils.parseNumber(number); + significance = utils.parseNumber(significance); + if (utils.anyIsError(number, significance)) { + return error.value; + } + if (significance === 0) { + return 0; + } + + if (!(number > 0 && significance > 0) && !(number < 0 && significance < 0)) { + return error.num; + } + + significance = Math.abs(significance); + var precision = -Math.floor(Math.log(significance) / Math.log(10)); + if (number >= 0) { + return exports.ROUND(Math.floor(number / significance) * significance, precision); + } else { + return -exports.ROUND(Math.ceil(Math.abs(number) / significance), precision); + } + }; + + //TODO: Verify + exports.FLOOR.MATH = function(number, significance, mode) { + significance = (significance === undefined) ? 1 : significance; + mode = (mode === undefined) ? 0 : mode; + + number = utils.parseNumber(number); + significance = utils.parseNumber(significance); + mode = utils.parseNumber(mode); + if (utils.anyIsError(number, significance, mode)) { + return error.value; + } + if (significance === 0) { + return 0; + } + + significance = significance ? Math.abs(significance) : 1; + var precision = -Math.floor(Math.log(significance) / Math.log(10)); + if (number >= 0) { + return exports.ROUND(Math.floor(number / significance) * significance, precision); + } else if (mode === 0 || mode === undefined) { + return -exports.ROUND(Math.ceil(Math.abs(number) / significance) * significance, precision); + } + return -exports.ROUND(Math.floor(Math.abs(number) / significance) * significance, precision); + }; + + // Deprecated + exports.FLOOR.PRECISE = exports.FLOOR.MATH; + + // adapted http://rosettacode.org/wiki/Greatest_common_divisor#JavaScript + exports.GCD = function() { + var range = utils.parseNumberArray(utils.flatten(arguments)); + if (range instanceof Error) { + return range; + } + var n = range.length; + var r0 = range[0]; + var x = r0 < 0 ? -r0 : r0; + for (var i = 1; i < n; i++) { + var ri = range[i]; + var y = ri < 0 ? -ri : ri; + while (x && y) { + if (x > y) { + x %= y; + } else { + y %= x; + } + } + x += y; + } + return x; + }; + + + exports.INT = function(number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + return Math.floor(number); + }; + + //TODO: verify + exports.ISO = { + CEILING: exports.CEILING + }; + + exports.LCM = function() { + // Credits: Jonas Raoni Soares Silva + var o = utils.parseNumberArray(utils.flatten(arguments)); + if (o instanceof Error) { + return o; + } + for (var i, j, n, d, r = 1; + (n = o.pop()) !== undefined;) { + while (n > 1) { + if (n % 2) { + for (i = 3, j = Math.floor(Math.sqrt(n)); i <= j && n % i; i += 2) { + //empty + } + d = (i <= j) ? i : n; + } else { + d = 2; + } + for (n /= d, r *= d, i = o.length; i; + (o[--i] % d) === 0 && (o[i] /= d) === 1 && o.splice(i, 1)) { + //empty + } + } + } + return r; + }; + + exports.LN = function(number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + return Math.log(number); + }; + + exports.LOG = function(number, base) { + number = utils.parseNumber(number); + base = utils.parseNumber(base); + if (utils.anyIsError(number, base)) { + return error.value; + } + base = (base === undefined) ? 10 : base; + return Math.log(number) / Math.log(base); + }; + + exports.LOG10 = function(number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + return Math.log(number) / Math.log(10); + }; + + exports.MDETERM = function(matrix) { + matrix = utils.parseMatrix(matrix); + if (matrix instanceof Error) { + return matrix; + } + return numeric.det(matrix); + }; + + exports.MINVERSE = function(matrix) { + matrix = utils.parseMatrix(matrix); + if (matrix instanceof Error) { + return matrix; + } + return numeric.inv(matrix); + }; + + exports.MMULT = function(matrix1, matrix2) { + matrix1 = utils.parseMatrix(matrix1); + matrix2 = utils.parseMatrix(matrix2); + if (utils.anyIsError(matrix1, matrix2)) { + return error.value; + } + return numeric.dot(matrix1, matrix2); + }; + + exports.MOD = function(dividend, divisor) { + dividend = utils.parseNumber(dividend); + divisor = utils.parseNumber(divisor); + if (utils.anyIsError(dividend, divisor)) { + return error.value; + } + if (divisor === 0) { + return error.div0; + } + var modulus = Math.abs(dividend % divisor); + return (divisor > 0) ? modulus : -modulus; + }; + + exports.MROUND = function(number, multiple) { + number = utils.parseNumber(number); + multiple = utils.parseNumber(multiple); + if (utils.anyIsError(number, multiple)) { + return error.value; + } + if (number * multiple < 0) { + return error.num; + } + + return Math.round(number / multiple) * multiple; + }; + + exports.MULTINOMIAL = function() { + var args = utils.parseNumberArray(utils.flatten(arguments)); + if (args instanceof Error) { + return args; + } + var sum = 0; + var divisor = 1; + for (var i = 0; i < args.length; i++) { + sum += args[i]; + divisor *= exports.FACT(args[i]); + } + return exports.FACT(sum) / divisor; + }; + + exports.MUNIT = function(dimension) { + dimension = utils.parseNumber(dimension); + if (dimension instanceof Error) { + return dimension; + } + return numeric.identity(dimension); + }; + + exports.ODD = function(number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + var temp = Math.ceil(Math.abs(number)); + temp = (temp & 1) ? temp : temp + 1; + return (number > 0) ? temp : -temp; + }; + + exports.PI = function() { + return Math.PI; + }; + + exports.POWER = function(number, power) { + number = utils.parseNumber(number); + power = utils.parseNumber(power); + if (utils.anyIsError(number, power)) { + return error.value; + } + var result = Math.pow(number, power); + if (isNaN(result)) { + return error.num; + } + + return result; + }; + + exports.PRODUCT = function() { + var args = utils.parseNumberArray(utils.flatten(arguments)); + if (args instanceof Error) { + return args; + } + var result = 1; + for (var i = 0; i < args.length; i++) { + result *= args[i]; + } + return result; + }; + + exports.QUOTIENT = function(numerator, denominator) { + numerator = utils.parseNumber(numerator); + denominator = utils.parseNumber(denominator); + if (utils.anyIsError(numerator, denominator)) { + return error.value; + } + return parseInt(numerator / denominator, 10); + }; + + exports.RADIANS = function(number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + return number * Math.PI / 180; + }; + + exports.RAND = function() { + return Math.random(); + }; + + exports.RANDBETWEEN = function(bottom, top) { + bottom = utils.parseNumber(bottom); + top = utils.parseNumber(top); + if (utils.anyIsError(bottom, top)) { + return error.value; + } + // Creative Commons Attribution 3.0 License + // Copyright (c) 2012 eqcode + return bottom + Math.ceil((top - bottom + 1) * Math.random()) - 1; + }; + + // TODO + exports.ROMAN = function(number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + // The MIT License + // Copyright (c) 2008 Steven Levithan + var digits = String(number).split(''); + var key = ['', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM', '', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC', '', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX']; + var roman = ''; + var i = 3; + while (i--) { + roman = (key[+digits.pop() + (i * 10)] || '') + roman; + } + return new Array(+digits.join('') + 1).join('M') + roman; + }; + + exports.ROUND = function(number, digits) { + number = utils.parseNumber(number); + digits = utils.parseNumber(digits); + if (utils.anyIsError(number, digits)) { + return error.value; + } + return Math.round(number * Math.pow(10, digits)) / Math.pow(10, digits); + }; + + exports.ROUNDDOWN = function(number, digits) { + number = utils.parseNumber(number); + digits = utils.parseNumber(digits); + if (utils.anyIsError(number, digits)) { + return error.value; + } + var sign = (number > 0) ? 1 : -1; + return sign * (Math.floor(Math.abs(number) * Math.pow(10, digits))) / Math.pow(10, digits); + }; + + exports.ROUNDUP = function(number, digits) { + number = utils.parseNumber(number); + digits = utils.parseNumber(digits); + if (utils.anyIsError(number, digits)) { + return error.value; + } + var sign = (number > 0) ? 1 : -1; + return sign * (Math.ceil(Math.abs(number) * Math.pow(10, digits))) / Math.pow(10, digits); + }; + + exports.SEC = function(number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + return 1 / Math.cos(number); + }; + + exports.SECH = function(number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + return 2 / (Math.exp(number) + Math.exp(-number)); + }; + + exports.SERIESSUM = function(x, n, m, coefficients) { + x = utils.parseNumber(x); + n = utils.parseNumber(n); + m = utils.parseNumber(m); + coefficients = utils.parseNumberArray(coefficients); + if (utils.anyIsError(x, n, m, coefficients)) { + return error.value; + } + var result = coefficients[0] * Math.pow(x, n); + for (var i = 1; i < coefficients.length; i++) { + result += coefficients[i] * Math.pow(x, n + i * m); + } + return result; + }; + + exports.SIGN = function(number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + if (number < 0) { + return -1; + } else if (number === 0) { + return 0; + } else { + return 1; + } + }; + + exports.SIN = function(number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + return Math.sin(number); + }; + + exports.SINH = function(number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + return (Math.exp(number) - Math.exp(-number)) / 2; + }; + + exports.SQRT = function(number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + if (number < 0) { + return error.num; + } + return Math.sqrt(number); + }; + + exports.SQRTPI = function(number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + return Math.sqrt(number * Math.PI); + }; + + exports.SUBTOTAL = function(function_code, ref1) { + function_code = utils.parseNumber(function_code); + if (function_code instanceof Error) { + return function_code; + } + switch (function_code) { + case 1: + return statistical.AVERAGE(ref1); + case 2: + return statistical.COUNT(ref1); + case 3: + return statistical.COUNTA(ref1); + case 4: + return statistical.MAX(ref1); + case 5: + return statistical.MIN(ref1); + case 6: + return exports.PRODUCT(ref1); + case 7: + return statistical.STDEV.S(ref1); + case 8: + return statistical.STDEV.P(ref1); + case 9: + return exports.SUM(ref1); + case 10: + return statistical.VAR.S(ref1); + case 11: + return statistical.VAR.P(ref1); + // no hidden values for us + case 101: + return statistical.AVERAGE(ref1); + case 102: + return statistical.COUNT(ref1); + case 103: + return statistical.COUNTA(ref1); + case 104: + return statistical.MAX(ref1); + case 105: + return statistical.MIN(ref1); + case 106: + return exports.PRODUCT(ref1); + case 107: + return statistical.STDEV.S(ref1); + case 108: + return statistical.STDEV.P(ref1); + case 109: + return exports.SUM(ref1); + case 110: + return statistical.VAR.S(ref1); + case 111: + return statistical.VAR.P(ref1); + + } + }; + + exports.ADD = function (num1, num2) { + if (arguments.length !== 2) { + return error.na; + } + + num1 = utils.parseNumber(num1); + num2 = utils.parseNumber(num2); + if (utils.anyIsError(num1, num2)) { + return error.value; + } + + return num1 + num2; + }; + + exports.MINUS = function (num1, num2) { + if (arguments.length !== 2) { + return error.na; + } + + num1 = utils.parseNumber(num1); + num2 = utils.parseNumber(num2); + if (utils.anyIsError(num1, num2)) { + return error.value; + } + + return num1 - num2; + }; + + exports.DIVIDE = function (dividend, divisor) { + if (arguments.length !== 2) { + return error.na; + } + + dividend = utils.parseNumber(dividend); + divisor = utils.parseNumber(divisor); + if (utils.anyIsError(dividend, divisor)) { + return error.value; + } + + if (divisor === 0) { + return error.div0; + } + + return dividend / divisor; + }; + + exports.MULTIPLY = function (factor1, factor2) { + if (arguments.length !== 2) { + return error.na; + } + + factor1 = utils.parseNumber(factor1); + factor2 = utils.parseNumber(factor2); + if (utils.anyIsError(factor1, factor2)) { + return error.value; + } + + return factor1 * factor2; + }; + + exports.GTE = function (num1, num2) { + if (arguments.length !== 2) { + return error.na; + } + + num1 = utils.parseNumber(num1); + num2 = utils.parseNumber(num2); + if (utils.anyIsError(num1, num2)) { + return error.error; + } + + return num1 >= num2; + }; + + exports.LT = function (num1, num2) { + if (arguments.length !== 2) { + return error.na; + } + + num1 = utils.parseNumber(num1); + num2 = utils.parseNumber(num2); + if (utils.anyIsError(num1, num2)) { + return error.error; + } + + return num1 < num2; + }; + + + exports.LTE = function (num1, num2) { + if (arguments.length !== 2) { + return error.na; + } + + num1 = utils.parseNumber(num1); + num2 = utils.parseNumber(num2); + if (utils.anyIsError(num1, num2)) { + return error.error; + } + + return num1 <= num2; + }; + + exports.EQ = function (value1, value2) { + if (arguments.length !== 2) { + return error.na; + } + + return value1 === value2; + }; + + exports.NE = function (value1, value2) { + if (arguments.length !== 2) { + return error.na; + } + + return value1 !== value2; + }; + + exports.POW = function (base, exponent) { + if (arguments.length !== 2) { + return error.na; + } + + base = utils.parseNumber(base); + exponent = utils.parseNumber(exponent); + if (utils.anyIsError(base, exponent)) { + return error.error; + } + + return exports.POWER(base, exponent); + }; + + exports.SUM = function() { + var result = 0; + var argsKeys = Object.keys(arguments); + for (var i = 0; i < argsKeys.length; ++i) { + var elt = arguments[argsKeys[i]]; + if (typeof elt === 'number') { + result += elt; + } else if (typeof elt === 'string') { + var parsed = parseFloat(elt); + !isNaN(parsed) && (result += parsed); + } else if (Array.isArray(elt)) { + result += exports.SUM.apply(null, elt); + } + } + return result; + }; + + exports.SUMIF = function(range, criteria) { + range = utils.parseNumberArray(utils.flatten(range)); + if (range instanceof Error) { + return range; + } + var result = 0; + for (var i = 0; i < range.length; i++) { + result += (eval(range[i] + criteria)) ? range[i] : 0; // jshint ignore:line + } + return result; + }; + + exports.SUMIFS = function() { + var args = utils.argsToArray(arguments); + var range = utils.parseNumberArray(utils.flatten(args.shift())); + if (range instanceof Error) { + return range; + } + var criteria = args; + + var n_range_elements = range.length; + var n_criterias = criteria.length; + + var result = 0; + for (var i = 0; i < n_range_elements; i++) { + var el = range[i]; + var condition = ''; + for (var c = 0; c < n_criterias; c++) { + condition += el + criteria[c]; + if (c !== n_criterias - 1) { + condition += '&&'; + } + } + if (eval(condition)) { // jshint ignore:line + result += el; + } + } + return result; + }; + + exports.SUMPRODUCT = function() { + if (!arguments || arguments.length === 0) { + return error.value; + } + var arrays = arguments.length + 1; + var result = 0; + var product; + var k; + var _i; + var _ij; + for (var i = 0; i < arguments[0].length; i++) { + if (!(arguments[0][i] instanceof Array)) { + product = 1; + for (k = 1; k < arrays; k++) { + _i = utils.parseNumber(arguments[k - 1][i]); + if (_i instanceof Error) { + return _i; + } + product *= _i; + } + result += product; + } else { + for (var j = 0; j < arguments[0][i].length; j++) { + product = 1; + for (k = 1; k < arrays; k++) { + _ij = utils.parseNumber(arguments[k - 1][i][j]); + if (_ij instanceof Error) { + return _ij; + } + product *= _ij; + } + result += product; + } + } + } + return result; + }; + + exports.SUMSQ = function() { + var numbers = utils.parseNumberArray(utils.flatten(arguments)); + if (numbers instanceof Error) { + return numbers; + } + var result = 0; + var length = numbers.length; + for (var i = 0; i < length; i++) { + result += (information.ISNUMBER(numbers[i])) ? numbers[i] * numbers[i] : 0; + } + return result; + }; + + exports.SUMX2MY2 = function(array_x, array_y) { + array_x = utils.parseNumberArray(utils.flatten(array_x)); + array_y = utils.parseNumberArray(utils.flatten(array_y)); + if (utils.anyIsError(array_x, array_y)) { + return error.value; + } + var result = 0; + for (var i = 0; i < array_x.length; i++) { + result += array_x[i] * array_x[i] - array_y[i] * array_y[i]; + } + return result; + }; + + exports.SUMX2PY2 = function(array_x, array_y) { + array_x = utils.parseNumberArray(utils.flatten(array_x)); + array_y = utils.parseNumberArray(utils.flatten(array_y)); + if (utils.anyIsError(array_x, array_y)) { + return error.value; + } + var result = 0; + array_x = utils.parseNumberArray(utils.flatten(array_x)); + array_y = utils.parseNumberArray(utils.flatten(array_y)); + for (var i = 0; i < array_x.length; i++) { + result += array_x[i] * array_x[i] + array_y[i] * array_y[i]; + } + return result; + }; + + exports.SUMXMY2 = function(array_x, array_y) { + array_x = utils.parseNumberArray(utils.flatten(array_x)); + array_y = utils.parseNumberArray(utils.flatten(array_y)); + if (utils.anyIsError(array_x, array_y)) { + return error.value; + } + var result = 0; + array_x = utils.flatten(array_x); + array_y = utils.flatten(array_y); + for (var i = 0; i < array_x.length; i++) { + result += Math.pow(array_x[i] - array_y[i], 2); + } + return result; + }; + + exports.TAN = function(number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + return Math.tan(number); + }; + + exports.TANH = function(number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + var e2 = Math.exp(2 * number); + return (e2 - 1) / (e2 + 1); + }; + + exports.TRUNC = function(number, digits) { + digits = (digits === undefined) ? 0 : digits; + number = utils.parseNumber(number); + digits = utils.parseNumber(digits); + if (utils.anyIsError(number, digits)) { + return error.value; + } + var sign = (number > 0) ? 1 : -1; + return sign * (Math.floor(Math.abs(number) * Math.pow(10, digits))) / Math.pow(10, digits); + }; + +/***/ }, +/* 3 */ +/***/ function(module, exports) { + + module.exports = __WEBPACK_EXTERNAL_MODULE_3__; + +/***/ }, +/* 4 */ +/***/ function(module, exports, __webpack_require__) { + + var error = __webpack_require__(5); + + function flattenShallow(array) { + if (!array || !array.reduce) { return array; } + return array.reduce(function(a, b) { + var aIsArray = Array.isArray(a); + var bIsArray = Array.isArray(b); + if (aIsArray && bIsArray ) { + return a.concat(b); + } + if (aIsArray) { + a.push(b); + return a; + } + if (bIsArray) { + return [a].concat(b); + } + return [a, b]; + }); + } + + function isFlat(array) { + if (!array) { return false; } + for (var i = 0; i < array.length; ++i) { + if (Array.isArray(array[i])) { + return false; + } + } + return true; + } + + exports.flatten = function() { + var result = exports.argsToArray.apply(null, arguments); + while (!isFlat(result)) { + result = flattenShallow(result); + } + return result; + }; + + exports.argsToArray = function(args) { + return Array.prototype.slice.call(args, 0); + }; + + exports.numbers = function() { + var possibleNumbers = this.flatten.apply(null, arguments); + return possibleNumbers.filter(function(el) { + return typeof el === 'number'; + }); + }; + + exports.cleanFloat = function(number) { + var power = 1e14; + return Math.round(number * power) / power; + }; + + exports.parseBool = function(bool) { + if (typeof bool === 'boolean') { + return bool; + } + + if (bool instanceof Error) { + return bool; + } + + if (typeof bool === 'number') { + return bool !== 0; + } + + if (typeof bool === 'string') { + var up = bool.toUpperCase(); + if (up === 'TRUE') { + return true; + } + + if (up === 'FALSE') { + return false; + } + } + + if (bool instanceof Date && !isNaN(bool)) { + return true; + } + + return error.value; + }; + + exports.parseNumber = function(string) { + if (string === undefined || string === '') { + return error.value; + } + if (!isNaN(string)) { + return parseFloat(string); + } + return error.value; + }; + + exports.parseNumberArray = function(arr) { + var len; + if (!arr || (len = arr.length) === 0) { + return error.value; + } + var parsed; + while (len--) { + parsed = exports.parseNumber(arr[len]); + if (parsed === error.value) { + return parsed; + } + arr[len] = parsed; + } + return arr; + }; + + exports.parseMatrix = function(matrix) { + var n; + if (!matrix || (n = matrix.length) === 0) { + return error.value; + } + var pnarr; + for (var i = 0; i < matrix.length; i++) { + pnarr = exports.parseNumberArray(matrix[i]); + matrix[i] = pnarr; + if (pnarr instanceof Error) { + return pnarr; + } + } + return matrix; + }; + + var d1900 = new Date(1900, 0, 1); + exports.parseDate = function(date) { + if (!isNaN(date)) { + if (date instanceof Date) { + return new Date(date); + } + var d = parseInt(date, 10); + if (d < 0) { + return error.num; + } + if (d <= 60) { + return new Date(d1900.getTime() + (d - 1) * 86400000); + } + return new Date(d1900.getTime() + (d - 2) * 86400000); + } + if (typeof date === 'string') { + date = new Date(date); + if (!isNaN(date)) { + return date; + } + } + return error.value; + }; + + exports.parseDateArray = function(arr) { + var len = arr.length; + var parsed; + while (len--) { + parsed = this.parseDate(arr[len]); + if (parsed === error.value) { + return parsed; + } + arr[len] = parsed; + } + return arr; + }; + + exports.anyIsError = function() { + var n = arguments.length; + while (n--) { + if (arguments[n] instanceof Error) { + return true; + } + } + return false; + }; + + exports.arrayValuesToNumbers = function(arr) { + var n = arr.length; + var el; + while (n--) { + el = arr[n]; + if (typeof el === 'number') { + continue; + } + if (el === true) { + arr[n] = 1; + continue; + } + if (el === false) { + arr[n] = 0; + continue; + } + if (typeof el === 'string') { + var number = this.parseNumber(el); + if (number instanceof Error) { + arr[n] = 0; + } else { + arr[n] = number; + } + } + } + return arr; + }; + + exports.rest = function(array, idx) { + idx = idx || 1; + if (!array || typeof array.slice !== 'function') { + return array; + } + return array.slice(idx); + }; + + exports.initial = function(array, idx) { + idx = idx || 1; + if (!array || typeof array.slice !== 'function') { + return array; + } + return array.slice(0, array.length - idx); + }; + +/***/ }, +/* 5 */ +/***/ function(module, exports) { + + exports.nil = new Error('#NULL!'); + exports.div0 = new Error('#DIV/0!'); + exports.value = new Error('#VALUE?'); + exports.ref = new Error('#REF!'); + exports.name = new Error('#NAME?'); + exports.num = new Error('#NUM!'); + exports.na = new Error('#N/A'); + exports.error = new Error('#ERROR!'); + exports.data = new Error('#GETTING_DATA'); + + +/***/ }, +/* 6 */ +/***/ function(module, exports, __webpack_require__) { + + var mathTrig = __webpack_require__(2); + var text = __webpack_require__(7); + var jStat = __webpack_require__(9).jStat; + var utils = __webpack_require__(4); + var error = __webpack_require__(5); + var misc = __webpack_require__(10); + + var SQRT2PI = 2.5066282746310002; + + exports.AVEDEV = function() { + var range = utils.parseNumberArray(utils.flatten(arguments)); + if (range instanceof Error) { + return range; + } + return jStat.sum(jStat(range).subtract(jStat.mean(range)).abs()[0]) / range.length; + }; + + exports.AVERAGE = function() { + var range = utils.numbers(utils.flatten(arguments)); + var n = range.length; + var sum = 0; + var count = 0; + for (var i = 0; i < n; i++) { + sum += range[i]; + count += 1; + } + return sum / count; + }; + + exports.AVERAGEA = function() { + var range = utils.flatten(arguments); + var n = range.length; + var sum = 0; + var count = 0; + for (var i = 0; i < n; i++) { + var el = range[i]; + if (typeof el === 'number') { + sum += el; + } + if (el === true) { + sum++; + } + if (el !== null) { + count++; + } + } + return sum / count; + }; + + exports.AVERAGEIF = function(range, criteria, average_range) { + average_range = average_range || range; + range = utils.flatten(range); + average_range = utils.parseNumberArray(utils.flatten(average_range)); + if (average_range instanceof Error) { + return average_range; + } + var average_count = 0; + var result = 0; + for (var i = 0; i < range.length; i++) { + if (eval(range[i] + criteria)) { // jshint ignore:line + result += average_range[i]; + average_count++; + } + } + return result / average_count; + }; + + exports.AVERAGEIFS = function() { + // Does not work with multi dimensional ranges yet! + //http://office.microsoft.com/en-001/excel-help/averageifs-function-HA010047493.aspx + var args = utils.argsToArray(arguments); + var criteria = (args.length - 1) / 2; + var range = utils.flatten(args[0]); + var count = 0; + var result = 0; + for (var i = 0; i < range.length; i++) { + var condition = ''; + for (var j = 0; j < criteria; j++) { + condition += args[2 * j + 1][i] + args[2 * j + 2]; + if (j !== criteria - 1) { + condition += '&&'; + } + } + if (eval(condition)) { // jshint ignore:line + result += range[i]; + count++; + } + } + + var average = result / count; + if (isNaN(average)) { + return 0; + } else { + return average; + } + }; + + exports.BETA = {}; + + exports.BETA.DIST = function(x, alpha, beta, cumulative, A, B) { + if (arguments.length < 4) { + return error.value; + } + + A = (A === undefined) ? 0 : A; + B = (B === undefined) ? 1 : B; + + x = utils.parseNumber(x); + alpha = utils.parseNumber(alpha); + beta = utils.parseNumber(beta); + A = utils.parseNumber(A); + B = utils.parseNumber(B); + if (utils.anyIsError(x, alpha, beta, A, B)) { + return error.value; + } + + x = (x - A) / (B - A); + return (cumulative) ? jStat.beta.cdf(x, alpha, beta) : jStat.beta.pdf(x, alpha, beta); + }; + + exports.BETA.INV = function(probability, alpha, beta, A, B) { + A = (A === undefined) ? 0 : A; + B = (B === undefined) ? 1 : B; + + probability = utils.parseNumber(probability); + alpha = utils.parseNumber(alpha); + beta = utils.parseNumber(beta); + A = utils.parseNumber(A); + B = utils.parseNumber(B); + if (utils.anyIsError(probability, alpha, beta, A, B)) { + return error.value; + } + + return jStat.beta.inv(probability, alpha, beta) * (B - A) + A; + }; + + exports.BINOM = {}; + + exports.BINOM.DIST = function(successes, trials, probability, cumulative) { + successes = utils.parseNumber(successes); + trials = utils.parseNumber(trials); + probability = utils.parseNumber(probability); + cumulative = utils.parseNumber(cumulative); + if (utils.anyIsError(successes, trials, probability, cumulative)) { + return error.value; + } + return (cumulative) ? jStat.binomial.cdf(successes, trials, probability) : jStat.binomial.pdf(successes, trials, probability); + }; + + exports.BINOM.DIST.RANGE = function(trials, probability, successes, successes2) { + successes2 = (successes2 === undefined) ? successes : successes2; + + trials = utils.parseNumber(trials); + probability = utils.parseNumber(probability); + successes = utils.parseNumber(successes); + successes2 = utils.parseNumber(successes2); + if (utils.anyIsError(trials, probability, successes, successes2)) { + return error.value; + } + + var result = 0; + for (var i = successes; i <= successes2; i++) { + result += mathTrig.COMBIN(trials, i) * Math.pow(probability, i) * Math.pow(1 - probability, trials - i); + } + return result; + }; + + exports.BINOM.INV = function(trials, probability, alpha) { + trials = utils.parseNumber(trials); + probability = utils.parseNumber(probability); + alpha = utils.parseNumber(alpha); + if (utils.anyIsError(trials, probability, alpha)) { + return error.value; + } + + var x = 0; + while (x <= trials) { + if (jStat.binomial.cdf(x, trials, probability) >= alpha) { + return x; + } + x++; + } + }; + + exports.CHISQ = {}; + + exports.CHISQ.DIST = function(x, k, cumulative) { + x = utils.parseNumber(x); + k = utils.parseNumber(k); + if (utils.anyIsError(x, k)) { + return error.value; + } + + return (cumulative) ? jStat.chisquare.cdf(x, k) : jStat.chisquare.pdf(x, k); + }; + + exports.CHISQ.DIST.RT = function(x, k) { + if (!x | !k) { + return error.na; + } + + if (x < 1 || k > Math.pow(10, 10)) { + return error.num; + } + + if ((typeof x !== 'number') || (typeof k !== 'number')) { + return error.value; + } + + return 1 - jStat.chisquare.cdf(x, k); + }; + + exports.CHISQ.INV = function(probability, k) { + probability = utils.parseNumber(probability); + k = utils.parseNumber(k); + if (utils.anyIsError(probability, k)) { + return error.value; + } + return jStat.chisquare.inv(probability, k); + }; + + exports.CHISQ.INV.RT = function(p, k) { + if (!p | !k) { + return error.na; + } + + if (p < 0 || p > 1 || k < 1 || k > Math.pow(10, 10)) { + return error.num; + } + + if ((typeof p !== 'number') || (typeof k !== 'number')) { + return error.value; + } + + return jStat.chisquare.inv(1.0 - p, k); + }; + + exports.CHISQ.TEST = function(observed, expected) { + if (arguments.length !== 2) { + return error.na; + } + + if ((!(observed instanceof Array)) || (!(expected instanceof Array))) { + return error.value; + } + + if (observed.length !== expected.length) { + return error.value; + } + + if (observed[0] && expected[0] && + observed[0].length !== expected[0].length) { + return error.value; + } + + var row = observed.length; + var tmp, i, j; + + // Convert single-dimension array into two-dimension array + for (i = 0; i < row; i ++) { + if (!(observed[i] instanceof Array)) { + tmp = observed[i]; + observed[i] = []; + observed[i].push(tmp); + } + if (!(expected[i] instanceof Array)) { + tmp = expected[i]; + expected[i] = []; + expected[i].push(tmp); + } + } + + var col = observed[0].length; + var dof = (col === 1) ? row-1 : (row-1)*(col-1); + var xsqr = 0; + var Pi =Math.PI; + + for (i = 0; i < row; i ++) { + for (j = 0; j < col; j ++) { + xsqr += Math.pow((observed[i][j] - expected[i][j]), 2) / expected[i][j]; + } + } + + // Get independency by X square and its degree of freedom + function ChiSq(xsqr, dof) { + var p = Math.exp(-0.5 * xsqr); + if((dof%2) === 1) { + p = p * Math.sqrt(2 * xsqr/Pi); + } + var k = dof; + while(k >= 2) { + p = p * xsqr/k; + k = k - 2; + } + var t = p; + var a = dof; + while (t > 0.0000000001*p) { + a = a + 2; + t = t * xsqr/a; + p = p + t; + } + return 1-p; + } + + return Math.round(ChiSq(xsqr, dof) * 1000000) / 1000000; + }; + + exports.COLUMN = function(matrix, index) { + if (arguments.length !== 2) { + return error.na; + } + + if (index < 0) { + return error.num; + } + + if (!(matrix instanceof Array) || (typeof index !== 'number')) { + return error.value; + } + + if (matrix.length === 0) { + return undefined; + } + + return jStat.col(matrix, index); + }; + + exports.COLUMNS = function(matrix) { + if (arguments.length !== 1) { + return error.na; + } + + if (!(matrix instanceof Array)) { + return error.value; + } + + if (matrix.length === 0) { + return 0; + } + + return jStat.cols(matrix); + }; + + exports.CONFIDENCE = {}; + + exports.CONFIDENCE.NORM = function(alpha, sd, n) { + alpha = utils.parseNumber(alpha); + sd = utils.parseNumber(sd); + n = utils.parseNumber(n); + if (utils.anyIsError(alpha, sd, n)) { + return error.value; + } + return jStat.normalci(1, alpha, sd, n)[1] - 1; + }; + + exports.CONFIDENCE.T = function(alpha, sd, n) { + alpha = utils.parseNumber(alpha); + sd = utils.parseNumber(sd); + n = utils.parseNumber(n); + if (utils.anyIsError(alpha, sd, n)) { + return error.value; + } + return jStat.tci(1, alpha, sd, n)[1] - 1; + }; + + exports.CORREL = function(array1, array2) { + array1 = utils.parseNumberArray(utils.flatten(array1)); + array2 = utils.parseNumberArray(utils.flatten(array2)); + if (utils.anyIsError(array1, array2)) { + return error.value; + } + return jStat.corrcoeff(array1, array2); + }; + + exports.COUNT = function() { + return utils.numbers(utils.flatten(arguments)).length; + }; + + exports.COUNTA = function() { + var range = utils.flatten(arguments); + return range.length - exports.COUNTBLANK(range); + }; + + exports.COUNTIN = function (range, value) { + var result = 0; + for (var i = 0; i < range.length; i++) { + if (range[i] === value) { + result++; + } + } + return result; + }; + + + exports.COUNTBLANK = function() { + var range = utils.flatten(arguments); + var blanks = 0; + var element; + for (var i = 0; i < range.length; i++) { + element = range[i]; + if (element === null || element === '') { + blanks++; + } + } + return blanks; + }; + + exports.COUNTIF = function(range, criteria) { + range = utils.flatten(range); + if (!/[<>=!]/.test(criteria)) { + criteria = '=="' + criteria + '"'; + } + var matches = 0; + for (var i = 0; i < range.length; i++) { + if (typeof range[i] !== 'string') { + if (eval(range[i] + criteria)) { // jshint ignore:line + matches++; + } + } else { + if (eval('"' + range[i] + '"' + criteria)) { // jshint ignore:line + matches++; + } + } + } + return matches; + }; + + exports.COUNTIFS = function() { + var args = utils.argsToArray(arguments); + var results = new Array(utils.flatten(args[0]).length); + for (var i = 0; i < results.length; i++) { + results[i] = true; + } + for (i = 0; i < args.length; i += 2) { + var range = utils.flatten(args[i]); + var criteria = args[i + 1]; + if (!/[<>=!]/.test(criteria)) { + criteria = '=="' + criteria + '"'; + } + for (var j = 0; j < range.length; j++) { + if (typeof range[j] !== 'string') { + results[j] = results[j] && eval(range[j] + criteria); // jshint ignore:line + } else { + results[j] = results[j] && eval('"' + range[j] + '"' + criteria); // jshint ignore:line + } + } + } + var result = 0; + for (i = 0; i < results.length; i++) { + if (results[i]) { + result++; + } + } + return result; + }; + + exports.COUNTUNIQUE = function () { + return misc.UNIQUE.apply(null, utils.flatten(arguments)).length; + }; + + exports.COVARIANCE = {}; + + exports.COVARIANCE.P = function(array1, array2) { + array1 = utils.parseNumberArray(utils.flatten(array1)); + array2 = utils.parseNumberArray(utils.flatten(array2)); + if (utils.anyIsError(array1, array2)) { + return error.value; + } + var mean1 = jStat.mean(array1); + var mean2 = jStat.mean(array2); + var result = 0; + var n = array1.length; + for (var i = 0; i < n; i++) { + result += (array1[i] - mean1) * (array2[i] - mean2); + } + return result / n; + }; + + exports.COVARIANCE.S = function(array1, array2) { + array1 = utils.parseNumberArray(utils.flatten(array1)); + array2 = utils.parseNumberArray(utils.flatten(array2)); + if (utils.anyIsError(array1, array2)) { + return error.value; + } + return jStat.covariance(array1, array2); + }; + + exports.DEVSQ = function() { + var range = utils.parseNumberArray(utils.flatten(arguments)); + if (range instanceof Error) { + return range; + } + var mean = jStat.mean(range); + var result = 0; + for (var i = 0; i < range.length; i++) { + result += Math.pow((range[i] - mean), 2); + } + return result; + }; + + exports.EXPON = {}; + + exports.EXPON.DIST = function(x, lambda, cumulative) { + x = utils.parseNumber(x); + lambda = utils.parseNumber(lambda); + if (utils.anyIsError(x, lambda)) { + return error.value; + } + return (cumulative) ? jStat.exponential.cdf(x, lambda) : jStat.exponential.pdf(x, lambda); + }; + + exports.F = {}; + + exports.F.DIST = function(x, d1, d2, cumulative) { + x = utils.parseNumber(x); + d1 = utils.parseNumber(d1); + d2 = utils.parseNumber(d2); + if (utils.anyIsError(x, d1, d2)) { + return error.value; + } + return (cumulative) ? jStat.centralF.cdf(x, d1, d2) : jStat.centralF.pdf(x, d1, d2); + }; + + exports.F.DIST.RT = function(x, d1, d2) { + if (arguments.length !== 3) { + return error.na; + } + + if (x < 0 || d1 < 1 || d2 < 1) { + return error.num; + } + + if ((typeof x !== 'number') || (typeof d1 !== 'number') || (typeof d2 !== 'number')) { + return error.value; + } + + return 1 - jStat.centralF.cdf(x, d1, d2); + }; + + exports.F.INV = function(probability, d1, d2) { + probability = utils.parseNumber(probability); + d1 = utils.parseNumber(d1); + d2 = utils.parseNumber(d2); + if (utils.anyIsError(probability, d1, d2)) { + return error.value; + } + if (probability <= 0.0 || probability > 1.0) { + return error.num; + } + + return jStat.centralF.inv(probability, d1, d2); + }; + + exports.F.INV.RT = function(p, d1, d2) { + if (arguments.length !== 3) { + return error.na; + } + + if (p < 0 || p > 1 || d1 < 1 || d1 > Math.pow(10, 10) || d2 < 1 || d2 > Math.pow(10, 10)) { + return error.num; + } + + if ((typeof p !== 'number') || (typeof d1 !== 'number') || (typeof d2 !== 'number')) { + return error.value; + } + + return jStat.centralF.inv(1.0 - p, d1, d2); + }; + + exports.F.TEST = function(array1, array2) { + if (!array1 || !array2) { + return error.na; + } + + if (!(array1 instanceof Array) || !(array2 instanceof Array)) { + return error.na; + } + + if (array1.length < 2 || array2.length < 2) { + return error.div0; + } + + var sumOfSquares = function(values, x1) { + var sum = 0; + for (var i = 0; i < values.length; i++) { + sum +=Math.pow((values[i] - x1), 2); + } + return sum; + }; + + var x1 = mathTrig.SUM(array1) / array1.length; + var x2 = mathTrig.SUM(array2) / array2.length; + var sum1 = sumOfSquares(array1, x1) / (array1.length - 1); + var sum2 = sumOfSquares(array2, x2) / (array2.length - 1); + + return sum1 / sum2; + }; + + exports.FISHER = function(x) { + x = utils.parseNumber(x); + if (x instanceof Error) { + return x; + } + return Math.log((1 + x) / (1 - x)) / 2; + }; + + exports.FISHERINV = function(y) { + y = utils.parseNumber(y); + if (y instanceof Error) { + return y; + } + var e2y = Math.exp(2 * y); + return (e2y - 1) / (e2y + 1); + }; + + exports.FORECAST = function(x, data_y, data_x) { + x = utils.parseNumber(x); + data_y = utils.parseNumberArray(utils.flatten(data_y)); + data_x = utils.parseNumberArray(utils.flatten(data_x)); + if (utils.anyIsError(x, data_y, data_x)) { + return error.value; + } + var xmean = jStat.mean(data_x); + var ymean = jStat.mean(data_y); + var n = data_x.length; + var num = 0; + var den = 0; + for (var i = 0; i < n; i++) { + num += (data_x[i] - xmean) * (data_y[i] - ymean); + den += Math.pow(data_x[i] - xmean, 2); + } + var b = num / den; + var a = ymean - b * xmean; + return a + b * x; + }; + + exports.FREQUENCY = function(data, bins) { + data = utils.parseNumberArray(utils.flatten(data)); + bins = utils.parseNumberArray(utils.flatten(bins)); + if (utils.anyIsError(data, bins)) { + return error.value; + } + var n = data.length; + var b = bins.length; + var r = []; + for (var i = 0; i <= b; i++) { + r[i] = 0; + for (var j = 0; j < n; j++) { + if (i === 0) { + if (data[j] <= bins[0]) { + r[0] += 1; + } + } else if (i < b) { + if (data[j] > bins[i - 1] && data[j] <= bins[i]) { + r[i] += 1; + } + } else if (i === b) { + if (data[j] > bins[b - 1]) { + r[b] += 1; + } + } + } + } + return r; + }; + + + exports.GAMMA = function(number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + + if (number === 0) { + return error.num; + } + + if (parseInt(number, 10) === number && number < 0) { + return error.num; + } + + return jStat.gammafn(number); + }; + + exports.GAMMA.DIST = function(value, alpha, beta, cumulative) { + if (arguments.length !== 4) { + return error.na; + } + + if (value < 0 || alpha <= 0 || beta <= 0) { + return error.value; + } + + if ((typeof value !== 'number') || (typeof alpha !== 'number') || (typeof beta !== 'number')) { + return error.value; + } + + return cumulative ? jStat.gamma.cdf(value, alpha, beta, true) : jStat.gamma.pdf(value, alpha, beta, false); + }; + + exports.GAMMA.INV = function(probability, alpha, beta) { + if (arguments.length !== 3) { + return error.na; + } + + if (probability < 0 || probability > 1 || alpha <= 0 || beta <= 0) { + return error.num; + } + + if ((typeof probability !== 'number') || (typeof alpha !== 'number') || (typeof beta !== 'number')) { + return error.value; + } + + return jStat.gamma.inv(probability, alpha, beta); + }; + + exports.GAMMALN = function(number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + return jStat.gammaln(number); + }; + + exports.GAMMALN.PRECISE = function(x) { + if (arguments.length !== 1) { + return error.na; + } + + if (x <= 0) { + return error.num; + } + + if (typeof x !== 'number') { + return error.value; + } + + return jStat.gammaln(x); + }; + + exports.GAUSS = function(z) { + z = utils.parseNumber(z); + if (z instanceof Error) { + return z; + } + return jStat.normal.cdf(z, 0, 1) - 0.5; + }; + + exports.GEOMEAN = function() { + var args = utils.parseNumberArray(utils.flatten(arguments)); + if (args instanceof Error) { + return args; + } + return jStat.geomean(args); + }; + + exports.GROWTH = function(known_y, known_x, new_x, use_const) { + // Credits: Ilmari Karonen (http://stackoverflow.com/questions/14161990/how-to-implement-growth-function-in-javascript) + + known_y = utils.parseNumberArray(known_y); + if (known_y instanceof Error) { + return known_y; + } + + // Default values for optional parameters: + var i; + if (known_x === undefined) { + known_x = []; + for (i = 1; i <= known_y.length; i++) { + known_x.push(i); + } + } + if (new_x === undefined) { + new_x = []; + for (i = 1; i <= known_y.length; i++) { + new_x.push(i); + } + } + + known_x = utils.parseNumberArray(known_x); + new_x = utils.parseNumberArray(new_x); + if (utils.anyIsError(known_x, new_x)) { + return error.value; + } + + + if (use_const === undefined) { + use_const = true; + } + + // Calculate sums over the data: + var n = known_y.length; + var avg_x = 0; + var avg_y = 0; + var avg_xy = 0; + var avg_xx = 0; + for (i = 0; i < n; i++) { + var x = known_x[i]; + var y = Math.log(known_y[i]); + avg_x += x; + avg_y += y; + avg_xy += x * y; + avg_xx += x * x; + } + avg_x /= n; + avg_y /= n; + avg_xy /= n; + avg_xx /= n; + + // Compute linear regression coefficients: + var beta; + var alpha; + if (use_const) { + beta = (avg_xy - avg_x * avg_y) / (avg_xx - avg_x * avg_x); + alpha = avg_y - beta * avg_x; + } else { + beta = avg_xy / avg_xx; + alpha = 0; + } + + // Compute and return result array: + var new_y = []; + for (i = 0; i < new_x.length; i++) { + new_y.push(Math.exp(alpha + beta * new_x[i])); + } + return new_y; + }; + + exports.HARMEAN = function() { + var range = utils.parseNumberArray(utils.flatten(arguments)); + if (range instanceof Error) { + return range; + } + var n = range.length; + var den = 0; + for (var i = 0; i < n; i++) { + den += 1 / range[i]; + } + return n / den; + }; + + exports.HYPGEOM = {}; + + exports.HYPGEOM.DIST = function(x, n, M, N, cumulative) { + x = utils.parseNumber(x); + n = utils.parseNumber(n); + M = utils.parseNumber(M); + N = utils.parseNumber(N); + if (utils.anyIsError(x, n, M, N)) { + return error.value; + } + + function pdf(x, n, M, N) { + return mathTrig.COMBIN(M, x) * mathTrig.COMBIN(N - M, n - x) / mathTrig.COMBIN(N, n); + } + + function cdf(x, n, M, N) { + var result = 0; + for (var i = 0; i <= x; i++) { + result += pdf(i, n, M, N); + } + return result; + } + + return (cumulative) ? cdf(x, n, M, N) : pdf(x, n, M, N); + }; + + exports.INTERCEPT = function(known_y, known_x) { + known_y = utils.parseNumberArray(known_y); + known_x = utils.parseNumberArray(known_x); + if (utils.anyIsError(known_y, known_x)) { + return error.value; + } + if (known_y.length !== known_x.length) { + return error.na; + } + return exports.FORECAST(0, known_y, known_x); + }; + + exports.KURT = function() { + var range = utils.parseNumberArray(utils.flatten(arguments)); + if (range instanceof Error) { + return range; + } + var mean = jStat.mean(range); + var n = range.length; + var sigma = 0; + for (var i = 0; i < n; i++) { + sigma += Math.pow(range[i] - mean, 4); + } + sigma = sigma / Math.pow(jStat.stdev(range, true), 4); + return ((n * (n + 1)) / ((n - 1) * (n - 2) * (n - 3))) * sigma - 3 * (n - 1) * (n - 1) / ((n - 2) * (n - 3)); + }; + + exports.LARGE = function(range, k) { + range = utils.parseNumberArray(utils.flatten(range)); + k = utils.parseNumber(k); + if (utils.anyIsError(range, k)) { + return range; + } + return range.sort(function(a, b) { + return b - a; + })[k - 1]; + }; + + exports.LINEST = function(data_y, data_x) { + data_y = utils.parseNumberArray(utils.flatten(data_y)); + data_x = utils.parseNumberArray(utils.flatten(data_x)); + if (utils.anyIsError(data_y, data_x)) { + return error.value; + } + var ymean = jStat.mean(data_y); + var xmean = jStat.mean(data_x); + var n = data_x.length; + var num = 0; + var den = 0; + for (var i = 0; i < n; i++) { + num += (data_x[i] - xmean) * (data_y[i] - ymean); + den += Math.pow(data_x[i] - xmean, 2); + } + var m = num / den; + var b = ymean - m * xmean; + return [m, b]; + }; + + // According to Microsoft: + // http://office.microsoft.com/en-us/starter-help/logest-function-HP010342665.aspx + // LOGEST returns are based on the following linear model: + // ln y = x1 ln m1 + ... + xn ln mn + ln b + exports.LOGEST = function(data_y, data_x) { + data_y = utils.parseNumberArray(utils.flatten(data_y)); + data_x = utils.parseNumberArray(utils.flatten(data_x)); + if (utils.anyIsError(data_y, data_x)) { + return error.value; + } + for (var i = 0; i < data_y.length; i ++) { + data_y[i] = Math.log(data_y[i]); + } + + var result = exports.LINEST(data_y, data_x); + result[0] = Math.round(Math.exp(result[0])*1000000)/1000000; + result[1] = Math.round(Math.exp(result[1])*1000000)/1000000; + return result; + }; + + exports.LOGNORM = {}; + + exports.LOGNORM.DIST = function(x, mean, sd, cumulative) { + x = utils.parseNumber(x); + mean = utils.parseNumber(mean); + sd = utils.parseNumber(sd); + if (utils.anyIsError(x, mean, sd)) { + return error.value; + } + return (cumulative) ? jStat.lognormal.cdf(x, mean, sd) : jStat.lognormal.pdf(x, mean, sd); + }; + + exports.LOGNORM.INV = function(probability, mean, sd) { + probability = utils.parseNumber(probability); + mean = utils.parseNumber(mean); + sd = utils.parseNumber(sd); + if (utils.anyIsError(probability, mean, sd)) { + return error.value; + } + return jStat.lognormal.inv(probability, mean, sd); + }; + + exports.MAX = function() { + var range = utils.numbers(utils.flatten(arguments)); + return (range.length === 0) ? 0 : Math.max.apply(Math, range); + }; + + exports.MAXA = function() { + var range = utils.arrayValuesToNumbers(utils.flatten(arguments)); + return (range.length === 0) ? 0 : Math.max.apply(Math, range); + }; + + exports.MEDIAN = function() { + var range = utils.arrayValuesToNumbers(utils.flatten(arguments)); + return jStat.median(range); + }; + + exports.MIN = function() { + var range = utils.numbers(utils.flatten(arguments)); + return (range.length === 0) ? 0 : Math.min.apply(Math, range); + }; + + exports.MINA = function() { + var range = utils.arrayValuesToNumbers(utils.flatten(arguments)); + return (range.length === 0) ? 0 : Math.min.apply(Math, range); + }; + + exports.MODE = {}; + + exports.MODE.MULT = function() { + // Credits: Roönaän + var range = utils.parseNumberArray(utils.flatten(arguments)); + if (range instanceof Error) { + return range; + } + var n = range.length; + var count = {}; + var maxItems = []; + var max = 0; + var currentItem; + + for (var i = 0; i < n; i++) { + currentItem = range[i]; + count[currentItem] = count[currentItem] ? count[currentItem] + 1 : 1; + if (count[currentItem] > max) { + max = count[currentItem]; + maxItems = []; + } + if (count[currentItem] === max) { + maxItems[maxItems.length] = currentItem; + } + } + return maxItems; + }; + + exports.MODE.SNGL = function() { + var range = utils.parseNumberArray(utils.flatten(arguments)); + if (range instanceof Error) { + return range; + } + return exports.MODE.MULT(range).sort(function(a, b) { + return a - b; + })[0]; + }; + + exports.NEGBINOM = {}; + + exports.NEGBINOM.DIST = function(k, r, p, cumulative) { + k = utils.parseNumber(k); + r = utils.parseNumber(r); + p = utils.parseNumber(p); + if (utils.anyIsError(k, r, p)) { + return error.value; + } + return (cumulative) ? jStat.negbin.cdf(k, r, p) : jStat.negbin.pdf(k, r, p); + }; + + exports.NORM = {}; + + exports.NORM.DIST = function(x, mean, sd, cumulative) { + x = utils.parseNumber(x); + mean = utils.parseNumber(mean); + sd = utils.parseNumber(sd); + if (utils.anyIsError(x, mean, sd)) { + return error.value; + } + if (sd <= 0) { + return error.num; + } + + // Return normal distribution computed by jStat [http://jstat.org] + return (cumulative) ? jStat.normal.cdf(x, mean, sd) : jStat.normal.pdf(x, mean, sd); + }; + + exports.NORM.INV = function(probability, mean, sd) { + probability = utils.parseNumber(probability); + mean = utils.parseNumber(mean); + sd = utils.parseNumber(sd); + if (utils.anyIsError(probability, mean, sd)) { + return error.value; + } + return jStat.normal.inv(probability, mean, sd); + }; + + exports.NORM.S = {}; + + exports.NORM.S.DIST = function(z, cumulative) { + z = utils.parseNumber(z); + if (z instanceof Error) { + return error.value; + } + return (cumulative) ? jStat.normal.cdf(z, 0, 1) : jStat.normal.pdf(z, 0, 1); + }; + + exports.NORM.S.INV = function(probability) { + probability = utils.parseNumber(probability); + if (probability instanceof Error) { + return error.value; + } + return jStat.normal.inv(probability, 0, 1); + }; + + exports.PEARSON = function(data_x, data_y) { + data_y = utils.parseNumberArray(utils.flatten(data_y)); + data_x = utils.parseNumberArray(utils.flatten(data_x)); + if (utils.anyIsError(data_y, data_x)) { + return error.value; + } + var xmean = jStat.mean(data_x); + var ymean = jStat.mean(data_y); + var n = data_x.length; + var num = 0; + var den1 = 0; + var den2 = 0; + for (var i = 0; i < n; i++) { + num += (data_x[i] - xmean) * (data_y[i] - ymean); + den1 += Math.pow(data_x[i] - xmean, 2); + den2 += Math.pow(data_y[i] - ymean, 2); + } + return num / Math.sqrt(den1 * den2); + }; + + exports.PERCENTILE = {}; + + exports.PERCENTILE.EXC = function(array, k) { + array = utils.parseNumberArray(utils.flatten(array)); + k = utils.parseNumber(k); + if (utils.anyIsError(array, k)) { + return error.value; + } + array = array.sort(function(a, b) { + { + return a - b; + } + }); + var n = array.length; + if (k < 1 / (n + 1) || k > 1 - 1 / (n + 1)) { + return error.num; + } + var l = k * (n + 1) - 1; + var fl = Math.floor(l); + return utils.cleanFloat((l === fl) ? array[l] : array[fl] + (l - fl) * (array[fl + 1] - array[fl])); + }; + + exports.PERCENTILE.INC = function(array, k) { + array = utils.parseNumberArray(utils.flatten(array)); + k = utils.parseNumber(k); + if (utils.anyIsError(array, k)) { + return error.value; + } + array = array.sort(function(a, b) { + return a - b; + }); + var n = array.length; + var l = k * (n - 1); + var fl = Math.floor(l); + return utils.cleanFloat((l === fl) ? array[l] : array[fl] + (l - fl) * (array[fl + 1] - array[fl])); + }; + + exports.PERCENTRANK = {}; + + exports.PERCENTRANK.EXC = function(array, x, significance) { + significance = (significance === undefined) ? 3 : significance; + array = utils.parseNumberArray(utils.flatten(array)); + x = utils.parseNumber(x); + significance = utils.parseNumber(significance); + if (utils.anyIsError(array, x, significance)) { + return error.value; + } + array = array.sort(function(a, b) { + return a - b; + }); + var uniques = misc.UNIQUE.apply(null, array); + var n = array.length; + var m = uniques.length; + var power = Math.pow(10, significance); + var result = 0; + var match = false; + var i = 0; + while (!match && i < m) { + if (x === uniques[i]) { + result = (array.indexOf(uniques[i]) + 1) / (n + 1); + match = true; + } else if (x >= uniques[i] && (x < uniques[i + 1] || i === m - 1)) { + result = (array.indexOf(uniques[i]) + 1 + (x - uniques[i]) / (uniques[i + 1] - uniques[i])) / (n + 1); + match = true; + } + i++; + } + return Math.floor(result * power) / power; + }; + + exports.PERCENTRANK.INC = function(array, x, significance) { + significance = (significance === undefined) ? 3 : significance; + array = utils.parseNumberArray(utils.flatten(array)); + x = utils.parseNumber(x); + significance = utils.parseNumber(significance); + if (utils.anyIsError(array, x, significance)) { + return error.value; + } + array = array.sort(function(a, b) { + return a - b; + }); + var uniques = misc.UNIQUE.apply(null, array); + var n = array.length; + var m = uniques.length; + var power = Math.pow(10, significance); + var result = 0; + var match = false; + var i = 0; + while (!match && i < m) { + if (x === uniques[i]) { + result = array.indexOf(uniques[i]) / (n - 1); + match = true; + } else if (x >= uniques[i] && (x < uniques[i + 1] || i === m - 1)) { + result = (array.indexOf(uniques[i]) + (x - uniques[i]) / (uniques[i + 1] - uniques[i])) / (n - 1); + match = true; + } + i++; + } + return Math.floor(result * power) / power; + }; + + exports.PERMUT = function(number, number_chosen) { + number = utils.parseNumber(number); + number_chosen = utils.parseNumber(number_chosen); + if (utils.anyIsError(number, number_chosen)) { + return error.value; + } + return mathTrig.FACT(number) / mathTrig.FACT(number - number_chosen); + }; + + exports.PERMUTATIONA = function(number, number_chosen) { + number = utils.parseNumber(number); + number_chosen = utils.parseNumber(number_chosen); + if (utils.anyIsError(number, number_chosen)) { + return error.value; + } + return Math.pow(number, number_chosen); + }; + + exports.PHI = function(x) { + x = utils.parseNumber(x); + if (x instanceof Error) { + return error.value; + } + return Math.exp(-0.5 * x * x) / SQRT2PI; + }; + + exports.POISSON = {}; + + exports.POISSON.DIST = function(x, mean, cumulative) { + x = utils.parseNumber(x); + mean = utils.parseNumber(mean); + if (utils.anyIsError(x, mean)) { + return error.value; + } + return (cumulative) ? jStat.poisson.cdf(x, mean) : jStat.poisson.pdf(x, mean); + }; + + exports.PROB = function(range, probability, lower, upper) { + if (lower === undefined) { + return 0; + } + upper = (upper === undefined) ? lower : upper; + + range = utils.parseNumberArray(utils.flatten(range)); + probability = utils.parseNumberArray(utils.flatten(probability)); + lower = utils.parseNumber(lower); + upper = utils.parseNumber(upper); + if (utils.anyIsError(range, probability, lower, upper)) { + return error.value; + } + + if (lower === upper) { + return (range.indexOf(lower) >= 0) ? probability[range.indexOf(lower)] : 0; + } + + var sorted = range.sort(function(a, b) { + return a - b; + }); + var n = sorted.length; + var result = 0; + for (var i = 0; i < n; i++) { + if (sorted[i] >= lower && sorted[i] <= upper) { + result += probability[range.indexOf(sorted[i])]; + } + } + return result; + }; + + exports.QUARTILE = {}; + + exports.QUARTILE.EXC = function(range, quart) { + range = utils.parseNumberArray(utils.flatten(range)); + quart = utils.parseNumber(quart); + if (utils.anyIsError(range, quart)) { + return error.value; + } + switch (quart) { + case 1: + return exports.PERCENTILE.EXC(range, 0.25); + case 2: + return exports.PERCENTILE.EXC(range, 0.5); + case 3: + return exports.PERCENTILE.EXC(range, 0.75); + default: + return error.num; + } + }; + + exports.QUARTILE.INC = function(range, quart) { + range = utils.parseNumberArray(utils.flatten(range)); + quart = utils.parseNumber(quart); + if (utils.anyIsError(range, quart)) { + return error.value; + } + switch (quart) { + case 1: + return exports.PERCENTILE.INC(range, 0.25); + case 2: + return exports.PERCENTILE.INC(range, 0.5); + case 3: + return exports.PERCENTILE.INC(range, 0.75); + default: + return error.num; + } + }; + + exports.RANK = {}; + + exports.RANK.AVG = function(number, range, order) { + number = utils.parseNumber(number); + range = utils.parseNumberArray(utils.flatten(range)); + if (utils.anyIsError(number, range)) { + return error.value; + } + range = utils.flatten(range); + order = order || false; + var sort = (order) ? function(a, b) { + return a - b; + } : function(a, b) { + return b - a; + }; + range = range.sort(sort); + + var length = range.length; + var count = 0; + for (var i = 0; i < length; i++) { + if (range[i] === number) { + count++; + } + } + + return (count > 1) ? (2 * range.indexOf(number) + count + 1) / 2 : range.indexOf(number) + 1; + }; + + exports.RANK.EQ = function(number, range, order) { + number = utils.parseNumber(number); + range = utils.parseNumberArray(utils.flatten(range)); + if (utils.anyIsError(number, range)) { + return error.value; + } + order = order || false; + var sort = (order) ? function(a, b) { + return a - b; + } : function(a, b) { + return b - a; + }; + range = range.sort(sort); + return range.indexOf(number) + 1; + }; + + exports.ROW = function(matrix, index) { + if (arguments.length !== 2) { + return error.na; + } + + if (index < 0) { + return error.num; + } + + if (!(matrix instanceof Array) || (typeof index !== 'number')) { + return error.value; + } + + if (matrix.length === 0) { + return undefined; + } + + return jStat.row(matrix, index); + }; + + exports.ROWS = function(matrix) { + if (arguments.length !== 1) { + return error.na; + } + + if (!(matrix instanceof Array)) { + return error.value; + } + + if (matrix.length === 0) { + return 0; + } + + return jStat.rows(matrix); + }; + + exports.RSQ = function(data_x, data_y) { // no need to flatten here, PEARSON will take care of that + data_x = utils.parseNumberArray(utils.flatten(data_x)); + data_y = utils.parseNumberArray(utils.flatten(data_y)); + if (utils.anyIsError(data_x, data_y)) { + return error.value; + } + return Math.pow(exports.PEARSON(data_x, data_y), 2); + }; + + exports.SKEW = function() { + var range = utils.parseNumberArray(utils.flatten(arguments)); + if (range instanceof Error) { + return range; + } + var mean = jStat.mean(range); + var n = range.length; + var sigma = 0; + for (var i = 0; i < n; i++) { + sigma += Math.pow(range[i] - mean, 3); + } + return n * sigma / ((n - 1) * (n - 2) * Math.pow(jStat.stdev(range, true), 3)); + }; + + exports.SKEW.P = function() { + var range = utils.parseNumberArray(utils.flatten(arguments)); + if (range instanceof Error) { + return range; + } + var mean = jStat.mean(range); + var n = range.length; + var m2 = 0; + var m3 = 0; + for (var i = 0; i < n; i++) { + m3 += Math.pow(range[i] - mean, 3); + m2 += Math.pow(range[i] - mean, 2); + } + m3 = m3 / n; + m2 = m2 / n; + return m3 / Math.pow(m2, 3 / 2); + }; + + exports.SLOPE = function(data_y, data_x) { + data_y = utils.parseNumberArray(utils.flatten(data_y)); + data_x = utils.parseNumberArray(utils.flatten(data_x)); + if (utils.anyIsError(data_y, data_x)) { + return error.value; + } + var xmean = jStat.mean(data_x); + var ymean = jStat.mean(data_y); + var n = data_x.length; + var num = 0; + var den = 0; + for (var i = 0; i < n; i++) { + num += (data_x[i] - xmean) * (data_y[i] - ymean); + den += Math.pow(data_x[i] - xmean, 2); + } + return num / den; + }; + + exports.SMALL = function(range, k) { + range = utils.parseNumberArray(utils.flatten(range)); + k = utils.parseNumber(k); + if (utils.anyIsError(range, k)) { + return range; + } + return range.sort(function(a, b) { + return a - b; + })[k - 1]; + }; + + exports.STANDARDIZE = function(x, mean, sd) { + x = utils.parseNumber(x); + mean = utils.parseNumber(mean); + sd = utils.parseNumber(sd); + if (utils.anyIsError(x, mean, sd)) { + return error.value; + } + return (x - mean) / sd; + }; + + exports.STDEV = {}; + + exports.STDEV.P = function() { + var v = exports.VAR.P.apply(this, arguments); + return Math.sqrt(v); + }; + + exports.STDEV.S = function() { + var v = exports.VAR.S.apply(this, arguments); + return Math.sqrt(v); + }; + + exports.STDEVA = function() { + var v = exports.VARA.apply(this, arguments); + return Math.sqrt(v); + }; + + exports.STDEVPA = function() { + var v = exports.VARPA.apply(this, arguments); + return Math.sqrt(v); + }; + + + exports.STEYX = function(data_y, data_x) { + data_y = utils.parseNumberArray(utils.flatten(data_y)); + data_x = utils.parseNumberArray(utils.flatten(data_x)); + if (utils.anyIsError(data_y, data_x)) { + return error.value; + } + var xmean = jStat.mean(data_x); + var ymean = jStat.mean(data_y); + var n = data_x.length; + var lft = 0; + var num = 0; + var den = 0; + for (var i = 0; i < n; i++) { + lft += Math.pow(data_y[i] - ymean, 2); + num += (data_x[i] - xmean) * (data_y[i] - ymean); + den += Math.pow(data_x[i] - xmean, 2); + } + return Math.sqrt((lft - num * num / den) / (n - 2)); + }; + + exports.TRANSPOSE = function(matrix) { + if (!matrix) { + return error.na; + } + return jStat.transpose(matrix); + }; + + exports.T = text.T; + + exports.T.DIST = function(x, df, cumulative) { + x = utils.parseNumber(x); + df = utils.parseNumber(df); + if (utils.anyIsError(x, df)) { + return error.value; + } + return (cumulative) ? jStat.studentt.cdf(x, df) : jStat.studentt.pdf(x, df); + }; + + exports.T.DIST['2T'] = function(x, df) { + if (arguments.length !== 2) { + return error.na; + } + + if (x < 0 || df < 1) { + return error.num; + } + + if ((typeof x !== 'number') || (typeof df !== 'number')) { + return error.value; + } + + return (1 - jStat.studentt.cdf(x , df)) * 2; + }; + + exports.T.DIST.RT = function(x, df) { + if (arguments.length !== 2) { + return error.na; + } + + if (x < 0 || df < 1) { + return error.num; + } + + if ((typeof x !== 'number') || (typeof df !== 'number')) { + return error.value; + } + + return 1 - jStat.studentt.cdf(x , df); + }; + + exports.T.INV = function(probability, df) { + probability = utils.parseNumber(probability); + df = utils.parseNumber(df); + if (utils.anyIsError(probability, df)) { + return error.value; + } + return jStat.studentt.inv(probability, df); + }; + + exports.T.INV['2T'] = function(probability, df) { + probability = utils.parseNumber(probability); + df = utils.parseNumber(df); + if (probability <= 0 || probability > 1 || df < 1) { + return error.num; + } + if (utils.anyIsError(probability, df)) { + return error.value; + } + return Math.abs(jStat.studentt.inv(probability/2, df)); + }; + + // The algorithm can be found here: + // http://www.chem.uoa.gr/applets/AppletTtest/Appl_Ttest2.html + exports.T.TEST = function(data_x, data_y) { + data_x = utils.parseNumberArray(utils.flatten(data_x)); + data_y = utils.parseNumberArray(utils.flatten(data_y)); + if (utils.anyIsError(data_x, data_y)) { + return error.value; + } + + var mean_x = jStat.mean(data_x); + var mean_y = jStat.mean(data_y); + var s_x = 0; + var s_y = 0; + var i; + + for (i = 0; i < data_x.length; i++) { + s_x += Math.pow(data_x[i] - mean_x, 2); + } + for (i = 0; i < data_y.length; i++) { + s_y += Math.pow(data_y[i] - mean_y, 2); + } + + s_x = s_x / (data_x.length-1); + s_y = s_y / (data_y.length-1); + + var t = Math.abs(mean_x - mean_y) / Math.sqrt(s_x/data_x.length + s_y/data_y.length); + + return exports.T.DIST['2T'](t, data_x.length+data_y.length-2); + }; + + exports.TREND = function(data_y, data_x, new_data_x) { + data_y = utils.parseNumberArray(utils.flatten(data_y)); + data_x = utils.parseNumberArray(utils.flatten(data_x)); + new_data_x = utils.parseNumberArray(utils.flatten(new_data_x)); + if (utils.anyIsError(data_y, data_x, new_data_x)) { + return error.value; + } + var linest = exports.LINEST(data_y, data_x); + var m = linest[0]; + var b = linest[1]; + var result = []; + + new_data_x.forEach(function(x) { + result.push(m * x + b); + }); + + return result; + }; + + exports.TRIMMEAN = function(range, percent) { + range = utils.parseNumberArray(utils.flatten(range)); + percent = utils.parseNumber(percent); + if (utils.anyIsError(range, percent)) { + return error.value; + } + var trim = mathTrig.FLOOR(range.length * percent, 2) / 2; + return jStat.mean(utils.initial(utils.rest(range.sort(function(a, b) { + return a - b; + }), trim), trim)); + }; + + exports.VAR = {}; + + exports.VAR.P = function() { + var range = utils.numbers(utils.flatten(arguments)); + var n = range.length; + var sigma = 0; + var mean = exports.AVERAGE(range); + for (var i = 0; i < n; i++) { + sigma += Math.pow(range[i] - mean, 2); + } + return sigma / n; + }; + + exports.VAR.S = function() { + var range = utils.numbers(utils.flatten(arguments)); + var n = range.length; + var sigma = 0; + var mean = exports.AVERAGE(range); + for (var i = 0; i < n; i++) { + sigma += Math.pow(range[i] - mean, 2); + } + return sigma / (n - 1); + }; + + exports.VARA = function() { + var range = utils.flatten(arguments); + var n = range.length; + var sigma = 0; + var count = 0; + var mean = exports.AVERAGEA(range); + for (var i = 0; i < n; i++) { + var el = range[i]; + if (typeof el === 'number') { + sigma += Math.pow(el - mean, 2); + } else if (el === true) { + sigma += Math.pow(1 - mean, 2); + } else { + sigma += Math.pow(0 - mean, 2); + } + + if (el !== null) { + count++; + } + } + return sigma / (count - 1); + }; + + exports.VARPA = function() { + var range = utils.flatten(arguments); + var n = range.length; + var sigma = 0; + var count = 0; + var mean = exports.AVERAGEA(range); + for (var i = 0; i < n; i++) { + var el = range[i]; + if (typeof el === 'number') { + sigma += Math.pow(el - mean, 2); + } else if (el === true) { + sigma += Math.pow(1 - mean, 2); + } else { + sigma += Math.pow(0 - mean, 2); + } + + if (el !== null) { + count++; + } + } + return sigma / count; + }; + + exports.WEIBULL = {}; + + exports.WEIBULL.DIST = function(x, alpha, beta, cumulative) { + x = utils.parseNumber(x); + alpha = utils.parseNumber(alpha); + beta = utils.parseNumber(beta); + if (utils.anyIsError(x, alpha, beta)) { + return error.value; + } + return (cumulative) ? 1 - Math.exp(-Math.pow(x / beta, alpha)) : Math.pow(x, alpha - 1) * Math.exp(-Math.pow(x / beta, alpha)) * alpha / Math.pow(beta, alpha); + }; + + exports.Z = {}; + + exports.Z.TEST = function(range, x, sd) { + range = utils.parseNumberArray(utils.flatten(range)); + x = utils.parseNumber(x); + if (utils.anyIsError(range, x)) { + return error.value; + } + + sd = sd || exports.STDEV.S(range); + var n = range.length; + return 1 - exports.NORM.S.DIST((exports.AVERAGE(range) - x) / (sd / Math.sqrt(n)), true); + }; + + +/***/ }, +/* 7 */ +/***/ function(module, exports, __webpack_require__) { + + var utils = __webpack_require__(4); + var error = __webpack_require__(5); + var numeral = __webpack_require__(8); + + //TODO + exports.ASC = function() { + throw new Error('ASC is not implemented'); + }; + + //TODO + exports.BAHTTEXT = function() { + throw new Error('BAHTTEXT is not implemented'); + }; + + exports.CHAR = function(number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + return String.fromCharCode(number); + }; + + exports.CLEAN = function(text) { + text = text || ''; + var re = /[\0-\x1F]/g; + return text.replace(re, ""); + }; + + exports.CODE = function(text) { + text = text || ''; + return text.charCodeAt(0); + }; + + exports.CONCATENATE = function() { + var args = utils.flatten(arguments); + + var trueFound = 0; + while ((trueFound = args.indexOf(true)) > -1) { + args[trueFound] = 'TRUE'; + } + + var falseFound = 0; + while ((falseFound = args.indexOf(false)) > -1) { + args[falseFound] = 'FALSE'; + } + + return args.join(''); + }; + + //TODO + exports.DBCS = function() { + throw new Error('DBCS is not implemented'); + }; + + exports.DOLLAR = function(number, decimals) { + decimals = (decimals === undefined) ? 2 : decimals; + + number = utils.parseNumber(number); + decimals = utils.parseNumber(decimals); + if (utils.anyIsError(number, decimals)) { + return error.value; + } + var format = ''; + if (decimals <= 0) { + number = Math.round(number * Math.pow(10, decimals)) / Math.pow(10, decimals); + format = '($0,0)'; + } else if (decimals > 0) { + format = '($0,0.' + new Array(decimals + 1).join('0') + ')'; + } + return numeral(number).format(format); + }; + + exports.EXACT = function(text1, text2) { + return text1 === text2; + }; + + exports.FIND = function(find_text, within_text, position) { + position = (position === undefined) ? 0 : position; + return within_text ? within_text.indexOf(find_text, position - 1) + 1 : null; + }; + + exports.FIXED = function(number, decimals, no_commas) { + decimals = (decimals === undefined) ? 2 : decimals; + no_commas = (no_commas === undefined) ? false : no_commas; + + number = utils.parseNumber(number); + decimals = utils.parseNumber(decimals); + if (utils.anyIsError(number, decimals)) { + return error.value; + } + + var format = no_commas ? '0' : '0,0'; + if (decimals <= 0) { + number = Math.round(number * Math.pow(10, decimals)) / Math.pow(10, decimals); + } else if (decimals > 0) { + format += '.' + new Array(decimals + 1).join('0'); + } + return numeral(number).format(format); + }; + + exports.HTML2TEXT = function (value) { + var result = ''; + + if (value) { + if (value instanceof Array) { + value.forEach(function (line) { + if (result !== '') { + result += '\n'; + } + result += (line.replace(/<(?:.|\n)*?>/gm, '')); + }); + } else { + result = value.replace(/<(?:.|\n)*?>/gm, ''); + } + } + + return result; + }; + + exports.LEFT = function(text, number) { + number = (number === undefined) ? 1 : number; + number = utils.parseNumber(number); + if (number instanceof Error || typeof text !== 'string') { + return error.value; + } + return text ? text.substring(0, number) : null; + }; + + exports.LEN = function(text) { + if (arguments.length === 0) { + return error.error; + } + + if (typeof text === 'string') { + return text ? text.length : 0; + } + + if (text.length) { + return text.length; + } + + return error.value; + }; + + exports.LOWER = function(text) { + if (typeof text !== 'string') { + return error.value; + } + return text ? text.toLowerCase() : text; + }; + + exports.MID = function(text, start, number) { + start = utils.parseNumber(start); + number = utils.parseNumber(number); + if (utils.anyIsError(start, number) || typeof text !== 'string') { + return number; + } + + var begin = start - 1; + var end = begin + number; + + return text.substring(begin, end); + }; + + // TODO + exports.NUMBERVALUE = function (text, decimal_separator, group_separator) { + decimal_separator = (typeof decimal_separator === 'undefined') ? '.' : decimal_separator; + group_separator = (typeof group_separator === 'undefined') ? ',' : group_separator; + return Number(text.replace(decimal_separator, '.').replace(group_separator, '')); + }; + + // TODO + exports.PRONETIC = function() { + throw new Error('PRONETIC is not implemented'); + }; + + exports.PROPER = function(text) { + if (text === undefined || text.length === 0) { + return error.value; + } + if (text === true) { + text = 'TRUE'; + } + if (text === false) { + text = 'FALSE'; + } + if (isNaN(text) && typeof text === 'number') { + return error.value; + } + if (typeof text === 'number') { + text = '' + text; + } + + return text.replace(/\w\S*/g, function(txt) { + return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); + }); + }; + + exports.REGEXEXTRACT = function (text, regular_expression) { + var match = text.match(new RegExp(regular_expression)); + return match ? (match[match.length > 1 ? match.length - 1 : 0]) : null; + }; + + exports.REGEXMATCH = function (text, regular_expression, full) { + var match = text.match(new RegExp(regular_expression)); + return full ? match : !!match; + }; + + exports.REGEXREPLACE = function (text, regular_expression, replacement) { + return text.replace(new RegExp(regular_expression), replacement); + }; + + exports.REPLACE = function(text, position, length, new_text) { + position = utils.parseNumber(position); + length = utils.parseNumber(length); + if (utils.anyIsError(position, length) || + typeof text !== 'string' || + typeof new_text !== 'string') { + return error.value; + } + return text.substr(0, position - 1) + new_text + text.substr(position - 1 + length); + }; + + exports.REPT = function(text, number) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + return new Array(number + 1).join(text); + }; + + exports.RIGHT = function(text, number) { + number = (number === undefined) ? 1 : number; + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + return text ? text.substring(text.length - number) : null; + }; + + exports.SEARCH = function(find_text, within_text, position) { + var foundAt; + if (typeof find_text !== 'string' || typeof within_text !== 'string') { + return error.value; + } + position = (position === undefined) ? 0 : position; + foundAt = within_text.toLowerCase().indexOf(find_text.toLowerCase(), position - 1)+1; + return (foundAt === 0)?error.value:foundAt; + }; + + exports.SPLIT = function (text, separator) { + return text.split(separator); + }; + + exports.SUBSTITUTE = function(text, old_text, new_text, occurrence) { + if (!text || !old_text || !new_text) { + return text; + } else if (occurrence === undefined) { + return text.replace(new RegExp(old_text, 'g'), new_text); + } else { + var index = 0; + var i = 0; + while (text.indexOf(old_text, index) > 0) { + index = text.indexOf(old_text, index + 1); + i++; + if (i === occurrence) { + return text.substring(0, index) + new_text + text.substring(index + old_text.length); + } + } + } + }; + + exports.T = function(value) { + return (typeof value === "string") ? value : ''; + }; + + // TODO incomplete implementation + exports.TEXT = function(value, format) { + value = utils.parseNumber(value); + if (utils.anyIsError(value)) { + return error.na; + } + + return numeral(value).format(format); + }; + + exports.TRIM = function(text) { + if (typeof text !== 'string') { + return error.value; + } + return text.replace(/ +/g, ' ').trim(); + }; + + exports.UNICHAR = this.CHAR; + + exports.UNICODE = this.CODE; + + exports.UPPER = function(text) { + if (typeof text !== 'string') { + return error.value; + } + return text.toUpperCase(); + }; + + exports.VALUE = function(text) { + if (typeof text !== 'string') { + return error.value; + } + return numeral().unformat(text); + }; + + +/***/ }, +/* 8 */ +/***/ function(module, exports) { + + module.exports = __WEBPACK_EXTERNAL_MODULE_8__; + +/***/ }, +/* 9 */ +/***/ function(module, exports) { + + module.exports = __WEBPACK_EXTERNAL_MODULE_9__; + +/***/ }, +/* 10 */ +/***/ function(module, exports, __webpack_require__) { + + var utils = __webpack_require__(4); + var numeral = __webpack_require__(8); + + exports.UNIQUE = function () { + var result = []; + for (var i = 0; i < arguments.length; ++i) { + var hasElement = false; + var element = arguments[i]; + + // Check if we've already seen this element. + for (var j = 0; j < result.length; ++j) { + hasElement = result[j] === element; + if (hasElement) { break; } + } + + // If we did not find it, add it to the result. + if (!hasElement) { + result.push(element); + } + } + return result; + }; + + exports.FLATTEN = utils.flatten; + + exports.ARGS2ARRAY = function () { + return Array.prototype.slice.call(arguments, 0); + }; + + exports.REFERENCE = function (context, reference) { + try { + var path = reference.split('.'); + var result = context; + for (var i = 0; i < path.length; ++i) { + var step = path[i]; + if (step[step.length - 1] === ']') { + var opening = step.indexOf('['); + var index = step.substring(opening + 1, step.length - 1); + result = result[step.substring(0, opening)][index]; + } else { + result = result[step]; + } + } + return result; + } catch (error) {} + }; + + exports.JOIN = function (array, separator) { + return array.join(separator); + }; + + exports.NUMBERS = function () { + var possibleNumbers = utils.flatten(arguments); + return possibleNumbers.filter(function (el) { + return typeof el === 'number'; + }); + }; + + exports.NUMERAL = function (number, format) { + return numeral(number).format(format); + }; + +/***/ }, +/* 11 */ +/***/ function(module, exports, __webpack_require__) { + + var error = __webpack_require__(5); + + // TODO + exports.CELL = function() { + throw new Error('CELL is not implemented'); + }; + + exports.ERROR = {}; + exports.ERROR.TYPE = function(error_val) { + switch (error_val) { + case error.nil: return 1; + case error.div0: return 2; + case error.value: return 3; + case error.ref: return 4; + case error.name: return 5; + case error.num: return 6; + case error.na: return 7; + case error.data: return 8; + } + return error.na; + }; + + // TODO + exports.INFO = function() { + throw new Error('INFO is not implemented'); + }; + + exports.ISBLANK = function(value) { + return value === null; + }; + + exports.ISBINARY = function (number) { + return (/^[01]{1,10}$/).test(number); + }; + + exports.ISERR = function(value) { + return ([error.value, error.ref, error.div0, error.num, error.name, error.nil]).indexOf(value) >= 0 || + (typeof value === 'number' && (isNaN(value) || !isFinite(value))); + }; + + exports.ISERROR = function(value) { + return exports.ISERR(value) || value === error.na; + }; + + exports.ISEVEN = function(number) { + return (Math.floor(Math.abs(number)) & 1) ? false : true; + }; + + // TODO + exports.ISFORMULA = function() { + throw new Error('ISFORMULA is not implemented'); + }; + + exports.ISLOGICAL = function(value) { + return value === true || value === false; + }; + + exports.ISNA = function(value) { + return value === error.na; + }; + + exports.ISNONTEXT = function(value) { + return typeof(value) !== 'string'; + }; + + exports.ISNUMBER = function(value) { + return typeof(value) === 'number' && !isNaN(value) && isFinite(value); + }; + + exports.ISODD = function(number) { + return (Math.floor(Math.abs(number)) & 1) ? true : false; + }; + + // TODO + exports.ISREF = function() { + throw new Error('ISREF is not implemented'); + }; + + exports.ISTEXT = function(value) { + return typeof(value) === 'string'; + }; + + exports.N = function(value) { + if (this.ISNUMBER(value)) { + return value; + } + if (value instanceof Date) { + return value.getTime(); + } + if (value === true) { + return 1; + } + if (value === false) { + return 0; + } + if (this.ISERROR(value)) { + return value; + } + return 0; + }; + + exports.NA = function() { + return error.na; + }; + + + // TODO + exports.SHEET = function() { + throw new Error('SHEET is not implemented'); + }; + + // TODO + exports.SHEETS = function() { + throw new Error('SHEETS is not implemented'); + }; + + exports.TYPE = function(value) { + if (this.ISNUMBER(value)) { + return 1; + } + if (this.ISTEXT(value)) { + return 2; + } + if (this.ISLOGICAL(value)) { + return 4; + } + if (this.ISERROR(value)) { + return 16; + } + if (Array.isArray(value)) { + return 64; + } + }; + + +/***/ }, +/* 12 */ +/***/ function(module, exports, __webpack_require__) { + + var error = __webpack_require__(5); + var jStat = __webpack_require__(9).jStat; + var text = __webpack_require__(7); + var utils = __webpack_require__(4); + var bessel = __webpack_require__(13); + + function isValidBinaryNumber(number) { + return (/^[01]{1,10}$/).test(number); + } + + exports.BESSELI = function(x, n) { + x = utils.parseNumber(x); + n = utils.parseNumber(n); + if (utils.anyIsError(x, n)) { + return error.value; + } + return bessel.besseli(x, n); + }; + + exports.BESSELJ = function(x, n) { + x = utils.parseNumber(x); + n = utils.parseNumber(n); + if (utils.anyIsError(x, n)) { + return error.value; + } + return bessel.besselj(x, n); + }; + + exports.BESSELK = function(x, n) { + x = utils.parseNumber(x); + n = utils.parseNumber(n); + if (utils.anyIsError(x, n)) { + return error.value; + } + return bessel.besselk(x, n); + }; + + exports.BESSELY = function(x, n) { + x = utils.parseNumber(x); + n = utils.parseNumber(n); + if (utils.anyIsError(x, n)) { + return error.value; + } + return bessel.bessely(x, n); + }; + + exports.BIN2DEC = function(number) { + // Return error if number is not binary or contains more than 10 characters (10 digits) + if (!isValidBinaryNumber(number)) { + return error.num; + } + + // Convert binary number to decimal + var result = parseInt(number, 2); + + // Handle negative numbers + var stringified = number.toString(); + if (stringified.length === 10 && stringified.substring(0, 1) === '1') { + return parseInt(stringified.substring(1), 2) - 512; + } else { + return result; + } + }; + + + exports.BIN2HEX = function(number, places) { + // Return error if number is not binary or contains more than 10 characters (10 digits) + if (!isValidBinaryNumber(number)) { + return error.num; + } + + // Ignore places and return a 10-character hexadecimal number if number is negative + var stringified = number.toString(); + if (stringified.length === 10 && stringified.substring(0, 1) === '1') { + return (1099511627264 + parseInt(stringified.substring(1), 2)).toString(16); + } + + // Convert binary number to hexadecimal + var result = parseInt(number, 2).toString(16); + + // Return hexadecimal number using the minimum number of characters necessary if places is undefined + if (places === undefined) { + return result; + } else { + // Return error if places is nonnumeric + if (isNaN(places)) { + return error.value; + } + + // Return error if places is negative + if (places < 0) { + return error.num; + } + + // Truncate places in case it is not an integer + places = Math.floor(places); + + // Pad return value with leading 0s (zeros) if necessary (using Underscore.string) + return (places >= result.length) ? text.REPT('0', places - result.length) + result : error.num; + } + }; + + exports.BIN2OCT = function(number, places) { + // Return error if number is not binary or contains more than 10 characters (10 digits) + if (!isValidBinaryNumber(number)) { + return error.num; + } + + // Ignore places and return a 10-character octal number if number is negative + var stringified = number.toString(); + if (stringified.length === 10 && stringified.substring(0, 1) === '1') { + return (1073741312 + parseInt(stringified.substring(1), 2)).toString(8); + } + + // Convert binary number to octal + var result = parseInt(number, 2).toString(8); + + // Return octal number using the minimum number of characters necessary if places is undefined + if (places === undefined) { + return result; + } else { + // Return error if places is nonnumeric + if (isNaN(places)) { + return error.value; + } + + // Return error if places is negative + if (places < 0) { + return error.num; + } + + // Truncate places in case it is not an integer + places = Math.floor(places); + + // Pad return value with leading 0s (zeros) if necessary (using Underscore.string) + return (places >= result.length) ? text.REPT('0', places - result.length) + result : error.num; + } + }; + + exports.BITAND = function(number1, number2) { + // Return error if either number is a non-numeric value + number1 = utils.parseNumber(number1); + number2 = utils.parseNumber(number2); + if (utils.anyIsError(number1, number2)) { + return error.value; + } + + // Return error if either number is less than 0 + if (number1 < 0 || number2 < 0) { + return error.num; + } + + // Return error if either number is a non-integer + if (Math.floor(number1) !== number1 || Math.floor(number2) !== number2) { + return error.num; + } + + // Return error if either number is greater than (2^48)-1 + if (number1 > 281474976710655 || number2 > 281474976710655) { + return error.num; + } + + // Return bitwise AND of two numbers + return number1 & number2; + }; + + exports.BITLSHIFT = function(number, shift) { + number = utils.parseNumber(number); + shift = utils.parseNumber(shift); + if (utils.anyIsError(number, shift)) { + return error.value; + } + + // Return error if number is less than 0 + if (number < 0) { + return error.num; + } + + // Return error if number is a non-integer + if (Math.floor(number) !== number) { + return error.num; + } + + // Return error if number is greater than (2^48)-1 + if (number > 281474976710655) { + return error.num; + } + + // Return error if the absolute value of shift is greater than 53 + if (Math.abs(shift) > 53) { + return error.num; + } + + // Return number shifted by shift bits to the left or to the right if shift is negative + return (shift >= 0) ? number << shift : number >> -shift; + }; + + exports.BITOR = function(number1, number2) { + number1 = utils.parseNumber(number1); + number2 = utils.parseNumber(number2); + if (utils.anyIsError(number1, number2)) { + return error.value; + } + + // Return error if either number is less than 0 + if (number1 < 0 || number2 < 0) { + return error.num; + } + + // Return error if either number is a non-integer + if (Math.floor(number1) !== number1 || Math.floor(number2) !== number2) { + return error.num; + } + + // Return error if either number is greater than (2^48)-1 + if (number1 > 281474976710655 || number2 > 281474976710655) { + return error.num; + } + + // Return bitwise OR of two numbers + return number1 | number2; + }; + + exports.BITRSHIFT = function(number, shift) { + number = utils.parseNumber(number); + shift = utils.parseNumber(shift); + if (utils.anyIsError(number, shift)) { + return error.value; + } + + // Return error if number is less than 0 + if (number < 0) { + return error.num; + } + + // Return error if number is a non-integer + if (Math.floor(number) !== number) { + return error.num; + } + + // Return error if number is greater than (2^48)-1 + if (number > 281474976710655) { + return error.num; + } + + // Return error if the absolute value of shift is greater than 53 + if (Math.abs(shift) > 53) { + return error.num; + } + + // Return number shifted by shift bits to the right or to the left if shift is negative + return (shift >= 0) ? number >> shift : number << -shift; + }; + + exports.BITXOR = function(number1, number2) { + number1 = utils.parseNumber(number1); + number2 = utils.parseNumber(number2); + if (utils.anyIsError(number1, number2)) { + return error.value; + } + + // Return error if either number is less than 0 + if (number1 < 0 || number2 < 0) { + return error.num; + } + + // Return error if either number is a non-integer + if (Math.floor(number1) !== number1 || Math.floor(number2) !== number2) { + return error.num; + } + + // Return error if either number is greater than (2^48)-1 + if (number1 > 281474976710655 || number2 > 281474976710655) { + return error.num; + } + + // Return bitwise XOR of two numbers + return number1 ^ number2; + }; + + exports.COMPLEX = function(real, imaginary, suffix) { + real = utils.parseNumber(real); + imaginary = utils.parseNumber(imaginary); + if (utils.anyIsError(real, imaginary)) { + return real; + } + + // Set suffix + suffix = (suffix === undefined) ? 'i' : suffix; + + // Return error if suffix is neither "i" nor "j" + if (suffix !== 'i' && suffix !== 'j') { + return error.value; + } + + // Return complex number + if (real === 0 && imaginary === 0) { + return 0; + } else if (real === 0) { + return (imaginary === 1) ? suffix : imaginary.toString() + suffix; + } else if (imaginary === 0) { + return real.toString(); + } else { + var sign = (imaginary > 0) ? '+' : ''; + return real.toString() + sign + ((imaginary === 1) ? suffix : imaginary.toString() + suffix); + } + }; + + exports.CONVERT = function(number, from_unit, to_unit) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + + // List of units supported by CONVERT and units defined by the International System of Units + // [Name, Symbol, Alternate symbols, Quantity, ISU, CONVERT, Conversion ratio] + var units = [ + ["a.u. of action", "?", null, "action", false, false, 1.05457168181818e-34], + ["a.u. of charge", "e", null, "electric_charge", false, false, 1.60217653141414e-19], + ["a.u. of energy", "Eh", null, "energy", false, false, 4.35974417757576e-18], + ["a.u. of length", "a?", null, "length", false, false, 5.29177210818182e-11], + ["a.u. of mass", "m?", null, "mass", false, false, 9.10938261616162e-31], + ["a.u. of time", "?/Eh", null, "time", false, false, 2.41888432650516e-17], + ["admiralty knot", "admkn", null, "speed", false, true, 0.514773333], + ["ampere", "A", null, "electric_current", true, false, 1], + ["ampere per meter", "A/m", null, "magnetic_field_intensity", true, false, 1], + ["ångström", "Å", ["ang"], "length", false, true, 1e-10], + ["are", "ar", null, "area", false, true, 100], + ["astronomical unit", "ua", null, "length", false, false, 1.49597870691667e-11], + ["bar", "bar", null, "pressure", false, false, 100000], + ["barn", "b", null, "area", false, false, 1e-28], + ["becquerel", "Bq", null, "radioactivity", true, false, 1], + ["bit", "bit", ["b"], "information", false, true, 1], + ["btu", "BTU", ["btu"], "energy", false, true, 1055.05585262], + ["byte", "byte", null, "information", false, true, 8], + ["candela", "cd", null, "luminous_intensity", true, false, 1], + ["candela per square metre", "cd/m?", null, "luminance", true, false, 1], + ["coulomb", "C", null, "electric_charge", true, false, 1], + ["cubic ångström", "ang3", ["ang^3"], "volume", false, true, 1e-30], + ["cubic foot", "ft3", ["ft^3"], "volume", false, true, 0.028316846592], + ["cubic inch", "in3", ["in^3"], "volume", false, true, 0.000016387064], + ["cubic light-year", "ly3", ["ly^3"], "volume", false, true, 8.46786664623715e-47], + ["cubic metre", "m?", null, "volume", true, true, 1], + ["cubic mile", "mi3", ["mi^3"], "volume", false, true, 4168181825.44058], + ["cubic nautical mile", "Nmi3", ["Nmi^3"], "volume", false, true, 6352182208], + ["cubic Pica", "Pica3", ["Picapt3", "Pica^3", "Picapt^3"], "volume", false, true, 7.58660370370369e-8], + ["cubic yard", "yd3", ["yd^3"], "volume", false, true, 0.764554857984], + ["cup", "cup", null, "volume", false, true, 0.0002365882365], + ["dalton", "Da", ["u"], "mass", false, false, 1.66053886282828e-27], + ["day", "d", ["day"], "time", false, true, 86400], + ["degree", "°", null, "angle", false, false, 0.0174532925199433], + ["degrees Rankine", "Rank", null, "temperature", false, true, 0.555555555555556], + ["dyne", "dyn", ["dy"], "force", false, true, 0.00001], + ["electronvolt", "eV", ["ev"], "energy", false, true, 1.60217656514141], + ["ell", "ell", null, "length", false, true, 1.143], + ["erg", "erg", ["e"], "energy", false, true, 1e-7], + ["farad", "F", null, "electric_capacitance", true, false, 1], + ["fluid ounce", "oz", null, "volume", false, true, 0.0000295735295625], + ["foot", "ft", null, "length", false, true, 0.3048], + ["foot-pound", "flb", null, "energy", false, true, 1.3558179483314], + ["gal", "Gal", null, "acceleration", false, false, 0.01], + ["gallon", "gal", null, "volume", false, true, 0.003785411784], + ["gauss", "G", ["ga"], "magnetic_flux_density", false, true, 1], + ["grain", "grain", null, "mass", false, true, 0.0000647989], + ["gram", "g", null, "mass", false, true, 0.001], + ["gray", "Gy", null, "absorbed_dose", true, false, 1], + ["gross registered ton", "GRT", ["regton"], "volume", false, true, 2.8316846592], + ["hectare", "ha", null, "area", false, true, 10000], + ["henry", "H", null, "inductance", true, false, 1], + ["hertz", "Hz", null, "frequency", true, false, 1], + ["horsepower", "HP", ["h"], "power", false, true, 745.69987158227], + ["horsepower-hour", "HPh", ["hh", "hph"], "energy", false, true, 2684519.538], + ["hour", "h", ["hr"], "time", false, true, 3600], + ["imperial gallon (U.K.)", "uk_gal", null, "volume", false, true, 0.00454609], + ["imperial hundredweight", "lcwt", ["uk_cwt", "hweight"], "mass", false, true, 50.802345], + ["imperial quart (U.K)", "uk_qt", null, "volume", false, true, 0.0011365225], + ["imperial ton", "brton", ["uk_ton", "LTON"], "mass", false, true, 1016.046909], + ["inch", "in", null, "length", false, true, 0.0254], + ["international acre", "uk_acre", null, "area", false, true, 4046.8564224], + ["IT calorie", "cal", null, "energy", false, true, 4.1868], + ["joule", "J", null, "energy", true, true, 1], + ["katal", "kat", null, "catalytic_activity", true, false, 1], + ["kelvin", "K", ["kel"], "temperature", true, true, 1], + ["kilogram", "kg", null, "mass", true, true, 1], + ["knot", "kn", null, "speed", false, true, 0.514444444444444], + ["light-year", "ly", null, "length", false, true, 9460730472580800], + ["litre", "L", ["l", "lt"], "volume", false, true, 0.001], + ["lumen", "lm", null, "luminous_flux", true, false, 1], + ["lux", "lx", null, "illuminance", true, false, 1], + ["maxwell", "Mx", null, "magnetic_flux", false, false, 1e-18], + ["measurement ton", "MTON", null, "volume", false, true, 1.13267386368], + ["meter per hour", "m/h", ["m/hr"], "speed", false, true, 0.00027777777777778], + ["meter per second", "m/s", ["m/sec"], "speed", true, true, 1], + ["meter per second squared", "m?s??", null, "acceleration", true, false, 1], + ["parsec", "pc", ["parsec"], "length", false, true, 30856775814671900], + ["meter squared per second", "m?/s", null, "kinematic_viscosity", true, false, 1], + ["metre", "m", null, "length", true, true, 1], + ["miles per hour", "mph", null, "speed", false, true, 0.44704], + ["millimetre of mercury", "mmHg", null, "pressure", false, false, 133.322], + ["minute", "?", null, "angle", false, false, 0.000290888208665722], + ["minute", "min", ["mn"], "time", false, true, 60], + ["modern teaspoon", "tspm", null, "volume", false, true, 0.000005], + ["mole", "mol", null, "amount_of_substance", true, false, 1], + ["morgen", "Morgen", null, "area", false, true, 2500], + ["n.u. of action", "?", null, "action", false, false, 1.05457168181818e-34], + ["n.u. of mass", "m?", null, "mass", false, false, 9.10938261616162e-31], + ["n.u. of speed", "c?", null, "speed", false, false, 299792458], + ["n.u. of time", "?/(me?c??)", null, "time", false, false, 1.28808866778687e-21], + ["nautical mile", "M", ["Nmi"], "length", false, true, 1852], + ["newton", "N", null, "force", true, true, 1], + ["œrsted", "Oe ", null, "magnetic_field_intensity", false, false, 79.5774715459477], + ["ohm", "Ω", null, "electric_resistance", true, false, 1], + ["ounce mass", "ozm", null, "mass", false, true, 0.028349523125], + ["pascal", "Pa", null, "pressure", true, false, 1], + ["pascal second", "Pa?s", null, "dynamic_viscosity", true, false, 1], + ["pferdestärke", "PS", null, "power", false, true, 735.49875], + ["phot", "ph", null, "illuminance", false, false, 0.0001], + ["pica (1/6 inch)", "pica", null, "length", false, true, 0.00035277777777778], + ["pica (1/72 inch)", "Pica", ["Picapt"], "length", false, true, 0.00423333333333333], + ["poise", "P", null, "dynamic_viscosity", false, false, 0.1], + ["pond", "pond", null, "force", false, true, 0.00980665], + ["pound force", "lbf", null, "force", false, true, 4.4482216152605], + ["pound mass", "lbm", null, "mass", false, true, 0.45359237], + ["quart", "qt", null, "volume", false, true, 0.000946352946], + ["radian", "rad", null, "angle", true, false, 1], + ["second", "?", null, "angle", false, false, 0.00000484813681109536], + ["second", "s", ["sec"], "time", true, true, 1], + ["short hundredweight", "cwt", ["shweight"], "mass", false, true, 45.359237], + ["siemens", "S", null, "electrical_conductance", true, false, 1], + ["sievert", "Sv", null, "equivalent_dose", true, false, 1], + ["slug", "sg", null, "mass", false, true, 14.59390294], + ["square ångström", "ang2", ["ang^2"], "area", false, true, 1e-20], + ["square foot", "ft2", ["ft^2"], "area", false, true, 0.09290304], + ["square inch", "in2", ["in^2"], "area", false, true, 0.00064516], + ["square light-year", "ly2", ["ly^2"], "area", false, true, 8.95054210748189e+31], + ["square meter", "m?", null, "area", true, true, 1], + ["square mile", "mi2", ["mi^2"], "area", false, true, 2589988.110336], + ["square nautical mile", "Nmi2", ["Nmi^2"], "area", false, true, 3429904], + ["square Pica", "Pica2", ["Picapt2", "Pica^2", "Picapt^2"], "area", false, true, 0.00001792111111111], + ["square yard", "yd2", ["yd^2"], "area", false, true, 0.83612736], + ["statute mile", "mi", null, "length", false, true, 1609.344], + ["steradian", "sr", null, "solid_angle", true, false, 1], + ["stilb", "sb", null, "luminance", false, false, 0.0001], + ["stokes", "St", null, "kinematic_viscosity", false, false, 0.0001], + ["stone", "stone", null, "mass", false, true, 6.35029318], + ["tablespoon", "tbs", null, "volume", false, true, 0.0000147868], + ["teaspoon", "tsp", null, "volume", false, true, 0.00000492892], + ["tesla", "T", null, "magnetic_flux_density", true, true, 1], + ["thermodynamic calorie", "c", null, "energy", false, true, 4.184], + ["ton", "ton", null, "mass", false, true, 907.18474], + ["tonne", "t", null, "mass", false, false, 1000], + ["U.K. pint", "uk_pt", null, "volume", false, true, 0.00056826125], + ["U.S. bushel", "bushel", null, "volume", false, true, 0.03523907], + ["U.S. oil barrel", "barrel", null, "volume", false, true, 0.158987295], + ["U.S. pint", "pt", ["us_pt"], "volume", false, true, 0.000473176473], + ["U.S. survey mile", "survey_mi", null, "length", false, true, 1609.347219], + ["U.S. survey/statute acre", "us_acre", null, "area", false, true, 4046.87261], + ["volt", "V", null, "voltage", true, false, 1], + ["watt", "W", null, "power", true, true, 1], + ["watt-hour", "Wh", ["wh"], "energy", false, true, 3600], + ["weber", "Wb", null, "magnetic_flux", true, false, 1], + ["yard", "yd", null, "length", false, true, 0.9144], + ["year", "yr", null, "time", false, true, 31557600] + ]; + + // Binary prefixes + // [Name, Prefix power of 2 value, Previx value, Abbreviation, Derived from] + var binary_prefixes = { + Yi: ["yobi", 80, 1208925819614629174706176, "Yi", "yotta"], + Zi: ["zebi", 70, 1180591620717411303424, "Zi", "zetta"], + Ei: ["exbi", 60, 1152921504606846976, "Ei", "exa"], + Pi: ["pebi", 50, 1125899906842624, "Pi", "peta"], + Ti: ["tebi", 40, 1099511627776, "Ti", "tera"], + Gi: ["gibi", 30, 1073741824, "Gi", "giga"], + Mi: ["mebi", 20, 1048576, "Mi", "mega"], + ki: ["kibi", 10, 1024, "ki", "kilo"] + }; + + // Unit prefixes + // [Name, Multiplier, Abbreviation] + var unit_prefixes = { + Y: ["yotta", 1e+24, "Y"], + Z: ["zetta", 1e+21, "Z"], + E: ["exa", 1e+18, "E"], + P: ["peta", 1e+15, "P"], + T: ["tera", 1e+12, "T"], + G: ["giga", 1e+09, "G"], + M: ["mega", 1e+06, "M"], + k: ["kilo", 1e+03, "k"], + h: ["hecto", 1e+02, "h"], + e: ["dekao", 1e+01, "e"], + d: ["deci", 1e-01, "d"], + c: ["centi", 1e-02, "c"], + m: ["milli", 1e-03, "m"], + u: ["micro", 1e-06, "u"], + n: ["nano", 1e-09, "n"], + p: ["pico", 1e-12, "p"], + f: ["femto", 1e-15, "f"], + a: ["atto", 1e-18, "a"], + z: ["zepto", 1e-21, "z"], + y: ["yocto", 1e-24, "y"] + }; + + // Initialize units and multipliers + var from = null; + var to = null; + var base_from_unit = from_unit; + var base_to_unit = to_unit; + var from_multiplier = 1; + var to_multiplier = 1; + var alt; + + // Lookup from and to units + for (var i = 0; i < units.length; i++) { + alt = (units[i][2] === null) ? [] : units[i][2]; + if (units[i][1] === base_from_unit || alt.indexOf(base_from_unit) >= 0) { + from = units[i]; + } + if (units[i][1] === base_to_unit || alt.indexOf(base_to_unit) >= 0) { + to = units[i]; + } + } + + // Lookup from prefix + if (from === null) { + var from_binary_prefix = binary_prefixes[from_unit.substring(0, 2)]; + var from_unit_prefix = unit_prefixes[from_unit.substring(0, 1)]; + + // Handle dekao unit prefix (only unit prefix with two characters) + if (from_unit.substring(0, 2) === 'da') { + from_unit_prefix = ["dekao", 1e+01, "da"]; + } + + // Handle binary prefixes first (so that 'Yi' is processed before 'Y') + if (from_binary_prefix) { + from_multiplier = from_binary_prefix[2]; + base_from_unit = from_unit.substring(2); + } else if (from_unit_prefix) { + from_multiplier = from_unit_prefix[1]; + base_from_unit = from_unit.substring(from_unit_prefix[2].length); + } + + // Lookup from unit + for (var j = 0; j < units.length; j++) { + alt = (units[j][2] === null) ? [] : units[j][2]; + if (units[j][1] === base_from_unit || alt.indexOf(base_from_unit) >= 0) { + from = units[j]; + } + } + } + + // Lookup to prefix + if (to === null) { + var to_binary_prefix = binary_prefixes[to_unit.substring(0, 2)]; + var to_unit_prefix = unit_prefixes[to_unit.substring(0, 1)]; + + // Handle dekao unit prefix (only unit prefix with two characters) + if (to_unit.substring(0, 2) === 'da') { + to_unit_prefix = ["dekao", 1e+01, "da"]; + } + + // Handle binary prefixes first (so that 'Yi' is processed before 'Y') + if (to_binary_prefix) { + to_multiplier = to_binary_prefix[2]; + base_to_unit = to_unit.substring(2); + } else if (to_unit_prefix) { + to_multiplier = to_unit_prefix[1]; + base_to_unit = to_unit.substring(to_unit_prefix[2].length); + } + + // Lookup to unit + for (var k = 0; k < units.length; k++) { + alt = (units[k][2] === null) ? [] : units[k][2]; + if (units[k][1] === base_to_unit || alt.indexOf(base_to_unit) >= 0) { + to = units[k]; + } + } + } + + // Return error if a unit does not exist + if (from === null || to === null) { + return error.na; + } + + // Return error if units represent different quantities + if (from[3] !== to[3]) { + return error.na; + } + + // Return converted number + return number * from[6] * from_multiplier / (to[6] * to_multiplier); + }; + + exports.DEC2BIN = function(number, places) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + + // Return error if number is not decimal, is lower than -512, or is greater than 511 + if (!/^-?[0-9]{1,3}$/.test(number) || number < -512 || number > 511) { + return error.num; + } + + // Ignore places and return a 10-character binary number if number is negative + if (number < 0) { + return '1' + text.REPT('0', 9 - (512 + number).toString(2).length) + (512 + number).toString(2); + } + + // Convert decimal number to binary + var result = parseInt(number, 10).toString(2); + + // Return binary number using the minimum number of characters necessary if places is undefined + if (typeof places === 'undefined') { + return result; + } else { + // Return error if places is nonnumeric + if (isNaN(places)) { + return error.value; + } + + // Return error if places is negative + if (places < 0) { + return error.num; + } + + // Truncate places in case it is not an integer + places = Math.floor(places); + + // Pad return value with leading 0s (zeros) if necessary (using Underscore.string) + return (places >= result.length) ? text.REPT('0', places - result.length) + result : error.num; + } + }; + + exports.DEC2HEX = function(number, places) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + + // Return error if number is not decimal, is lower than -549755813888, or is greater than 549755813887 + if (!/^-?[0-9]{1,12}$/.test(number) || number < -549755813888 || number > 549755813887) { + return error.num; + } + + // Ignore places and return a 10-character hexadecimal number if number is negative + if (number < 0) { + return (1099511627776 + number).toString(16); + } + + // Convert decimal number to hexadecimal + var result = parseInt(number, 10).toString(16); + + // Return hexadecimal number using the minimum number of characters necessary if places is undefined + if (typeof places === 'undefined') { + return result; + } else { + // Return error if places is nonnumeric + if (isNaN(places)) { + return error.value; + } + + // Return error if places is negative + if (places < 0) { + return error.num; + } + + // Truncate places in case it is not an integer + places = Math.floor(places); + + // Pad return value with leading 0s (zeros) if necessary (using Underscore.string) + return (places >= result.length) ? text.REPT('0', places - result.length) + result : error.num; + } + }; + + exports.DEC2OCT = function(number, places) { + number = utils.parseNumber(number); + if (number instanceof Error) { + return number; + } + + // Return error if number is not decimal, is lower than -549755813888, or is greater than 549755813887 + if (!/^-?[0-9]{1,9}$/.test(number) || number < -536870912 || number > 536870911) { + return error.num; + } + + // Ignore places and return a 10-character octal number if number is negative + if (number < 0) { + return (1073741824 + number).toString(8); + } + + // Convert decimal number to octal + var result = parseInt(number, 10).toString(8); + + // Return octal number using the minimum number of characters necessary if places is undefined + if (typeof places === 'undefined') { + return result; + } else { + // Return error if places is nonnumeric + if (isNaN(places)) { + return error.value; + } + + // Return error if places is negative + if (places < 0) { + return error.num; + } + + // Truncate places in case it is not an integer + places = Math.floor(places); + + // Pad return value with leading 0s (zeros) if necessary (using Underscore.string) + return (places >= result.length) ? text.REPT('0', places - result.length) + result : error.num; + } + }; + + exports.DELTA = function(number1, number2) { + // Set number2 to zero if undefined + number2 = (number2 === undefined) ? 0 : number2; + number1 = utils.parseNumber(number1); + number2 = utils.parseNumber(number2); + if (utils.anyIsError(number1, number2)) { + return error.value; + } + + // Return delta + return (number1 === number2) ? 1 : 0; + }; + + // TODO: why is upper_bound not used ? The excel documentation has no examples with upper_bound + exports.ERF = function(lower_bound, upper_bound) { + // Set number2 to zero if undefined + upper_bound = (upper_bound === undefined) ? 0 : upper_bound; + + lower_bound = utils.parseNumber(lower_bound); + upper_bound = utils.parseNumber(upper_bound); + if (utils.anyIsError(lower_bound, upper_bound)) { + return error.value; + } + + return jStat.erf(lower_bound); + }; + + // TODO + exports.ERF.PRECISE = function() { + throw new Error('ERF.PRECISE is not implemented'); + }; + + exports.ERFC = function(x) { + // Return error if x is not a number + if (isNaN(x)) { + return error.value; + } + + return jStat.erfc(x); + }; + + // TODO + exports.ERFC.PRECISE = function() { + throw new Error('ERFC.PRECISE is not implemented'); + }; + + exports.GESTEP = function(number, step) { + step = step || 0; + number = utils.parseNumber(number); + if (utils.anyIsError(step, number)) { + return number; + } + + // Return delta + return (number >= step) ? 1 : 0; + }; + + exports.HEX2BIN = function(number, places) { + // Return error if number is not hexadecimal or contains more than ten characters (10 digits) + if (!/^[0-9A-Fa-f]{1,10}$/.test(number)) { + return error.num; + } + + // Check if number is negative + var negative = (number.length === 10 && number.substring(0, 1).toLowerCase() === 'f') ? true : false; + + // Convert hexadecimal number to decimal + var decimal = (negative) ? parseInt(number, 16) - 1099511627776 : parseInt(number, 16); + + // Return error if number is lower than -512 or greater than 511 + if (decimal < -512 || decimal > 511) { + return error.num; + } + + // Ignore places and return a 10-character binary number if number is negative + if (negative) { + return '1' + text.REPT('0', 9 - (512 + decimal).toString(2).length) + (512 + decimal).toString(2); + } + + // Convert decimal number to binary + var result = decimal.toString(2); + + // Return binary number using the minimum number of characters necessary if places is undefined + if (places === undefined) { + return result; + } else { + // Return error if places is nonnumeric + if (isNaN(places)) { + return error.value; + } + + // Return error if places is negative + if (places < 0) { + return error.num; + } + + // Truncate places in case it is not an integer + places = Math.floor(places); + + // Pad return value with leading 0s (zeros) if necessary (using Underscore.string) + return (places >= result.length) ? text.REPT('0', places - result.length) + result : error.num; + } + }; + + exports.HEX2DEC = function(number) { + // Return error if number is not hexadecimal or contains more than ten characters (10 digits) + if (!/^[0-9A-Fa-f]{1,10}$/.test(number)) { + return error.num; + } + + // Convert hexadecimal number to decimal + var decimal = parseInt(number, 16); + + // Return decimal number + return (decimal >= 549755813888) ? decimal - 1099511627776 : decimal; + }; + + exports.HEX2OCT = function(number, places) { + // Return error if number is not hexadecimal or contains more than ten characters (10 digits) + if (!/^[0-9A-Fa-f]{1,10}$/.test(number)) { + return error.num; + } + + // Convert hexadecimal number to decimal + var decimal = parseInt(number, 16); + + // Return error if number is positive and greater than 0x1fffffff (536870911) + if (decimal > 536870911 && decimal < 1098974756864) { + return error.num; + } + + // Ignore places and return a 10-character octal number if number is negative + if (decimal >= 1098974756864) { + return (decimal - 1098437885952).toString(8); + } + + // Convert decimal number to octal + var result = decimal.toString(8); + + // Return octal number using the minimum number of characters necessary if places is undefined + if (places === undefined) { + return result; + } else { + // Return error if places is nonnumeric + if (isNaN(places)) { + return error.value; + } + + // Return error if places is negative + if (places < 0) { + return error.num; + } + + // Truncate places in case it is not an integer + places = Math.floor(places); + + // Pad return value with leading 0s (zeros) if necessary (using Underscore.string) + return (places >= result.length) ? text.REPT('0', places - result.length) + result : error.num; + } + }; + + exports.IMABS = function(inumber) { + // Lookup real and imaginary coefficients using exports.js [http://formulajs.org] + var x = exports.IMREAL(inumber); + var y = exports.IMAGINARY(inumber); + + // Return error if either coefficient is not a number + if (utils.anyIsError(x, y)) { + return error.value; + } + + // Return absolute value of complex number + return Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)); + }; + + exports.IMAGINARY = function(inumber) { + if (inumber === undefined || inumber === true || inumber === false) { + return error.value; + } + + // Return 0 if inumber is equal to 0 + if (inumber === 0 || inumber === '0') { + return 0; + } + + // Handle special cases + if (['i', 'j'].indexOf(inumber) >= 0) { + return 1; + } + + // Normalize imaginary coefficient + inumber = inumber.replace('+i', '+1i').replace('-i', '-1i').replace('+j', '+1j').replace('-j', '-1j'); + + // Lookup sign + var plus = inumber.indexOf('+'); + var minus = inumber.indexOf('-'); + if (plus === 0) { + plus = inumber.indexOf('+', 1); + } + + if (minus === 0) { + minus = inumber.indexOf('-', 1); + } + + // Lookup imaginary unit + var last = inumber.substring(inumber.length - 1, inumber.length); + var unit = (last === 'i' || last === 'j'); + + if (plus >= 0 || minus >= 0) { + // Return error if imaginary unit is neither i nor j + if (!unit) { + return error.num; + } + + // Return imaginary coefficient of complex number + if (plus >= 0) { + return (isNaN(inumber.substring(0, plus)) || isNaN(inumber.substring(plus + 1, inumber.length - 1))) ? + error.num : + Number(inumber.substring(plus + 1, inumber.length - 1)); + } else { + return (isNaN(inumber.substring(0, minus)) || isNaN(inumber.substring(minus + 1, inumber.length - 1))) ? + error.num : + -Number(inumber.substring(minus + 1, inumber.length - 1)); + } + } else { + if (unit) { + return (isNaN(inumber.substring(0, inumber.length - 1))) ? error.num : inumber.substring(0, inumber.length - 1); + } else { + return (isNaN(inumber)) ? error.num : 0; + } + } + }; + + exports.IMARGUMENT = function(inumber) { + // Lookup real and imaginary coefficients using exports.js [http://formulajs.org] + var x = exports.IMREAL(inumber); + var y = exports.IMAGINARY(inumber); + + // Return error if either coefficient is not a number + if (utils.anyIsError(x, y)) { + return error.value; + } + + // Return error if inumber is equal to zero + if (x === 0 && y === 0) { + return error.div0; + } + + // Return PI/2 if x is equal to zero and y is positive + if (x === 0 && y > 0) { + return Math.PI / 2; + } + + // Return -PI/2 if x is equal to zero and y is negative + if (x === 0 && y < 0) { + return -Math.PI / 2; + } + + // Return zero if x is negative and y is equal to zero + if (y === 0 && x > 0) { + return 0; + } + + // Return zero if x is negative and y is equal to zero + if (y === 0 && x < 0) { + return -Math.PI; + } + + // Return argument of complex number + if (x > 0) { + return Math.atan(y / x); + } else if (x < 0 && y >= 0) { + return Math.atan(y / x) + Math.PI; + } else { + return Math.atan(y / x) - Math.PI; + } + }; + + exports.IMCONJUGATE = function(inumber) { + // Lookup real and imaginary coefficients using exports.js [http://formulajs.org] + var x = exports.IMREAL(inumber); + var y = exports.IMAGINARY(inumber); + + if (utils.anyIsError(x, y)) { + return error.value; + } + + // Lookup imaginary unit + var unit = inumber.substring(inumber.length - 1); + unit = (unit === 'i' || unit === 'j') ? unit : 'i'; + + // Return conjugate of complex number + return (y !== 0) ? exports.COMPLEX(x, -y, unit) : inumber; + }; + + exports.IMCOS = function(inumber) { + // Lookup real and imaginary coefficients using exports.js [http://formulajs.org] + var x = exports.IMREAL(inumber); + var y = exports.IMAGINARY(inumber); + + if (utils.anyIsError(x, y)) { + return error.value; + } + + // Lookup imaginary unit + var unit = inumber.substring(inumber.length - 1); + unit = (unit === 'i' || unit === 'j') ? unit : 'i'; + + // Return cosine of complex number + return exports.COMPLEX(Math.cos(x) * (Math.exp(y) + Math.exp(-y)) / 2, -Math.sin(x) * (Math.exp(y) - Math.exp(-y)) / 2, unit); + }; + + exports.IMCOSH = function(inumber) { + // Lookup real and imaginary coefficients using exports.js [http://formulajs.org] + var x = exports.IMREAL(inumber); + var y = exports.IMAGINARY(inumber); + + if (utils.anyIsError(x, y)) { + return error.value; + } + + // Lookup imaginary unit + var unit = inumber.substring(inumber.length - 1); + unit = (unit === 'i' || unit === 'j') ? unit : 'i'; + + // Return hyperbolic cosine of complex number + return exports.COMPLEX(Math.cos(y) * (Math.exp(x) + Math.exp(-x)) / 2, Math.sin(y) * (Math.exp(x) - Math.exp(-x)) / 2, unit); + }; + + exports.IMCOT = function(inumber) { + // Lookup real and imaginary coefficients using Formula.js [http://formulajs.org] + var x = exports.IMREAL(inumber); + var y = exports.IMAGINARY(inumber); + + if (utils.anyIsError(x, y)) { + return error.value; + } + + // Return cotangent of complex number + return exports.IMDIV(exports.IMCOS(inumber), exports.IMSIN(inumber)); + }; + + exports.IMDIV = function(inumber1, inumber2) { + // Lookup real and imaginary coefficients using Formula.js [http://formulajs.org] + var a = exports.IMREAL(inumber1); + var b = exports.IMAGINARY(inumber1); + var c = exports.IMREAL(inumber2); + var d = exports.IMAGINARY(inumber2); + + if (utils.anyIsError(a, b, c, d)) { + return error.value; + } + + // Lookup imaginary unit + var unit1 = inumber1.substring(inumber1.length - 1); + var unit2 = inumber2.substring(inumber2.length - 1); + var unit = 'i'; + if (unit1 === 'j') { + unit = 'j'; + } else if (unit2 === 'j') { + unit = 'j'; + } + + // Return error if inumber2 is null + if (c === 0 && d === 0) { + return error.num; + } + + // Return exponential of complex number + var den = c * c + d * d; + return exports.COMPLEX((a * c + b * d) / den, (b * c - a * d) / den, unit); + }; + + exports.IMEXP = function(inumber) { + // Lookup real and imaginary coefficients using Formula.js [http://formulajs.org] + var x = exports.IMREAL(inumber); + var y = exports.IMAGINARY(inumber); + + if (utils.anyIsError(x, y)) { + return error.value; + } + + // Lookup imaginary unit + var unit = inumber.substring(inumber.length - 1); + unit = (unit === 'i' || unit === 'j') ? unit : 'i'; + + // Return exponential of complex number + var e = Math.exp(x); + return exports.COMPLEX(e * Math.cos(y), e * Math.sin(y), unit); + }; + + exports.IMLN = function(inumber) { + // Lookup real and imaginary coefficients using Formula.js [http://formulajs.org] + var x = exports.IMREAL(inumber); + var y = exports.IMAGINARY(inumber); + + if (utils.anyIsError(x, y)) { + return error.value; + } + + // Lookup imaginary unit + var unit = inumber.substring(inumber.length - 1); + unit = (unit === 'i' || unit === 'j') ? unit : 'i'; + + // Return exponential of complex number + return exports.COMPLEX(Math.log(Math.sqrt(x * x + y * y)), Math.atan(y / x), unit); + }; + + exports.IMLOG10 = function(inumber) { + // Lookup real and imaginary coefficients using Formula.js [http://formulajs.org] + var x = exports.IMREAL(inumber); + var y = exports.IMAGINARY(inumber); + + if (utils.anyIsError(x, y)) { + return error.value; + } + + // Lookup imaginary unit + var unit = inumber.substring(inumber.length - 1); + unit = (unit === 'i' || unit === 'j') ? unit : 'i'; + + // Return exponential of complex number + return exports.COMPLEX(Math.log(Math.sqrt(x * x + y * y)) / Math.log(10), Math.atan(y / x) / Math.log(10), unit); + }; + + exports.IMLOG2 = function(inumber) { + // Lookup real and imaginary coefficients using Formula.js [http://formulajs.org] + var x = exports.IMREAL(inumber); + var y = exports.IMAGINARY(inumber); + + if (utils.anyIsError(x, y)) { + return error.value; + } + + // Lookup imaginary unit + var unit = inumber.substring(inumber.length - 1); + unit = (unit === 'i' || unit === 'j') ? unit : 'i'; + + // Return exponential of complex number + return exports.COMPLEX(Math.log(Math.sqrt(x * x + y * y)) / Math.log(2), Math.atan(y / x) / Math.log(2), unit); + }; + + exports.IMPOWER = function(inumber, number) { + number = utils.parseNumber(number); + var x = exports.IMREAL(inumber); + var y = exports.IMAGINARY(inumber); + if (utils.anyIsError(number, x, y)) { + return error.value; + } + + // Lookup imaginary unit + var unit = inumber.substring(inumber.length - 1); + unit = (unit === 'i' || unit === 'j') ? unit : 'i'; + + // Calculate power of modulus + var p = Math.pow(exports.IMABS(inumber), number); + + // Calculate argument + var t = exports.IMARGUMENT(inumber); + + // Return exponential of complex number + return exports.COMPLEX(p * Math.cos(number * t), p * Math.sin(number * t), unit); + }; + + exports.IMPRODUCT = function() { + // Initialize result + var result = arguments[0]; + + // Loop on all numbers + for (var i = 1; i < arguments.length; i++) { + // Lookup coefficients of two complex numbers + var a = exports.IMREAL(result); + var b = exports.IMAGINARY(result); + var c = exports.IMREAL(arguments[i]); + var d = exports.IMAGINARY(arguments[i]); + + if (utils.anyIsError(a, b, c, d)) { + return error.value; + } + + // Complute product of two complex numbers + result = exports.COMPLEX(a * c - b * d, a * d + b * c); + } + + // Return product of complex numbers + return result; + }; + + exports.IMREAL = function(inumber) { + if (inumber === undefined || inumber === true || inumber === false) { + return error.value; + } + + // Return 0 if inumber is equal to 0 + if (inumber === 0 || inumber === '0') { + return 0; + } + + // Handle special cases + if (['i', '+i', '1i', '+1i', '-i', '-1i', 'j', '+j', '1j', '+1j', '-j', '-1j'].indexOf(inumber) >= 0) { + return 0; + } + + // Lookup sign + var plus = inumber.indexOf('+'); + var minus = inumber.indexOf('-'); + if (plus === 0) { + plus = inumber.indexOf('+', 1); + } + if (minus === 0) { + minus = inumber.indexOf('-', 1); + } + + // Lookup imaginary unit + var last = inumber.substring(inumber.length - 1, inumber.length); + var unit = (last === 'i' || last === 'j'); + + if (plus >= 0 || minus >= 0) { + // Return error if imaginary unit is neither i nor j + if (!unit) { + return error.num; + } + + // Return real coefficient of complex number + if (plus >= 0) { + return (isNaN(inumber.substring(0, plus)) || isNaN(inumber.substring(plus + 1, inumber.length - 1))) ? + error.num : + Number(inumber.substring(0, plus)); + } else { + return (isNaN(inumber.substring(0, minus)) || isNaN(inumber.substring(minus + 1, inumber.length - 1))) ? + error.num : + Number(inumber.substring(0, minus)); + } + } else { + if (unit) { + return (isNaN(inumber.substring(0, inumber.length - 1))) ? error.num : 0; + } else { + return (isNaN(inumber)) ? error.num : inumber; + } + } + }; + + exports.IMSEC = function(inumber) { + // Return error if inumber is a logical value + if (inumber === true || inumber === false) { + return error.value; + } + + // Lookup real and imaginary coefficients using Formula.js [http://formulajs.org] + var x = exports.IMREAL(inumber); + var y = exports.IMAGINARY(inumber); + + if (utils.anyIsError(x, y)) { + return error.value; + } + + // Return secant of complex number + return exports.IMDIV('1', exports.IMCOS(inumber)); + }; + + exports.IMSECH = function(inumber) { + // Lookup real and imaginary coefficients using Formula.js [http://formulajs.org] + var x = exports.IMREAL(inumber); + var y = exports.IMAGINARY(inumber); + + if (utils.anyIsError(x, y)) { + return error.value; + } + + // Return hyperbolic secant of complex number + return exports.IMDIV('1', exports.IMCOSH(inumber)); + }; + + exports.IMSIN = function(inumber) { + // Lookup real and imaginary coefficients using Formula.js [http://formulajs.org] + var x = exports.IMREAL(inumber); + var y = exports.IMAGINARY(inumber); + + if (utils.anyIsError(x, y)) { + return error.value; + } + + // Lookup imaginary unit + var unit = inumber.substring(inumber.length - 1); + unit = (unit === 'i' || unit === 'j') ? unit : 'i'; + + // Return sine of complex number + return exports.COMPLEX(Math.sin(x) * (Math.exp(y) + Math.exp(-y)) / 2, Math.cos(x) * (Math.exp(y) - Math.exp(-y)) / 2, unit); + }; + + exports.IMSINH = function(inumber) { + // Lookup real and imaginary coefficients using Formula.js [http://formulajs.org] + var x = exports.IMREAL(inumber); + var y = exports.IMAGINARY(inumber); + + if (utils.anyIsError(x, y)) { + return error.value; + } + + // Lookup imaginary unit + var unit = inumber.substring(inumber.length - 1); + unit = (unit === 'i' || unit === 'j') ? unit : 'i'; + + // Return hyperbolic sine of complex number + return exports.COMPLEX(Math.cos(y) * (Math.exp(x) - Math.exp(-x)) / 2, Math.sin(y) * (Math.exp(x) + Math.exp(-x)) / 2, unit); + }; + + exports.IMSQRT = function(inumber) { + // Lookup real and imaginary coefficients using Formula.js [http://formulajs.org] + var x = exports.IMREAL(inumber); + var y = exports.IMAGINARY(inumber); + + if (utils.anyIsError(x, y)) { + return error.value; + } + + // Lookup imaginary unit + var unit = inumber.substring(inumber.length - 1); + unit = (unit === 'i' || unit === 'j') ? unit : 'i'; + + // Calculate power of modulus + var s = Math.sqrt(exports.IMABS(inumber)); + + // Calculate argument + var t = exports.IMARGUMENT(inumber); + + // Return exponential of complex number + return exports.COMPLEX(s * Math.cos(t / 2), s * Math.sin(t / 2), unit); + }; + + exports.IMCSC = function (inumber) { + // Return error if inumber is a logical value + if (inumber === true || inumber === false) { + return error.value; + } + + // Lookup real and imaginary coefficients using Formula.js [http://formulajs.org] + var x = exports.IMREAL(inumber); + var y = exports.IMAGINARY(inumber); + + // Return error if either coefficient is not a number + if (utils.anyIsError(x, y)) { + return error.num; + } + + // Return cosecant of complex number + return exports.IMDIV('1', exports.IMSIN(inumber)); + }; + + exports.IMCSCH = function (inumber) { + // Return error if inumber is a logical value + if (inumber === true || inumber === false) { + return error.value; + } + + // Lookup real and imaginary coefficients using Formula.js [http://formulajs.org] + var x = exports.IMREAL(inumber); + var y = exports.IMAGINARY(inumber); + + // Return error if either coefficient is not a number + if (utils.anyIsError(x, y)) { + return error.num; + } + + // Return hyperbolic cosecant of complex number + return exports.IMDIV('1', exports.IMSINH(inumber)); + }; + + exports.IMSUB = function(inumber1, inumber2) { + // Lookup real and imaginary coefficients using Formula.js [http://formulajs.org] + var a = this.IMREAL(inumber1); + var b = this.IMAGINARY(inumber1); + var c = this.IMREAL(inumber2); + var d = this.IMAGINARY(inumber2); + + if (utils.anyIsError(a, b, c, d)) { + return error.value; + } + + // Lookup imaginary unit + var unit1 = inumber1.substring(inumber1.length - 1); + var unit2 = inumber2.substring(inumber2.length - 1); + var unit = 'i'; + if (unit1 === 'j') { + unit = 'j'; + } else if (unit2 === 'j') { + unit = 'j'; + } + + // Return _ of two complex numbers + return this.COMPLEX(a - c, b - d, unit); + }; + + exports.IMSUM = function() { + var args = utils.flatten(arguments); + + // Initialize result + var result = args[0]; + + // Loop on all numbers + for (var i = 1; i < args.length; i++) { + // Lookup coefficients of two complex numbers + var a = this.IMREAL(result); + var b = this.IMAGINARY(result); + var c = this.IMREAL(args[i]); + var d = this.IMAGINARY(args[i]); + + if (utils.anyIsError(a, b, c, d)) { + return error.value; + } + + // Complute product of two complex numbers + result = this.COMPLEX(a + c, b + d); + } + + // Return sum of complex numbers + return result; + }; + + exports.IMTAN = function(inumber) { + // Return error if inumber is a logical value + if (inumber === true || inumber === false) { + return error.value; + } + + // Lookup real and imaginary coefficients using Formula.js [http://formulajs.org] + var x = exports.IMREAL(inumber); + var y = exports.IMAGINARY(inumber); + + if (utils.anyIsError(x, y)) { + return error.value; + } + + // Return tangent of complex number + return this.IMDIV(this.IMSIN(inumber), this.IMCOS(inumber)); + }; + + exports.OCT2BIN = function(number, places) { + // Return error if number is not hexadecimal or contains more than ten characters (10 digits) + if (!/^[0-7]{1,10}$/.test(number)) { + return error.num; + } + + // Check if number is negative + var negative = (number.length === 10 && number.substring(0, 1) === '7') ? true : false; + + // Convert octal number to decimal + var decimal = (negative) ? parseInt(number, 8) - 1073741824 : parseInt(number, 8); + + // Return error if number is lower than -512 or greater than 511 + if (decimal < -512 || decimal > 511) { + return error.num; + } + + // Ignore places and return a 10-character binary number if number is negative + if (negative) { + return '1' + text.REPT('0', 9 - (512 + decimal).toString(2).length) + (512 + decimal).toString(2); + } + + // Convert decimal number to binary + var result = decimal.toString(2); + + // Return binary number using the minimum number of characters necessary if places is undefined + if (typeof places === 'undefined') { + return result; + } else { + // Return error if places is nonnumeric + if (isNaN(places)) { + return error.value; + } + + // Return error if places is negative + if (places < 0) { + return error.num; + } + + // Truncate places in case it is not an integer + places = Math.floor(places); + + // Pad return value with leading 0s (zeros) if necessary (using Underscore.string) + return (places >= result.length) ? text.REPT('0', places - result.length) + result : error.num; + } + }; + + exports.OCT2DEC = function(number) { + // Return error if number is not octal or contains more than ten characters (10 digits) + if (!/^[0-7]{1,10}$/.test(number)) { + return error.num; + } + + // Convert octal number to decimal + var decimal = parseInt(number, 8); + + // Return decimal number + return (decimal >= 536870912) ? decimal - 1073741824 : decimal; + }; + + exports.OCT2HEX = function(number, places) { + // Return error if number is not octal or contains more than ten characters (10 digits) + if (!/^[0-7]{1,10}$/.test(number)) { + return error.num; + } + + // Convert octal number to decimal + var decimal = parseInt(number, 8); + + // Ignore places and return a 10-character octal number if number is negative + if (decimal >= 536870912) { + return 'ff' + (decimal + 3221225472).toString(16); + } + + // Convert decimal number to hexadecimal + var result = decimal.toString(16); + + // Return hexadecimal number using the minimum number of characters necessary if places is undefined + if (places === undefined) { + return result; + } else { + // Return error if places is nonnumeric + if (isNaN(places)) { + return error.value; + } + + // Return error if places is negative + if (places < 0) { + return error.num; + } + + // Truncate places in case it is not an integer + places = Math.floor(places); + + // Pad return value with leading 0s (zeros) if necessary (using Underscore.string) + return (places >= result.length) ? text.REPT('0', places - result.length) + result : error.num; + } + }; + +/***/ }, +/* 13 */ +/***/ function(module, exports, __webpack_require__) { + + var M = Math; + function _horner(arr, v) { return arr.reduce(function(z,w){return v * z + w;},0); }; + function _bessel_iter(x, n, f0, f1, sign) { + if(!sign) sign = -1; + var tdx = 2 / x, f2; + if(n === 0) return f0; + if(n === 1) return f1; + for(var o = 1; o != n; ++o) { + f2 = f1 * o * tdx + sign * f0; + f0 = f1; f1 = f2; + } + return f1; + } + function _bessel_wrap(bessel0, bessel1, name, nonzero, sign) { + return function bessel(x,n) { + if(n === 0) return bessel0(x); + if(n === 1) return bessel1(x); + if(n < 0) throw name + ': Order (' + n + ') must be nonnegative'; + if(nonzero == 1 && x === 0) throw name + ': Undefined when x == 0'; + if(nonzero == 2 && x <= 0) throw name + ': Undefined when x <= 0'; + var b0 = bessel0(x), b1 = bessel1(x); + return _bessel_iter(x, n, b0, b1, sign); + }; + } + var besselj = (function() { + var b0_a1a = [57568490574.0,-13362590354.0,651619640.7,-11214424.18,77392.33017,-184.9052456].reverse(); + var b0_a2a = [57568490411.0,1029532985.0,9494680.718,59272.64853,267.8532712,1.0].reverse(); + var b0_a1b = [1.0, -0.1098628627e-2, 0.2734510407e-4, -0.2073370639e-5, 0.2093887211e-6].reverse(); + var b0_a2b = [-0.1562499995e-1, 0.1430488765e-3, -0.6911147651e-5, 0.7621095161e-6, -0.934935152e-7].reverse(); + var W = 0.636619772; // 2 / Math.PI + + function bessel0(x) { + var a, a1, a2, y = x * x, xx = M.abs(x) - 0.785398164; + if(M.abs(x) < 8) { + a1 = _horner(b0_a1a, y); + a2 = _horner(b0_a2a, y); + a = a1/a2; + } + else { + y = 64 / y; + a1 = _horner(b0_a1b, y); + a2 = _horner(b0_a2b, y); + a = M.sqrt(W/M.abs(x))*(M.cos(xx)*a1-M.sin(xx)*a2*8/M.abs(x)); + } + return a; + } + var b1_a1a = [72362614232.0,-7895059235.0,242396853.1,-2972611.439, 15704.48260, -30.16036606].reverse(); + var b1_a2a = [144725228442.0, 2300535178.0, 18583304.74, 99447.43394, 376.9991397, 1.0].reverse(); + var b1_a1b = [1.0, 0.183105e-2, -0.3516396496e-4, 0.2457520174e-5, -0.240337019e-6].reverse(); + var b1_a2b = [0.04687499995, -0.2002690873e-3, 0.8449199096e-5, -0.88228987e-6, 0.105787412e-6].reverse(); + function bessel1(x) { + var a, a1, a2, y = x*x, xx = M.abs(x) - 2.356194491; + if(Math.abs(x)< 8) { + a1 = x*_horner(b1_a1a, y); + a2 = _horner(b1_a2a, y); + a = a1 / a2; + } else { + y = 64 / y; + a1=_horner(b1_a1b, y); + a2=_horner(b1_a2b, y); + a=M.sqrt(W/M.abs(x))*(M.cos(xx)*a1-M.sin(xx)*a2*8/M.abs(x)); + if(x < 0) a = -a; + } + return a; + } + return function besselj(x, n) { + n = Math.round(n); + if(n === 0) return bessel0(M.abs(x)); + if(n === 1) return bessel1(M.abs(x)); + if(n < 0) throw 'BESSELJ: Order (' + n + ') must be nonnegative'; + if(M.abs(x) === 0) return 0; + + var ret, j, tox = 2 / M.abs(x), m, jsum, sum, bjp, bj, bjm; + if(M.abs(x) > n) { + ret = _bessel_iter(x, n, bessel0(M.abs(x)), bessel1(M.abs(x)),-1); + } else { + m=2*M.floor((n+M.floor(M.sqrt(40*n)))/2); + jsum=0; + bjp=ret=sum=0.0; + bj=1.0; + for (j=m;j>0;j--) { + bjm=j*tox*bj-bjp; + bjp=bj; + bj=bjm; + if (M.abs(bj) > 1E10) { + bj *= 1E-10; + bjp *= 1E-10; + ret *= 1E-10; + sum *= 1E-10; + } + if (jsum) sum += bj; + jsum=!jsum; + if (j == n) ret=bjp; + } + sum=2.0*sum-bj; + ret /= sum; + } + return x < 0 && (n%2) ? -ret : ret; + }; + })(); + var bessely = (function() { + var b0_a1a = [-2957821389.0, 7062834065.0, -512359803.6, 10879881.29, -86327.92757, 228.4622733].reverse(); + var b0_a2a = [40076544269.0, 745249964.8, 7189466.438, 47447.26470, 226.1030244, 1.0].reverse(); + var b0_a1b = [1.0, -0.1098628627e-2, 0.2734510407e-4, -0.2073370639e-5, 0.2093887211e-6].reverse(); + var b0_a2b = [-0.1562499995e-1, 0.1430488765e-3, -0.6911147651e-5, 0.7621095161e-6, -0.934945152e-7].reverse(); + + var W = 0.636619772; + function bessel0(x) { + var a, a1, a2, y = x * x, xx = x - 0.785398164; + if(x < 8) { + a1 = _horner(b0_a1a, y); + a2 = _horner(b0_a2a, y); + a = a1/a2 + W * besselj(x,0) * M.log(x); + } else { + y = 64 / y; + a1 = _horner(b0_a1b, y); + a2 = _horner(b0_a2b, y); + a = M.sqrt(W/x)*(M.sin(xx)*a1+M.cos(xx)*a2*8/x); + } + return a; + } + + var b1_a1a = [-0.4900604943e13, 0.1275274390e13, -0.5153438139e11, 0.7349264551e9, -0.4237922726e7, 0.8511937935e4].reverse(); + var b1_a2a = [0.2499580570e14, 0.4244419664e12, 0.3733650367e10, 0.2245904002e8, 0.1020426050e6, 0.3549632885e3, 1].reverse(); + var b1_a1b = [1.0, 0.183105e-2, -0.3516396496e-4, 0.2457520174e-5, -0.240337019e-6].reverse(); + var b1_a2b = [0.04687499995, -0.2002690873e-3, 0.8449199096e-5, -0.88228987e-6, 0.105787412e-6].reverse(); + function bessel1(x) { + var a, a1, a2, y = x*x, xx = x - 2.356194491; + if(x < 8) { + a1 = x*_horner(b1_a1a, y); + a2 = _horner(b1_a2a, y); + a = a1/a2 + W * (besselj(x,1) * M.log(x) - 1 / x); + } else { + y = 64 / y; + a1=_horner(b1_a1b, y); + a2=_horner(b1_a2b, y); + a=M.sqrt(W/x)*(M.sin(xx)*a1+M.cos(xx)*a2*8/x); + } + return a; + } + + return _bessel_wrap(bessel0, bessel1, 'BESSELY', 1, -1); + })(); + var besseli = (function() { + var b0_a = [1.0, 3.5156229, 3.0899424, 1.2067492, 0.2659732, 0.360768e-1, 0.45813e-2].reverse(); + var b0_b = [0.39894228, 0.1328592e-1, 0.225319e-2, -0.157565e-2, 0.916281e-2, -0.2057706e-1, 0.2635537e-1, -0.1647633e-1, 0.392377e-2].reverse(); + function bessel0(x) { + if(x <= 3.75) return _horner(b0_a, x*x/(3.75*3.75)); + return M.exp(M.abs(x))/M.sqrt(M.abs(x))*_horner(b0_b, 3.75/M.abs(x)); + } + + var b1_a = [0.5, 0.87890594, 0.51498869, 0.15084934, 0.2658733e-1, 0.301532e-2, 0.32411e-3].reverse(); + var b1_b = [0.39894228, -0.3988024e-1, -0.362018e-2, 0.163801e-2, -0.1031555e-1, 0.2282967e-1, -0.2895312e-1, 0.1787654e-1, -0.420059e-2].reverse(); + function bessel1(x) { + if(x < 3.75) return x * _horner(b1_a, x*x/(3.75*3.75)); + return (x < 0 ? -1 : 1) * M.exp(M.abs(x))/M.sqrt(M.abs(x))*_horner(b1_b, 3.75/M.abs(x)); + } + + return function besseli(x, n) { + n = Math.round(n); + if(n === 0) return bessel0(x); + if(n == 1) return bessel1(x); + if(n < 0) throw 'BESSELI Order (' + n + ') must be nonnegative'; + if(M.abs(x) === 0) return 0; + + var ret, j, tox = 2 / M.abs(x), m, bip, bi, bim; + m=2*M.round((n+M.round(M.sqrt(40*n)))/2); + bip=ret=0.0; + bi=1.0; + for (j=m;j>0;j--) { + bim=j*tox*bi + bip; + bip=bi; bi=bim; + if (M.abs(bi) > 1E10) { + bi *= 1E-10; + bip *= 1E-10; + ret *= 1E-10; + } + if(j == n) ret = bip; + } + ret *= besseli(x, 0) / bi; + return x < 0 && (n%2) ? -ret : ret; + }; + + })(); + + var besselk = (function() { + var b0_a = [-0.57721566, 0.42278420, 0.23069756, 0.3488590e-1, 0.262698e-2, 0.10750e-3, 0.74e-5].reverse(); + var b0_b = [1.25331414, -0.7832358e-1, 0.2189568e-1, -0.1062446e-1, 0.587872e-2, -0.251540e-2, 0.53208e-3].reverse(); + function bessel0(x) { + if(x <= 2) return -M.log(x/2)*besseli(x,0) + _horner(b0_a, x*x/4); + return M.exp(-x)/M.sqrt(x)*_horner(b0_b, 2/x); + } + + var b1_a = [1.0, 0.15443144, -0.67278579, -0.18156897, -0.1919402e-1, -0.110404e-2, -0.4686e-4].reverse(); + var b1_b = [1.25331414, 0.23498619, -0.3655620e-1, 0.1504268e-1, -0.780353e-2, 0.325614e-2, -0.68245e-3].reverse(); + function bessel1(x) { + if(x <= 2) return M.log(x/2)*besseli(x,1) + (1/x)*_horner(b1_a, x*x/4); + return M.exp(-x)/M.sqrt(x)*_horner(b1_b, 2/x); + } + + return _bessel_wrap(bessel0, bessel1, 'BESSELK', 2, 1); + })(); + if(true) { + exports.besselj = besselj; + exports.bessely = bessely; + exports.besseli = besseli; + exports.besselk = besselk; + } + + + +/***/ }, +/* 14 */ +/***/ function(module, exports, __webpack_require__) { + + var error = __webpack_require__(5); + var utils = __webpack_require__(4); + + var d1900 = new Date(1900, 0, 1); + var WEEK_STARTS = [ + undefined, + 0, + 1, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + 1, + 2, + 3, + 4, + 5, + 6, + 0 + ]; + var WEEK_TYPES = [ + [], + [1, 2, 3, 4, 5, 6, 7], + [7, 1, 2, 3, 4, 5, 6], + [6, 0, 1, 2, 3, 4, 5], + [], + [], + [], + [], + [], + [], + [], + [7, 1, 2, 3, 4, 5, 6], + [6, 7, 1, 2, 3, 4, 5], + [5, 6, 7, 1, 2, 3, 4], + [4, 5, 6, 7, 1, 2, 3], + [3, 4, 5, 6, 7, 1, 2], + [2, 3, 4, 5, 6, 7, 1], + [1, 2, 3, 4, 5, 6, 7] + ]; + var WEEKEND_TYPES = [ + [], + [6, 0], + [0, 1], + [1, 2], + [2, 3], + [3, 4], + [4, 5], + [5, 6], + undefined, + undefined, + undefined, [0, 0], + [1, 1], + [2, 2], + [3, 3], + [4, 4], + [5, 5], + [6, 6] + ]; + + exports.DATE = function(year, month, day) { + year = utils.parseNumber(year); + month = utils.parseNumber(month); + day = utils.parseNumber(day); + if (utils.anyIsError(year, month, day)) { + return error.value; + } + if (year < 0 || month < 0 || day < 0) { + return error.num; + } + var date = new Date(year, month - 1, day); + return date; + }; + + exports.DATEVALUE = function(date_text) { + if (typeof date_text !== 'string') { + return error.value; + } + var date = Date.parse(date_text); + if (isNaN(date)) { + return error.value; + } + if (date <= -2203891200000) { + return (date - d1900) / 86400000 + 1; + } + return (date - d1900) / 86400000 + 2; + }; + + exports.DAY = function(serial_number) { + var date = utils.parseDate(serial_number); + if (date instanceof Error) { + return date; + } + return date.getDate(); + }; + + exports.DAYS = function(end_date, start_date) { + end_date = utils.parseDate(end_date); + start_date = utils.parseDate(start_date); + if (end_date instanceof Error) { + return end_date; + } + if (start_date instanceof Error) { + return start_date; + } + return serial(end_date) - serial(start_date); + }; + + exports.DAYS360 = function(start_date, end_date, method) { + method = utils.parseBool(method); + start_date = utils.parseDate(start_date); + end_date = utils.parseDate(end_date); + if (start_date instanceof Error) { + return start_date; + } + if (end_date instanceof Error) { + return end_date; + } + if (method instanceof Error) { + return method; + } + var sm = start_date.getMonth(); + var em = end_date.getMonth(); + var sd, ed; + if (method) { + sd = start_date.getDate() === 31 ? 30 : start_date.getDate(); + ed = end_date.getDate() === 31 ? 30 : end_date.getDate(); + } else { + var smd = new Date(start_date.getFullYear(), sm + 1, 0).getDate(); + var emd = new Date(end_date.getFullYear(), em + 1, 0).getDate(); + sd = start_date.getDate() === smd ? 30 : start_date.getDate(); + if (end_date.getDate() === emd) { + if (sd < 30) { + em++; + ed = 1; + } else { + ed = 30; + } + } else { + ed = end_date.getDate(); + } + } + return 360 * (end_date.getFullYear() - start_date.getFullYear()) + + 30 * (em - sm) + (ed - sd); + }; + + exports.EDATE = function(start_date, months) { + start_date = utils.parseDate(start_date); + if (start_date instanceof Error) { + return start_date; + } + if (isNaN(months)) { + return error.value; + } + months = parseInt(months, 10); + start_date.setMonth(start_date.getMonth() + months); + return serial(start_date); + }; + + exports.EOMONTH = function(start_date, months) { + start_date = utils.parseDate(start_date); + if (start_date instanceof Error) { + return start_date; + } + if (isNaN(months)) { + return error.value; + } + months = parseInt(months, 10); + return serial(new Date(start_date.getFullYear(), start_date.getMonth() + months + 1, 0)); + }; + + exports.HOUR = function(serial_number) { + serial_number = utils.parseDate(serial_number); + if (serial_number instanceof Error) { + return serial_number; + } + return serial_number.getHours(); + }; + + exports.INTERVAL = function (second) { + if (typeof second !== 'number' && typeof second !== 'string') { + return error.value; + } else { + second = parseInt(second, 10); + } + + var year = Math.floor(second/946080000); + second = second%946080000; + var month = Math.floor(second/2592000); + second = second%2592000; + var day = Math.floor(second/86400); + second = second%86400; + + var hour = Math.floor(second/3600); + second = second%3600; + var min = Math.floor(second/60); + second = second%60; + var sec = second; + + year = (year > 0) ? year + 'Y' : ''; + month = (month > 0) ? month + 'M' : ''; + day = (day > 0) ? day + 'D' : ''; + hour = (hour > 0) ? hour + 'H' : ''; + min = (min > 0) ? min + 'M' : ''; + sec = (sec > 0) ? sec + 'S' : ''; + + return 'P' + year + month + day + + 'T' + hour + min + sec; + }; + + exports.ISOWEEKNUM = function(date) { + date = utils.parseDate(date); + if (date instanceof Error) { + return date; + } + + date.setHours(0, 0, 0); + date.setDate(date.getDate() + 4 - (date.getDay() || 7)); + var yearStart = new Date(date.getFullYear(), 0, 1); + return Math.ceil((((date - yearStart) / 86400000) + 1) / 7); + }; + + exports.MINUTE = function(serial_number) { + serial_number = utils.parseDate(serial_number); + if (serial_number instanceof Error) { + return serial_number; + } + return serial_number.getMinutes(); + }; + + exports.MONTH = function(serial_number) { + serial_number = utils.parseDate(serial_number); + if (serial_number instanceof Error) { + return serial_number; + } + return serial_number.getMonth() + 1; + }; + + exports.NETWORKDAYS = function(start_date, end_date, holidays) { + return this.NETWORKDAYS.INTL(start_date, end_date, 1, holidays); + }; + + exports.NETWORKDAYS.INTL = function(start_date, end_date, weekend, holidays) { + start_date = utils.parseDate(start_date); + if (start_date instanceof Error) { + return start_date; + } + end_date = utils.parseDate(end_date); + if (end_date instanceof Error) { + return end_date; + } + if (weekend === undefined) { + weekend = WEEKEND_TYPES[1]; + } else { + weekend = WEEKEND_TYPES[weekend]; + } + if (!(weekend instanceof Array)) { + return error.value; + } + if (holidays === undefined) { + holidays = []; + } else if (!(holidays instanceof Array)) { + holidays = [holidays]; + } + for (var i = 0; i < holidays.length; i++) { + var h = utils.parseDate(holidays[i]); + if (h instanceof Error) { + return h; + } + holidays[i] = h; + } + var days = (end_date - start_date) / (1000 * 60 * 60 * 24) + 1; + var total = days; + var day = start_date; + for (i = 0; i < days; i++) { + var d = (new Date().getTimezoneOffset() > 0) ? day.getUTCDay() : day.getDay(); + var dec = false; + if (d === weekend[0] || d === weekend[1]) { + dec = true; + } + for (var j = 0; j < holidays.length; j++) { + var holiday = holidays[j]; + if (holiday.getDate() === day.getDate() && + holiday.getMonth() === day.getMonth() && + holiday.getFullYear() === day.getFullYear()) { + dec = true; + break; + } + } + if (dec) { + total--; + } + day.setDate(day.getDate() + 1); + } + return total; + }; + + exports.NOW = function() { + return new Date(); + }; + + exports.SECOND = function(serial_number) { + serial_number = utils.parseDate(serial_number); + if (serial_number instanceof Error) { + return serial_number; + } + return serial_number.getSeconds(); + }; + + exports.TIME = function(hour, minute, second) { + hour = utils.parseNumber(hour); + minute = utils.parseNumber(minute); + second = utils.parseNumber(second); + if (utils.anyIsError(hour, minute, second)) { + return error.value; + } + if (hour < 0 || minute < 0 || second < 0) { + return error.num; + } + return (3600 * hour + 60 * minute + second) / 86400; + }; + + exports.TIMEVALUE = function(time_text) { + time_text = utils.parseDate(time_text); + if (time_text instanceof Error) { + return time_text; + } + return (3600 * time_text.getHours() + + 60 * time_text.getMinutes() + + time_text.getSeconds()) / 86400; + }; + + exports.TODAY = function() { + return new Date(); + }; + + exports.WEEKDAY = function(serial_number, return_type) { + serial_number = utils.parseDate(serial_number); + if (serial_number instanceof Error) { + return serial_number; + } + if (return_type === undefined) { + return_type = 1; + } + var day = serial_number.getDay(); + return WEEK_TYPES[return_type][day]; + }; + + exports.WEEKNUM = function(serial_number, return_type) { + serial_number = utils.parseDate(serial_number); + if (serial_number instanceof Error) { + return serial_number; + } + if (return_type === undefined) { + return_type = 1; + } + if (return_type === 21) { + return this.ISOWEEKNUM(serial_number); + } + var week_start = WEEK_STARTS[return_type]; + var jan = new Date(serial_number.getFullYear(), 0, 1); + var inc = jan.getDay() < week_start ? 1 : 0; + jan -= Math.abs(jan.getDay() - week_start) * 24 * 60 * 60 * 1000; + return Math.floor(((serial_number - jan) / (1000 * 60 * 60 * 24)) / 7 + 1) + inc; + }; + + exports.WORKDAY = function(start_date, days, holidays) { + return this.WORKDAY.INTL(start_date, days, 1, holidays); + }; + + exports.WORKDAY.INTL = function(start_date, days, weekend, holidays) { + start_date = utils.parseDate(start_date); + if (start_date instanceof Error) { + return start_date; + } + days = utils.parseNumber(days); + if (days instanceof Error) { + return days; + } + if (days < 0) { + return error.num; + } + if (weekend === undefined) { + weekend = WEEKEND_TYPES[1]; + } else { + weekend = WEEKEND_TYPES[weekend]; + } + if (!(weekend instanceof Array)) { + return error.value; + } + if (holidays === undefined) { + holidays = []; + } else if (!(holidays instanceof Array)) { + holidays = [holidays]; + } + for (var i = 0; i < holidays.length; i++) { + var h = utils.parseDate(holidays[i]); + if (h instanceof Error) { + return h; + } + holidays[i] = h; + } + var d = 0; + while (d < days) { + start_date.setDate(start_date.getDate() + 1); + var day = start_date.getDay(); + if (day === weekend[0] || day === weekend[1]) { + continue; + } + for (var j = 0; j < holidays.length; j++) { + var holiday = holidays[j]; + if (holiday.getDate() === start_date.getDate() && + holiday.getMonth() === start_date.getMonth() && + holiday.getFullYear() === start_date.getFullYear()) { + d--; + break; + } + } + d++; + } + return start_date; + }; + + exports.YEAR = function(serial_number) { + serial_number = utils.parseDate(serial_number); + if (serial_number instanceof Error) { + return serial_number; + } + return serial_number.getFullYear(); + }; + + function isLeapYear(year) { + return new Date(year, 1, 29).getMonth() === 1; + } + + // TODO : Use DAYS ? + function daysBetween(start_date, end_date) { + return Math.ceil((end_date - start_date) / 1000 / 60 / 60 / 24); + } + + exports.YEARFRAC = function(start_date, end_date, basis) { + start_date = utils.parseDate(start_date); + if (start_date instanceof Error) { + return start_date; + } + end_date = utils.parseDate(end_date); + if (end_date instanceof Error) { + return end_date; + } + + basis = basis || 0; + var sd = start_date.getDate(); + var sm = start_date.getMonth() + 1; + var sy = start_date.getFullYear(); + var ed = end_date.getDate(); + var em = end_date.getMonth() + 1; + var ey = end_date.getFullYear(); + + switch (basis) { + case 0: + // US (NASD) 30/360 + if (sd === 31 && ed === 31) { + sd = 30; + ed = 30; + } else if (sd === 31) { + sd = 30; + } else if (sd === 30 && ed === 31) { + ed = 30; + } + return ((ed + em * 30 + ey * 360) - (sd + sm * 30 + sy * 360)) / 360; + case 1: + // Actual/actual + var feb29Between = function(date1, date2) { + var year1 = date1.getFullYear(); + var mar1year1 = new Date(year1, 2, 1); + if (isLeapYear(year1) && date1 < mar1year1 && date2 >= mar1year1) { + return true; + } + var year2 = date2.getFullYear(); + var mar1year2 = new Date(year2, 2, 1); + return (isLeapYear(year2) && date2 >= mar1year2 && date1 < mar1year2); + }; + var ylength = 365; + if (sy === ey || ((sy + 1) === ey) && ((sm > em) || ((sm === em) && (sd >= ed)))) { + if ((sy === ey && isLeapYear(sy)) || + feb29Between(start_date, end_date) || + (em === 1 && ed === 29)) { + ylength = 366; + } + return daysBetween(start_date, end_date) / ylength; + } + var years = (ey - sy) + 1; + var days = (new Date(ey + 1, 0, 1) - new Date(sy, 0, 1)) / 1000 / 60 / 60 / 24; + var average = days / years; + return daysBetween(start_date, end_date) / average; + case 2: + // Actual/360 + return daysBetween(start_date, end_date) / 360; + case 3: + // Actual/365 + return daysBetween(start_date, end_date) / 365; + case 4: + // European 30/360 + return ((ed + em * 30 + ey * 360) - (sd + sm * 30 + sy * 360)) / 360; + } + }; + + function serial(date) { + var addOn = (date > -2203891200000)?2:1; + return (date - d1900) / 86400000 + addOn; + } + +/***/ }, +/* 15 */ +/***/ function(module, exports, __webpack_require__) { + + var error = __webpack_require__(5); + var stats = __webpack_require__(6); + var maths = __webpack_require__(2); + var utils = __webpack_require__(4); + + function compact(array) { + if (!array) { return array; } + var result = []; + for (var i = 0; i < array.length; ++i) { + if (!array[i]) { continue; } + result.push(array[i]); + } + return result; + } + + exports.FINDFIELD = function(database, title) { + var index = null; + for (var i = 0; i < database.length; i++) { + if (database[i][0] === title) { + index = i; + break; + } + } + + // Return error if the input field title is incorrect + if (index == null) { + return error.value; + } + return index; + }; + + function findResultIndex(database, criterias) { + var matches = {}; + for (var i = 1; i < database[0].length; ++i) { + matches[i] = true; + } + var maxCriteriaLength = criterias[0].length; + for (i = 1; i < criterias.length; ++i) { + if (criterias[i].length > maxCriteriaLength) { + maxCriteriaLength = criterias[i].length; + } + } + + for (var k = 1; k < database.length; ++k) { + for (var l = 1; l < database[k].length; ++l) { + var currentCriteriaResult = false; + var hasMatchingCriteria = false; + for (var j = 0; j < criterias.length; ++j) { + var criteria = criterias[j]; + if (criteria.length < maxCriteriaLength) { + continue; + } + + var criteriaField = criteria[0]; + if (database[k][0] !== criteriaField) { + continue; + } + hasMatchingCriteria = true; + for (var p = 1; p < criteria.length; ++p) { + currentCriteriaResult = currentCriteriaResult || eval(database[k][l] + criteria[p]); // jshint ignore:line + } + } + if (hasMatchingCriteria) { + matches[l] = matches[l] && currentCriteriaResult; + } + } + } + + var result = []; + for (var n = 0; n < database[0].length; ++n) { + if (matches[n]) { + result.push(n - 1); + } + } + return result; + } + + // Database functions + exports.DAVERAGE = function(database, field, criteria) { + // Return error if field is not a number and not a string + if (isNaN(field) && (typeof field !== "string")) { + return error.value; + } + var resultIndexes = findResultIndex(database, criteria); + var targetFields = []; + if (typeof field === "string") { + var index = exports.FINDFIELD(database, field); + targetFields = utils.rest(database[index]); + } else { + targetFields = utils.rest(database[field]); + } + var sum = 0; + for (var i = 0; i < resultIndexes.length; i++) { + sum += targetFields[resultIndexes[i]]; + } + return resultIndexes.length === 0 ? error.div0 : sum / resultIndexes.length; + }; + + exports.DCOUNT = function(database, field, criteria) { + // Return error if field is not a number and not a string + if (isNaN(field) && (typeof field !== "string")) { + return error.value; + } + var resultIndexes = findResultIndex(database, criteria); + var targetFields = []; + if (typeof field === "string") { + var index = exports.FINDFIELD(database, field); + targetFields = utils.rest(database[index]); + } else { + targetFields = utils.rest(database[field]); + } + var targetValues = []; + for (var i = 0; i < resultIndexes.length; i++) { + targetValues[i] = targetFields[resultIndexes[i]]; + } + return stats.COUNT(targetValues); + }; + + exports.DCOUNTA = function(database, field, criteria) { + // Return error if field is not a number and not a string + if (isNaN(field) && (typeof field !== "string")) { + return error.value; + } + var resultIndexes = findResultIndex(database, criteria); + var targetFields = []; + if (typeof field === "string") { + var index = exports.FINDFIELD(database, field); + targetFields = utils.rest(database[index]); + } else { + targetFields = utils.rest(database[field]); + } + var targetValues = []; + for (var i = 0; i < resultIndexes.length; i++) { + targetValues[i] = targetFields[resultIndexes[i]]; + } + return stats.COUNTA(targetValues); + }; + + exports.DGET = function(database, field, criteria) { + // Return error if field is not a number and not a string + if (isNaN(field) && (typeof field !== "string")) { + return error.value; + } + var resultIndexes = findResultIndex(database, criteria); + var targetFields = []; + if (typeof field === "string") { + var index = exports.FINDFIELD(database, field); + targetFields = utils.rest(database[index]); + } else { + targetFields = utils.rest(database[field]); + } + // Return error if no record meets the criteria + if (resultIndexes.length === 0) { + return error.value; + } + // Returns the #NUM! error value because more than one record meets the + // criteria + if (resultIndexes.length > 1) { + return error.num; + } + + return targetFields[resultIndexes[0]]; + }; + + exports.DMAX = function(database, field, criteria) { + // Return error if field is not a number and not a string + if (isNaN(field) && (typeof field !== "string")) { + return error.value; + } + var resultIndexes = findResultIndex(database, criteria); + var targetFields = []; + if (typeof field === "string") { + var index = exports.FINDFIELD(database, field); + targetFields = utils.rest(database[index]); + } else { + targetFields = utils.rest(database[field]); + } + var maxValue = targetFields[resultIndexes[0]]; + for (var i = 1; i < resultIndexes.length; i++) { + if (maxValue < targetFields[resultIndexes[i]]) { + maxValue = targetFields[resultIndexes[i]]; + } + } + return maxValue; + }; + + exports.DMIN = function(database, field, criteria) { + // Return error if field is not a number and not a string + if (isNaN(field) && (typeof field !== "string")) { + return error.value; + } + var resultIndexes = findResultIndex(database, criteria); + var targetFields = []; + if (typeof field === "string") { + var index = exports.FINDFIELD(database, field); + targetFields = utils.rest(database[index]); + } else { + targetFields = utils.rest(database[field]); + } + var minValue = targetFields[resultIndexes[0]]; + for (var i = 1; i < resultIndexes.length; i++) { + if (minValue > targetFields[resultIndexes[i]]) { + minValue = targetFields[resultIndexes[i]]; + } + } + return minValue; + }; + + exports.DPRODUCT = function(database, field, criteria) { + // Return error if field is not a number and not a string + if (isNaN(field) && (typeof field !== "string")) { + return error.value; + } + var resultIndexes = findResultIndex(database, criteria); + var targetFields = []; + if (typeof field === "string") { + var index = exports.FINDFIELD(database, field); + targetFields = utils.rest(database[index]); + } else { + targetFields = utils.rest(database[field]); + } + var targetValues = []; + for (var i = 0; i < resultIndexes.length; i++) { + targetValues[i] = targetFields[resultIndexes[i]]; + } + targetValues = compact(targetValues); + var result = 1; + for (i = 0; i < targetValues.length; i++) { + result *= targetValues[i]; + } + return result; + }; + + exports.DSTDEV = function(database, field, criteria) { + // Return error if field is not a number and not a string + if (isNaN(field) && (typeof field !== "string")) { + return error.value; + } + var resultIndexes = findResultIndex(database, criteria); + var targetFields = []; + if (typeof field === "string") { + var index = exports.FINDFIELD(database, field); + targetFields = utils.rest(database[index]); + } else { + targetFields = utils.rest(database[field]); + } + var targetValues = []; + for (var i = 0; i < resultIndexes.length; i++) { + targetValues[i] = targetFields[resultIndexes[i]]; + } + targetValues = compact(targetValues); + return stats.STDEV.S(targetValues); + }; + + exports.DSTDEVP = function(database, field, criteria) { + // Return error if field is not a number and not a string + if (isNaN(field) && (typeof field !== "string")) { + return error.value; + } + var resultIndexes = findResultIndex(database, criteria); + var targetFields = []; + if (typeof field === "string") { + var index = exports.FINDFIELD(database, field); + targetFields = utils.rest(database[index]); + } else { + targetFields = utils.rest(database[field]); + } + var targetValues = []; + for (var i = 0; i < resultIndexes.length; i++) { + targetValues[i] = targetFields[resultIndexes[i]]; + } + targetValues = compact(targetValues); + return stats.STDEV.P(targetValues); + }; + + exports.DSUM = function(database, field, criteria) { + // Return error if field is not a number and not a string + if (isNaN(field) && (typeof field !== "string")) { + return error.value; + } + var resultIndexes = findResultIndex(database, criteria); + var targetFields = []; + if (typeof field === "string") { + var index = exports.FINDFIELD(database, field); + targetFields = utils.rest(database[index]); + } else { + targetFields = utils.rest(database[field]); + } + var targetValues = []; + for (var i = 0; i < resultIndexes.length; i++) { + targetValues[i] = targetFields[resultIndexes[i]]; + } + return maths.SUM(targetValues); + }; + + exports.DVAR = function(database, field, criteria) { + // Return error if field is not a number and not a string + if (isNaN(field) && (typeof field !== "string")) { + return error.value; + } + var resultIndexes = findResultIndex(database, criteria); + var targetFields = []; + if (typeof field === "string") { + var index = exports.FINDFIELD(database, field); + targetFields = utils.rest(database[index]); + } else { + targetFields = utils.rest(database[field]); + } + var targetValues = []; + for (var i = 0; i < resultIndexes.length; i++) { + targetValues[i] = targetFields[resultIndexes[i]]; + } + return stats.VAR.S(targetValues); + }; + + exports.DVARP = function(database, field, criteria) { + // Return error if field is not a number and not a string + if (isNaN(field) && (typeof field !== "string")) { + return error.value; + } + var resultIndexes = findResultIndex(database, criteria); + var targetFields = []; + if (typeof field === "string") { + var index = exports.FINDFIELD(database, field); + targetFields = utils.rest(database[index]); + } else { + targetFields = utils.rest(database[field]); + } + var targetValues = []; + for (var i = 0; i < resultIndexes.length; i++) { + targetValues[i] = targetFields[resultIndexes[i]]; + } + return stats.VAR.P(targetValues); + }; + + +/***/ }, +/* 16 */ +/***/ function(module, exports, __webpack_require__) { + + var error = __webpack_require__(5); + var utils = __webpack_require__(4); + var information = __webpack_require__(11); + + exports.AND = function() { + var args = utils.flatten(arguments); + var result = true; + for (var i = 0; i < args.length; i++) { + if (!args[i]) { + result = false; + } + } + return result; + }; + + exports.CHOOSE = function() { + if (arguments.length < 2) { + return error.na; + } + + var index = arguments[0]; + if (index < 1 || index > 254) { + return error.value; + } + + if (arguments.length < index + 1) { + return error.value; + } + + return arguments[index]; + }; + + exports.FALSE = function() { + return false; + }; + + exports.IF = function(test, then_value, otherwise_value) { + return test ? then_value : otherwise_value; + }; + + exports.IFERROR = function(value, valueIfError) { + if (information.ISERROR(value)) { + return valueIfError; + } + return value; + }; + + exports.IFNA = function(value, value_if_na) { + return value === error.na ? value_if_na : value; + }; + + exports.NOT = function(logical) { + return !logical; + }; + + exports.OR = function() { + var args = utils.flatten(arguments); + var result = false; + for (var i = 0; i < args.length; i++) { + if (args[i]) { + result = true; + } + } + return result; + }; + + exports.TRUE = function() { + return true; + }; + + exports.XOR = function() { + var args = utils.flatten(arguments); + var result = 0; + for (var i = 0; i < args.length; i++) { + if (args[i]) { + result++; + } + } + return (Math.floor(Math.abs(result)) & 1) ? true : false; + }; + + exports.SWITCH = function () { + var result; + if (arguments.length > 0) { + var targetValue = arguments[0]; + var argc = arguments.length - 1; + var switchCount = Math.floor(argc / 2); + var switchSatisfied = false; + var defaultClause = argc % 2 === 0 ? null : arguments[arguments.length - 1]; + + if (switchCount) { + for (var index = 0; index < switchCount; index++) { + if (targetValue === arguments[index * 2 + 1]) { + result = arguments[index * 2 + 2]; + switchSatisfied = true; + break; + } + } + } + + if (!switchSatisfied && defaultClause) { + result = defaultClause; + } + } + + return result; + }; + + +/***/ }, +/* 17 */ +/***/ function(module, exports, __webpack_require__) { + + var error = __webpack_require__(5); + var dateTime = __webpack_require__(14); + var utils = __webpack_require__(4); + + function validDate(d) { + return d && d.getTime && !isNaN(d.getTime()); + } + + function ensureDate(d) { + return (d instanceof Date)?d:new Date(d); + } + + exports.ACCRINT = function(issue, first, settlement, rate, par, frequency, basis) { + // Return error if either date is invalid + issue = ensureDate(issue); + first = ensureDate(first); + settlement = ensureDate(settlement); + if (!validDate(issue) || !validDate(first) || !validDate(settlement)) { + return '#VALUE!'; + } + + // Return error if either rate or par are lower than or equal to zero + if (rate <= 0 || par <= 0) { + return '#NUM!'; + } + + // Return error if frequency is neither 1, 2, or 4 + if ([1, 2, 4].indexOf(frequency) === -1) { + return '#NUM!'; + } + + // Return error if basis is neither 0, 1, 2, 3, or 4 + if ([0, 1, 2, 3, 4].indexOf(basis) === -1) { + return '#NUM!'; + } + + // Return error if settlement is before or equal to issue + if (settlement <= issue) { + return '#NUM!'; + } + + // Set default values + par = par || 0; + basis = basis || 0; + + // Compute accrued interest + return par * rate * dateTime.YEARFRAC(issue, settlement, basis); + }; + + // TODO + exports.ACCRINTM = function() { + throw new Error('ACCRINTM is not implemented'); + }; + + // TODO + exports.AMORDEGRC = function() { + throw new Error('AMORDEGRC is not implemented'); + }; + + // TODO + exports.AMORLINC = function() { + throw new Error('AMORLINC is not implemented'); + }; + + // TODO + exports.COUPDAYBS = function() { + throw new Error('COUPDAYBS is not implemented'); + }; + + // TODO + exports.COUPDAYS = function() { + throw new Error('COUPDAYS is not implemented'); + }; + + // TODO + exports.COUPDAYSNC = function() { + throw new Error('COUPDAYSNC is not implemented'); + }; + + // TODO + exports.COUPNCD = function() { + throw new Error('COUPNCD is not implemented'); + }; + + // TODO + exports.COUPNUM = function() { + throw new Error('COUPNUM is not implemented'); + }; + + // TODO + exports.COUPPCD = function() { + throw new Error('COUPPCD is not implemented'); + }; + + exports.CUMIPMT = function(rate, periods, value, start, end, type) { + // Credits: algorithm inspired by Apache OpenOffice + // Credits: Hannes Stiebitzhofer for the translations of function and variable names + // Requires exports.FV() and exports.PMT() from exports.js [http://stoic.com/exports/] + + rate = utils.parseNumber(rate); + periods = utils.parseNumber(periods); + value = utils.parseNumber(value); + if (utils.anyIsError(rate, periods, value)) { + return error.value; + } + + // Return error if either rate, periods, or value are lower than or equal to zero + if (rate <= 0 || periods <= 0 || value <= 0) { + return error.num; + } + + // Return error if start < 1, end < 1, or start > end + if (start < 1 || end < 1 || start > end) { + return error.num; + } + + // Return error if type is neither 0 nor 1 + if (type !== 0 && type !== 1) { + return error.num; + } + + // Compute cumulative interest + var payment = exports.PMT(rate, periods, value, 0, type); + var interest = 0; + + if (start === 1) { + if (type === 0) { + interest = -value; + start++; + } + } + + for (var i = start; i <= end; i++) { + if (type === 1) { + interest += exports.FV(rate, i - 2, payment, value, 1) - payment; + } else { + interest += exports.FV(rate, i - 1, payment, value, 0); + } + } + interest *= rate; + + // Return cumulative interest + return interest; + }; + + exports.CUMPRINC = function(rate, periods, value, start, end, type) { + // Credits: algorithm inspired by Apache OpenOffice + // Credits: Hannes Stiebitzhofer for the translations of function and variable names + + rate = utils.parseNumber(rate); + periods = utils.parseNumber(periods); + value = utils.parseNumber(value); + if (utils.anyIsError(rate, periods, value)) { + return error.value; + } + + // Return error if either rate, periods, or value are lower than or equal to zero + if (rate <= 0 || periods <= 0 || value <= 0) { + return error.num; + } + + // Return error if start < 1, end < 1, or start > end + if (start < 1 || end < 1 || start > end) { + return error.num; + } + + // Return error if type is neither 0 nor 1 + if (type !== 0 && type !== 1) { + return error.num; + } + + // Compute cumulative principal + var payment = exports.PMT(rate, periods, value, 0, type); + var principal = 0; + if (start === 1) { + if (type === 0) { + principal = payment + value * rate; + } else { + principal = payment; + } + start++; + } + for (var i = start; i <= end; i++) { + if (type > 0) { + principal += payment - (exports.FV(rate, i - 2, payment, value, 1) - payment) * rate; + } else { + principal += payment - exports.FV(rate, i - 1, payment, value, 0) * rate; + } + } + + // Return cumulative principal + return principal; + }; + + exports.DB = function(cost, salvage, life, period, month) { + // Initialize month + month = (month === undefined) ? 12 : month; + + cost = utils.parseNumber(cost); + salvage = utils.parseNumber(salvage); + life = utils.parseNumber(life); + period = utils.parseNumber(period); + month = utils.parseNumber(month); + if (utils.anyIsError(cost, salvage, life, period, month)) { + return error.value; + } + + // Return error if any of the parameters is negative + if (cost < 0 || salvage < 0 || life < 0 || period < 0) { + return error.num; + } + + // Return error if month is not an integer between 1 and 12 + if ([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12].indexOf(month) === -1) { + return error.num; + } + + // Return error if period is greater than life + if (period > life) { + return error.num; + } + + // Return 0 (zero) if salvage is greater than or equal to cost + if (salvage >= cost) { + return 0; + } + + // Rate is rounded to three decimals places + var rate = (1 - Math.pow(salvage / cost, 1 / life)).toFixed(3); + + // Compute initial depreciation + var initial = cost * rate * month / 12; + + // Compute total depreciation + var total = initial; + var current = 0; + var ceiling = (period === life) ? life - 1 : period; + for (var i = 2; i <= ceiling; i++) { + current = (cost - total) * rate; + total += current; + } + + // Depreciation for the first and last periods are special cases + if (period === 1) { + // First period + return initial; + } else if (period === life) { + // Last period + return (cost - total) * rate; + } else { + return current; + } + }; + + exports.DDB = function(cost, salvage, life, period, factor) { + // Initialize factor + factor = (factor === undefined) ? 2 : factor; + + cost = utils.parseNumber(cost); + salvage = utils.parseNumber(salvage); + life = utils.parseNumber(life); + period = utils.parseNumber(period); + factor = utils.parseNumber(factor); + if (utils.anyIsError(cost, salvage, life, period, factor)) { + return error.value; + } + + // Return error if any of the parameters is negative or if factor is null + if (cost < 0 || salvage < 0 || life < 0 || period < 0 || factor <= 0) { + return error.num; + } + + // Return error if period is greater than life + if (period > life) { + return error.num; + } + + // Return 0 (zero) if salvage is greater than or equal to cost + if (salvage >= cost) { + return 0; + } + + // Compute depreciation + var total = 0; + var current = 0; + for (var i = 1; i <= period; i++) { + current = Math.min((cost - total) * (factor / life), (cost - salvage - total)); + total += current; + } + + // Return depreciation + return current; + }; + + // TODO + exports.DISC = function() { + throw new Error('DISC is not implemented'); + }; + + exports.DOLLARDE = function(dollar, fraction) { + // Credits: algorithm inspired by Apache OpenOffice + + dollar = utils.parseNumber(dollar); + fraction = utils.parseNumber(fraction); + if (utils.anyIsError(dollar, fraction)) { + return error.value; + } + + // Return error if fraction is negative + if (fraction < 0) { + return error.num; + } + + // Return error if fraction is greater than or equal to 0 and less than 1 + if (fraction >= 0 && fraction < 1) { + return error.div0; + } + + // Truncate fraction if it is not an integer + fraction = parseInt(fraction, 10); + + // Compute integer part + var result = parseInt(dollar, 10); + + // Add decimal part + result += (dollar % 1) * Math.pow(10, Math.ceil(Math.log(fraction) / Math.LN10)) / fraction; + + // Round result + var power = Math.pow(10, Math.ceil(Math.log(fraction) / Math.LN2) + 1); + result = Math.round(result * power) / power; + + // Return converted dollar price + return result; + }; + + exports.DOLLARFR = function(dollar, fraction) { + // Credits: algorithm inspired by Apache OpenOffice + + dollar = utils.parseNumber(dollar); + fraction = utils.parseNumber(fraction); + if (utils.anyIsError(dollar, fraction)) { + return error.value; + } + + // Return error if fraction is negative + if (fraction < 0) { + return error.num; + } + + // Return error if fraction is greater than or equal to 0 and less than 1 + if (fraction >= 0 && fraction < 1) { + return error.div0; + } + + // Truncate fraction if it is not an integer + fraction = parseInt(fraction, 10); + + // Compute integer part + var result = parseInt(dollar, 10); + + // Add decimal part + result += (dollar % 1) * Math.pow(10, -Math.ceil(Math.log(fraction) / Math.LN10)) * fraction; + + // Return converted dollar price + return result; + }; + + // TODO + exports.DURATION = function() { + throw new Error('DURATION is not implemented'); + }; + + exports.EFFECT = function(rate, periods) { + rate = utils.parseNumber(rate); + periods = utils.parseNumber(periods); + if (utils.anyIsError(rate, periods)) { + return error.value; + } + + // Return error if rate <=0 or periods < 1 + if (rate <= 0 || periods < 1) { + return error.num; + } + + // Truncate periods if it is not an integer + periods = parseInt(periods, 10); + + // Return effective annual interest rate + return Math.pow(1 + rate / periods, periods) - 1; + }; + + exports.FV = function(rate, periods, payment, value, type) { + // Credits: algorithm inspired by Apache OpenOffice + + value = value || 0; + type = type || 0; + + rate = utils.parseNumber(rate); + periods = utils.parseNumber(periods); + payment = utils.parseNumber(payment); + value = utils.parseNumber(value); + type = utils.parseNumber(type); + if (utils.anyIsError(rate, periods, payment, value, type)) { + return error.value; + } + + // Return future value + var result; + if (rate === 0) { + result = value + payment * periods; + } else { + var term = Math.pow(1 + rate, periods); + if (type === 1) { + result = value * term + payment * (1 + rate) * (term - 1) / rate; + } else { + result = value * term + payment * (term - 1) / rate; + } + } + return -result; + }; + + exports.FVSCHEDULE = function(principal, schedule) { + principal = utils.parseNumber(principal); + schedule = utils.parseNumberArray(utils.flatten(schedule)); + if (utils.anyIsError(principal, schedule)) { + return error.value; + } + + var n = schedule.length; + var future = principal; + + // Apply all interests in schedule + for (var i = 0; i < n; i++) { + // Apply scheduled interest + future *= 1 + schedule[i]; + } + + // Return future value + return future; + }; + + // TODO + exports.INTRATE = function() { + throw new Error('INTRATE is not implemented'); + }; + + exports.IPMT = function(rate, period, periods, present, future, type) { + // Credits: algorithm inspired by Apache OpenOffice + + future = future || 0; + type = type || 0; + + rate = utils.parseNumber(rate); + period = utils.parseNumber(period); + periods = utils.parseNumber(periods); + present = utils.parseNumber(present); + future = utils.parseNumber(future); + type = utils.parseNumber(type); + if (utils.anyIsError(rate, period, periods, present, future, type)) { + return error.value; + } + + // Compute payment + var payment = exports.PMT(rate, periods, present, future, type); + + // Compute interest + var interest; + if (period === 1) { + if (type === 1) { + interest = 0; + } else { + interest = -present; + } + } else { + if (type === 1) { + interest = exports.FV(rate, period - 2, payment, present, 1) - payment; + } else { + interest = exports.FV(rate, period - 1, payment, present, 0); + } + } + + // Return interest + return interest * rate; + }; + + exports.IRR = function(values, guess) { + // Credits: algorithm inspired by Apache OpenOffice + + guess = guess || 0; + + values = utils.parseNumberArray(utils.flatten(values)); + guess = utils.parseNumber(guess); + if (utils.anyIsError(values, guess)) { + return error.value; + } + + // Calculates the resulting amount + var irrResult = function(values, dates, rate) { + var r = rate + 1; + var result = values[0]; + for (var i = 1; i < values.length; i++) { + result += values[i] / Math.pow(r, (dates[i] - dates[0]) / 365); + } + return result; + }; + + // Calculates the first derivation + var irrResultDeriv = function(values, dates, rate) { + var r = rate + 1; + var result = 0; + for (var i = 1; i < values.length; i++) { + var frac = (dates[i] - dates[0]) / 365; + result -= frac * values[i] / Math.pow(r, frac + 1); + } + return result; + }; + + // Initialize dates and check that values contains at least one positive value and one negative value + var dates = []; + var positive = false; + var negative = false; + for (var i = 0; i < values.length; i++) { + dates[i] = (i === 0) ? 0 : dates[i - 1] + 365; + if (values[i] > 0) { + positive = true; + } + if (values[i] < 0) { + negative = true; + } + } + + // Return error if values does not contain at least one positive value and one negative value + if (!positive || !negative) { + return error.num; + } + + // Initialize guess and resultRate + guess = (guess === undefined) ? 0.1 : guess; + var resultRate = guess; + + // Set maximum epsilon for end of iteration + var epsMax = 1e-10; + + // Implement Newton's method + var newRate, epsRate, resultValue; + var contLoop = true; + do { + resultValue = irrResult(values, dates, resultRate); + newRate = resultRate - resultValue / irrResultDeriv(values, dates, resultRate); + epsRate = Math.abs(newRate - resultRate); + resultRate = newRate; + contLoop = (epsRate > epsMax) && (Math.abs(resultValue) > epsMax); + } while (contLoop); + + // Return internal rate of return + return resultRate; + }; + + exports.ISPMT = function(rate, period, periods, value) { + rate = utils.parseNumber(rate); + period = utils.parseNumber(period); + periods = utils.parseNumber(periods); + value = utils.parseNumber(value); + if (utils.anyIsError(rate, period, periods, value)) { + return error.value; + } + + // Return interest + return value * rate * (period / periods - 1); + }; + + // TODO + exports.MDURATION = function() { + throw new Error('MDURATION is not implemented'); + }; + + exports.MIRR = function(values, finance_rate, reinvest_rate) { + values = utils.parseNumberArray(utils.flatten(values)); + finance_rate = utils.parseNumber(finance_rate); + reinvest_rate = utils.parseNumber(reinvest_rate); + if (utils.anyIsError(values, finance_rate, reinvest_rate)) { + return error.value; + } + + // Initialize number of values + var n = values.length; + + // Lookup payments (negative values) and incomes (positive values) + var payments = []; + var incomes = []; + for (var i = 0; i < n; i++) { + if (values[i] < 0) { + payments.push(values[i]); + } else { + incomes.push(values[i]); + } + } + + // Return modified internal rate of return + var num = -exports.NPV(reinvest_rate, incomes) * Math.pow(1 + reinvest_rate, n - 1); + var den = exports.NPV(finance_rate, payments) * (1 + finance_rate); + return Math.pow(num / den, 1 / (n - 1)) - 1; + }; + + exports.NOMINAL = function(rate, periods) { + rate = utils.parseNumber(rate); + periods = utils.parseNumber(periods); + if (utils.anyIsError(rate, periods)) { + return error.value; + } + + // Return error if rate <=0 or periods < 1 + if (rate <= 0 || periods < 1) { + return error.num; + } + + // Truncate periods if it is not an integer + periods = parseInt(periods, 10); + + // Return nominal annual interest rate + return (Math.pow(rate + 1, 1 / periods) - 1) * periods; + }; + + exports.NPER = function(rate, payment, present, future, type) { + type = (type === undefined) ? 0 : type; + future = (future === undefined) ? 0 : future; + + rate = utils.parseNumber(rate); + payment = utils.parseNumber(payment); + present = utils.parseNumber(present); + future = utils.parseNumber(future); + type = utils.parseNumber(type); + if (utils.anyIsError(rate, payment, present, future, type)) { + return error.value; + } + + // Return number of periods + var num = payment * (1 + rate * type) - future * rate; + var den = (present * rate + payment * (1 + rate * type)); + return Math.log(num / den) / Math.log(1 + rate); + }; + + exports.NPV = function() { + var args = utils.parseNumberArray(utils.flatten(arguments)); + if (args instanceof Error) { + return args; + } + + // Lookup rate + var rate = args[0]; + + // Initialize net present value + var value = 0; + + // Loop on all values + for (var j = 1; j < args.length; j++) { + value += args[j] / Math.pow(1 + rate, j); + } + + // Return net present value + return value; + }; + + // TODO + exports.ODDFPRICE = function() { + throw new Error('ODDFPRICE is not implemented'); + }; + + // TODO + exports.ODDFYIELD = function() { + throw new Error('ODDFYIELD is not implemented'); + }; + + // TODO + exports.ODDLPRICE = function() { + throw new Error('ODDLPRICE is not implemented'); + }; + + // TODO + exports.ODDLYIELD = function() { + throw new Error('ODDLYIELD is not implemented'); + }; + + exports.PDURATION = function(rate, present, future) { + rate = utils.parseNumber(rate); + present = utils.parseNumber(present); + future = utils.parseNumber(future); + if (utils.anyIsError(rate, present, future)) { + return error.value; + } + + // Return error if rate <=0 + if (rate <= 0) { + return error.num; + } + + // Return number of periods + return (Math.log(future) - Math.log(present)) / Math.log(1 + rate); + }; + + exports.PMT = function(rate, periods, present, future, type) { + // Credits: algorithm inspired by Apache OpenOffice + + future = future || 0; + type = type || 0; + + rate = utils.parseNumber(rate); + periods = utils.parseNumber(periods); + present = utils.parseNumber(present); + future = utils.parseNumber(future); + type = utils.parseNumber(type); + if (utils.anyIsError(rate, periods, present, future, type)) { + return error.value; + } + + // Return payment + var result; + if (rate === 0) { + result = (present + future) / periods; + } else { + var term = Math.pow(1 + rate, periods); + if (type === 1) { + result = (future * rate / (term - 1) + present * rate / (1 - 1 / term)) / (1 + rate); + } else { + result = future * rate / (term - 1) + present * rate / (1 - 1 / term); + } + } + return -result; + }; + + exports.PPMT = function(rate, period, periods, present, future, type) { + future = future || 0; + type = type || 0; + + rate = utils.parseNumber(rate); + periods = utils.parseNumber(periods); + present = utils.parseNumber(present); + future = utils.parseNumber(future); + type = utils.parseNumber(type); + if (utils.anyIsError(rate, periods, present, future, type)) { + return error.value; + } + + return exports.PMT(rate, periods, present, future, type) - exports.IPMT(rate, period, periods, present, future, type); + }; + + // TODO + exports.PRICE = function() { + throw new Error('PRICE is not implemented'); + }; + + // TODO + exports.PRICEDISC = function() { + throw new Error('PRICEDISC is not implemented'); + }; + + // TODO + exports.PRICEMAT = function() { + throw new Error('PRICEMAT is not implemented'); + }; + + exports.PV = function(rate, periods, payment, future, type) { + future = future || 0; + type = type || 0; + + rate = utils.parseNumber(rate); + periods = utils.parseNumber(periods); + payment = utils.parseNumber(payment); + future = utils.parseNumber(future); + type = utils.parseNumber(type); + if (utils.anyIsError(rate, periods, payment, future, type)) { + return error.value; + } + + // Return present value + if (rate === 0) { + return -payment * periods - future; + } else { + return (((1 - Math.pow(1 + rate, periods)) / rate) * payment * (1 + rate * type) - future) / Math.pow(1 + rate, periods); + } + }; + + exports.RATE = function(periods, payment, present, future, type, guess) { + // Credits: rabugento + + guess = (guess === undefined) ? 0.01 : guess; + future = (future === undefined) ? 0 : future; + type = (type === undefined) ? 0 : type; + + periods = utils.parseNumber(periods); + payment = utils.parseNumber(payment); + present = utils.parseNumber(present); + future = utils.parseNumber(future); + type = utils.parseNumber(type); + guess = utils.parseNumber(guess); + if (utils.anyIsError(periods, payment, present, future, type, guess)) { + return error.value; + } + + // Set maximum epsilon for end of iteration + var epsMax = 1e-10; + + // Set maximum number of iterations + var iterMax = 50; + + // Implement Newton's method + var y, y0, y1, x0, x1 = 0, + f = 0, + i = 0; + var rate = guess; + if (Math.abs(rate) < epsMax) { + y = present * (1 + periods * rate) + payment * (1 + rate * type) * periods + future; + } else { + f = Math.exp(periods * Math.log(1 + rate)); + y = present * f + payment * (1 / rate + type) * (f - 1) + future; + } + y0 = present + payment * periods + future; + y1 = present * f + payment * (1 / rate + type) * (f - 1) + future; + i = x0 = 0; + x1 = rate; + while ((Math.abs(y0 - y1) > epsMax) && (i < iterMax)) { + rate = (y1 * x0 - y0 * x1) / (y1 - y0); + x0 = x1; + x1 = rate; + if (Math.abs(rate) < epsMax) { + y = present * (1 + periods * rate) + payment * (1 + rate * type) * periods + future; + } else { + f = Math.exp(periods * Math.log(1 + rate)); + y = present * f + payment * (1 / rate + type) * (f - 1) + future; + } + y0 = y1; + y1 = y; + ++i; + } + return rate; + }; + + // TODO + exports.RECEIVED = function() { + throw new Error('RECEIVED is not implemented'); + }; + + exports.RRI = function(periods, present, future) { + periods = utils.parseNumber(periods); + present = utils.parseNumber(present); + future = utils.parseNumber(future); + if (utils.anyIsError(periods, present, future)) { + return error.value; + } + + // Return error if periods or present is equal to 0 (zero) + if (periods === 0 || present === 0) { + return error.num; + } + + // Return equivalent interest rate + return Math.pow(future / present, 1 / periods) - 1; + }; + + exports.SLN = function(cost, salvage, life) { + cost = utils.parseNumber(cost); + salvage = utils.parseNumber(salvage); + life = utils.parseNumber(life); + if (utils.anyIsError(cost, salvage, life)) { + return error.value; + } + + // Return error if life equal to 0 (zero) + if (life === 0) { + return error.num; + } + + // Return straight-line depreciation + return (cost - salvage) / life; + }; + + exports.SYD = function(cost, salvage, life, period) { + // Return error if any of the parameters is not a number + cost = utils.parseNumber(cost); + salvage = utils.parseNumber(salvage); + life = utils.parseNumber(life); + period = utils.parseNumber(period); + if (utils.anyIsError(cost, salvage, life, period)) { + return error.value; + } + + // Return error if life equal to 0 (zero) + if (life === 0) { + return error.num; + } + + // Return error if period is lower than 1 or greater than life + if (period < 1 || period > life) { + return error.num; + } + + // Truncate period if it is not an integer + period = parseInt(period, 10); + + // Return straight-line depreciation + return ((cost - salvage) * (life - period + 1) * 2) / (life * (life + 1)); + }; + + exports.TBILLEQ = function(settlement, maturity, discount) { + settlement = utils.parseDate(settlement); + maturity = utils.parseDate(maturity); + discount = utils.parseNumber(discount); + if (utils.anyIsError(settlement, maturity, discount)) { + return error.value; + } + + // Return error if discount is lower than or equal to zero + if (discount <= 0) { + return error.num; + } + + // Return error if settlement is greater than maturity + if (settlement > maturity) { + return error.num; + } + + // Return error if maturity is more than one year after settlement + if (maturity - settlement > 365 * 24 * 60 * 60 * 1000) { + return error.num; + } + + // Return bond-equivalent yield + return (365 * discount) / (360 - discount * dateTime.DAYS360(settlement, maturity, false)); + }; + + exports.TBILLPRICE = function(settlement, maturity, discount) { + settlement = utils.parseDate(settlement); + maturity = utils.parseDate(maturity); + discount = utils.parseNumber(discount); + if (utils.anyIsError(settlement, maturity, discount)) { + return error.value; + } + + // Return error if discount is lower than or equal to zero + if (discount <= 0) { + return error.num; + } + + // Return error if settlement is greater than maturity + if (settlement > maturity) { + return error.num; + } + + // Return error if maturity is more than one year after settlement + if (maturity - settlement > 365 * 24 * 60 * 60 * 1000) { + return error.num; + } + + // Return bond-equivalent yield + return 100 * (1 - discount * dateTime.DAYS360(settlement, maturity, false) / 360); + }; + + exports.TBILLYIELD = function(settlement, maturity, price) { + settlement = utils.parseDate(settlement); + maturity = utils.parseDate(maturity); + price = utils.parseNumber(price); + if (utils.anyIsError(settlement, maturity, price)) { + return error.value; + } + + // Return error if price is lower than or equal to zero + if (price <= 0) { + return error.num; + } + + // Return error if settlement is greater than maturity + if (settlement > maturity) { + return error.num; + } + + // Return error if maturity is more than one year after settlement + if (maturity - settlement > 365 * 24 * 60 * 60 * 1000) { + return error.num; + } + + // Return bond-equivalent yield + return (100 - price) * 360 / (price * dateTime.DAYS360(settlement, maturity, false)); + }; + + // TODO + exports.VDB = function() { + throw new Error('VDB is not implemented'); + }; + + + exports.XIRR = function(values, dates, guess) { + // Credits: algorithm inspired by Apache OpenOffice + + values = utils.parseNumberArray(utils.flatten(values)); + dates = utils.parseDateArray(utils.flatten(dates)); + guess = utils.parseNumber(guess); + if (utils.anyIsError(values, dates, guess)) { + return error.value; + } + + // Calculates the resulting amount + var irrResult = function(values, dates, rate) { + var r = rate + 1; + var result = values[0]; + for (var i = 1; i < values.length; i++) { + result += values[i] / Math.pow(r, dateTime.DAYS(dates[i], dates[0]) / 365); + } + return result; + }; + + // Calculates the first derivation + var irrResultDeriv = function(values, dates, rate) { + var r = rate + 1; + var result = 0; + for (var i = 1; i < values.length; i++) { + var frac = dateTime.DAYS(dates[i], dates[0]) / 365; + result -= frac * values[i] / Math.pow(r, frac + 1); + } + return result; + }; + + // Check that values contains at least one positive value and one negative value + var positive = false; + var negative = false; + for (var i = 0; i < values.length; i++) { + if (values[i] > 0) { + positive = true; + } + if (values[i] < 0) { + negative = true; + } + } + + // Return error if values does not contain at least one positive value and one negative value + if (!positive || !negative) { + return error.num; + } + + // Initialize guess and resultRate + guess = guess || 0.1; + var resultRate = guess; + + // Set maximum epsilon for end of iteration + var epsMax = 1e-10; + + // Implement Newton's method + var newRate, epsRate, resultValue; + var contLoop = true; + do { + resultValue = irrResult(values, dates, resultRate); + newRate = resultRate - resultValue / irrResultDeriv(values, dates, resultRate); + epsRate = Math.abs(newRate - resultRate); + resultRate = newRate; + contLoop = (epsRate > epsMax) && (Math.abs(resultValue) > epsMax); + } while (contLoop); + + // Return internal rate of return + return resultRate; + }; + + exports.XNPV = function(rate, values, dates) { + rate = utils.parseNumber(rate); + values = utils.parseNumberArray(utils.flatten(values)); + dates = utils.parseDateArray(utils.flatten(dates)); + if (utils.anyIsError(rate, values, dates)) { + return error.value; + } + + var result = 0; + for (var i = 0; i < values.length; i++) { + result += values[i] / Math.pow(1 + rate, dateTime.DAYS(dates[i], dates[0]) / 365); + } + return result; + }; + + // TODO + exports.YIELD = function() { + throw new Error('YIELD is not implemented'); + }; + + // TODO + exports.YIELDDISC = function() { + throw new Error('YIELDDISC is not implemented'); + }; + + // TODO + exports.YIELDMAT = function() { + throw new Error('YIELDMAT is not implemented'); + }; + +/***/ }, +/* 18 */ +/***/ function(module, exports, __webpack_require__) { + + var error = __webpack_require__(5); + + exports.MATCH = function(lookupValue, lookupArray, matchType) { + if (!lookupValue && !lookupArray) { + return error.na; + } + + if (arguments.length === 2) { + matchType = 1; + } + if (!(lookupArray instanceof Array)) { + return error.na; + } + + if (matchType !== -1 && matchType !== 0 && matchType !== 1) { + return error.na; + } + var index; + var indexValue; + for (var idx = 0; idx < lookupArray.length; idx++) { + if (matchType === 1) { + if (lookupArray[idx] === lookupValue) { + return idx + 1; + } else if (lookupArray[idx] < lookupValue) { + if (!indexValue) { + index = idx + 1; + indexValue = lookupArray[idx]; + } else if (lookupArray[idx] > indexValue) { + index = idx + 1; + indexValue = lookupArray[idx]; + } + } + } else if (matchType === 0) { + if (typeof lookupValue === 'string') { + lookupValue = lookupValue.replace(/\?/g, '.'); + if (lookupArray[idx].toLowerCase().match(lookupValue.toLowerCase())) { + return idx + 1; + } + } else { + if (lookupArray[idx] === lookupValue) { + return idx + 1; + } + } + } else if (matchType === -1) { + if (lookupArray[idx] === lookupValue) { + return idx + 1; + } else if (lookupArray[idx] > lookupValue) { + if (!indexValue) { + index = idx + 1; + indexValue = lookupArray[idx]; + } else if (lookupArray[idx] < indexValue) { + index = idx + 1; + indexValue = lookupArray[idx]; + } + } + } + } + + return index ? index : error.na; + }; + +/***/ } +/******/ ]) +}); +; \ No newline at end of file diff --git a/dist/formula.min.js b/dist/formula.min.js new file mode 100644 index 00000000..5a8ff0e2 --- /dev/null +++ b/dist/formula.min.js @@ -0,0 +1,13 @@ +!function(r,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.formulajs=e():r.formulajs=e()}(this,function(){return function(r){function e(t){if(n[t])return n[t].exports;var u=n[t]={exports:{},id:t,loaded:!1};return r[t].call(u.exports,u,u.exports,e),u.loaded=!0,u.exports}var n={};return e.m=r,e.c=n,e.p="",e(0)}([function(r,e,n){var t=[n(1),n(15),n(12),n(16),n(2),n(7),n(14),n(17),n(11),n(18),n(6),n(10)];for(var u in t){var i=t[u];for(var a in i)e[a]=e[a]||i[a]}},function(r,e,n){function t(r,e){if(e)for(var n in e)r[n]=e[n];return r}var u=n(2),i=n(6),a=n(12),o=n(14);e.BETADIST=i.BETA.DIST,e.BETAINV=i.BETA.INV,e.BINOMDIST=i.BINOM.DIST,e.CEILING=e.ISOCEILING=t(u.CEILING.MATH,u.CEILING),e.CEILINGMATH=u.CEILING.MATH,e.CEILINGPRECISE=u.CEILING.PRECISE,e.CHIDIST=i.CHISQ.DIST,e.CHIDISTRT=i.CHISQ.DIST.RT,e.CHIINV=i.CHISQ.INV,e.CHIINVRT=i.CHISQ.INV.RT,e.CHITEST=i.CHISQ.TEST,e.CONFIDENCE=t(i.CONFIDENCE.NORM,i.CONFIDENCE),e.COVAR=i.COVARIANCE.P,e.COVARIANCEP=i.COVARIANCE.P,e.COVARIANCES=i.COVARIANCE.S,e.CRITBINOM=i.BINOM.INV,e.EXPONDIST=i.EXPON.DIST,e.ERFCPRECISE=a.ERFC.PRECISE,e.ERFPRECISE=a.ERF.PRECISE,e.FDIST=i.F.DIST,e.FDISTRT=i.F.DIST.RT,e.FINVRT=i.F.INV.RT,e.FINV=i.F.INV,e.FLOOR=t(u.FLOOR.MATH,u.FLOOR),e.FLOORMATH=u.FLOOR.MATH,e.FLOORPRECISE=u.FLOOR.PRECISE,e.FTEST=i.F.TEST,e.GAMMADIST=i.GAMMA.DIST,e.GAMMAINV=i.GAMMA.INV,e.GAMMALNPRECISE=i.GAMMALN.PRECISE,e.HYPGEOMDIST=i.HYPGEOM.DIST,e.LOGINV=i.LOGNORM.INV,e.LOGNORMINV=i.LOGNORM.INV,e.LOGNORMDIST=i.LOGNORM.DIST,e.MODE=t(i.MODE.SNGL,i.MODE),e.MODEMULT=i.MODE.MULT,e.MODESNGL=i.MODE.SNGL,e.NEGBINOMDIST=i.NEGBINOM.DIST,e.NETWORKDAYSINTL=o.NETWORKDAYS.INTL,e.NORMDIST=i.NORM.DIST,e.NORMINV=i.NORM.INV,e.NORMSDIST=i.NORM.S.DIST,e.NORMSINV=i.NORM.S.INV,e.PERCENTILE=t(i.PERCENTILE.EXC,i.PERCENTILE),e.PERCENTILEEXC=i.PERCENTILE.EXC,e.PERCENTILEINC=i.PERCENTILE.INC,e.PERCENTRANK=t(i.PERCENTRANK.INC,i.PERCENTRANK),e.PERCENTRANKEXC=i.PERCENTRANK.EXC,e.PERCENTRANKINC=i.PERCENTRANK.INC,e.POISSON=t(i.POISSON.DIST,i.POISSON),e.POISSONDIST=i.POISSON.DIST,e.QUARTILE=t(i.QUARTILE.INC,i.QUARTILE),e.QUARTILEEXC=i.QUARTILE.EXC,e.QUARTILEINC=i.QUARTILE.INC,e.RANK=t(i.RANK.EQ,i.RANK),e.RANKAVG=i.RANK.AVG,e.RANKEQ=i.RANK.EQ,e.SKEWP=i.SKEW.P,e.STDEV=t(i.STDEV.S,i.STDEV),e.STDEVP=i.STDEV.P,e.STDEVS=i.STDEV.S,e.TDIST=i.T.DIST,e.TDISTRT=i.T.DIST.RT,e.TINV=i.T.INV,e.TTEST=i.T.TEST,e.VAR=t(i.VAR.S,i.VAR),e.VARP=i.VAR.P,e.VARS=i.VAR.S,e.WEIBULL=t(i.WEIBULL.DIST,i.WEIBULL),e.WEIBULLDIST=i.WEIBULL.DIST,e.WORKDAYINTL=o.WORKDAY.INTL,e.ZTEST=i.Z.TEST},function(module,exports,__webpack_require__){var numeric=__webpack_require__(3),utils=__webpack_require__(4),error=__webpack_require__(5),statistical=__webpack_require__(6),information=__webpack_require__(11);exports.ABS=function(r){return r=utils.parseNumber(r),r instanceof Error?r:Math.abs(utils.parseNumber(r))},exports.ACOS=function(r){return r=utils.parseNumber(r),r instanceof Error?r:Math.acos(r)},exports.ACOSH=function(r){return r=utils.parseNumber(r),r instanceof Error?r:Math.log(r+Math.sqrt(r*r-1))},exports.ACOT=function(r){return r=utils.parseNumber(r),r instanceof Error?r:Math.atan(1/r)},exports.ACOTH=function(r){return r=utils.parseNumber(r),r instanceof Error?r:.5*Math.log((r+1)/(r-1))},exports.AGGREGATE=function(r,e,n,t){if(r=utils.parseNumber(r),e=utils.parseNumber(r),utils.anyIsError(r,e))return error.value;switch(r){case 1:return statistical.AVERAGE(n);case 2:return statistical.COUNT(n);case 3:return statistical.COUNTA(n);case 4:return statistical.MAX(n);case 5:return statistical.MIN(n);case 6:return exports.PRODUCT(n);case 7:return statistical.STDEV.S(n);case 8:return statistical.STDEV.P(n);case 9:return exports.SUM(n);case 10:return statistical.VAR.S(n);case 11:return statistical.VAR.P(n);case 12:return statistical.MEDIAN(n);case 13:return statistical.MODE.SNGL(n);case 14:return statistical.LARGE(n,t);case 15:return statistical.SMALL(n,t);case 16:return statistical.PERCENTILE.INC(n,t);case 17:return statistical.QUARTILE.INC(n,t);case 18:return statistical.PERCENTILE.EXC(n,t);case 19:return statistical.QUARTILE.EXC(n,t)}},exports.ARABIC=function(r){if(!/^M*(?:D?C{0,3}|C[MD])(?:L?X{0,3}|X[CL])(?:V?I{0,3}|I[XV])$/.test(r))return error.value;var e=0;return r.replace(/[MDLV]|C[MD]?|X[CL]?|I[XV]?/g,function(r){e+={M:1e3,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1}[r]}),e},exports.ASIN=function(r){return r=utils.parseNumber(r),r instanceof Error?r:Math.asin(r)},exports.ASINH=function(r){return r=utils.parseNumber(r),r instanceof Error?r:Math.log(r+Math.sqrt(r*r+1))},exports.ATAN=function(r){return r=utils.parseNumber(r),r instanceof Error?r:Math.atan(r)},exports.ATAN2=function(r,e){return r=utils.parseNumber(r),e=utils.parseNumber(e),utils.anyIsError(r,e)?error.value:Math.atan2(r,e)},exports.ATANH=function(r){return r=utils.parseNumber(r),r instanceof Error?r:Math.log((1+r)/(1-r))/2},exports.BASE=function(r,e,n){if(n=n||0,r=utils.parseNumber(r),e=utils.parseNumber(e),n=utils.parseNumber(n),utils.anyIsError(r,e,n))return error.value;n=void 0===n?0:n;var t=r.toString(e);return new Array(Math.max(n+1-t.length,0)).join("0")+t},exports.CEILING=function(r,e,n){if(e=void 0===e?1:Math.abs(e),n=n||0,r=utils.parseNumber(r),e=utils.parseNumber(e),n=utils.parseNumber(n),utils.anyIsError(r,e,n))return error.value;if(0===e)return 0;var t=-Math.floor(Math.log(e)/Math.log(10));return r>=0?exports.ROUND(Math.ceil(r/e)*e,t):0===n?-exports.ROUND(Math.floor(Math.abs(r)/e)*e,t):-exports.ROUND(Math.ceil(Math.abs(r)/e)*e,t)},exports.CEILING.MATH=exports.CEILING,exports.CEILING.PRECISE=exports.CEILING,exports.COMBIN=function(r,e){return r=utils.parseNumber(r),e=utils.parseNumber(e),utils.anyIsError(r,e)?error.value:exports.FACT(r)/(exports.FACT(e)*exports.FACT(r-e))},exports.COMBINA=function(r,e){return r=utils.parseNumber(r),e=utils.parseNumber(e),utils.anyIsError(r,e)?error.value:0===r&&0===e?1:exports.COMBIN(r+e-1,r-1)},exports.COS=function(r){return r=utils.parseNumber(r),r instanceof Error?r:Math.cos(r)},exports.COSH=function(r){return r=utils.parseNumber(r),r instanceof Error?r:(Math.exp(r)+Math.exp(-r))/2},exports.COT=function(r){return r=utils.parseNumber(r),r instanceof Error?r:1/Math.tan(r)},exports.COTH=function(r){if(r=utils.parseNumber(r),r instanceof Error)return r;var e=Math.exp(2*r);return(e+1)/(e-1)},exports.CSC=function(r){return r=utils.parseNumber(r),r instanceof Error?r:1/Math.sin(r)},exports.CSCH=function(r){return r=utils.parseNumber(r),r instanceof Error?r:2/(Math.exp(r)-Math.exp(-r))},exports.DECIMAL=function(r,e){return arguments.length<1?error.value:parseInt(r,e)},exports.DEGREES=function(r){return r=utils.parseNumber(r),r instanceof Error?r:180*r/Math.PI},exports.EVEN=function(r){return r=utils.parseNumber(r),r instanceof Error?r:exports.CEILING(r,-2,-1)},exports.EXP=Math.exp;var MEMOIZED_FACT=[];exports.FACT=function(r){if(r=utils.parseNumber(r),r instanceof Error)return r;var e=Math.floor(r);return 0===e||1===e?1:MEMOIZED_FACT[e]>0?MEMOIZED_FACT[e]:(MEMOIZED_FACT[e]=exports.FACT(e-1)*e,MEMOIZED_FACT[e])},exports.FACTDOUBLE=function(r){if(r=utils.parseNumber(r),r instanceof Error)return r;var e=Math.floor(r);return e<=0?1:e*exports.FACTDOUBLE(e-2)},exports.FLOOR=function(r,e){if(r=utils.parseNumber(r),e=utils.parseNumber(e),utils.anyIsError(r,e))return error.value;if(0===e)return 0;if(!(r>0&&e>0||r<0&&e<0))return error.num;e=Math.abs(e);var n=-Math.floor(Math.log(e)/Math.log(10));return r>=0?exports.ROUND(Math.floor(r/e)*e,n):-exports.ROUND(Math.ceil(Math.abs(r)/e),n)},exports.FLOOR.MATH=function(r,e,n){if(e=void 0===e?1:e,n=void 0===n?0:n,r=utils.parseNumber(r),e=utils.parseNumber(e),n=utils.parseNumber(n),utils.anyIsError(r,e,n))return error.value;if(0===e)return 0;e=e?Math.abs(e):1;var t=-Math.floor(Math.log(e)/Math.log(10));return r>=0?exports.ROUND(Math.floor(r/e)*e,t):0===n||void 0===n?-exports.ROUND(Math.ceil(Math.abs(r)/e)*e,t):-exports.ROUND(Math.floor(Math.abs(r)/e)*e,t)},exports.FLOOR.PRECISE=exports.FLOOR.MATH,exports.GCD=function(){var r=utils.parseNumberArray(utils.flatten(arguments));if(r instanceof Error)return r;for(var e=r.length,n=r[0],t=n<0?-n:n,u=1;ua?t%=a:a%=t;t+=a}return t},exports.INT=function(r){return r=utils.parseNumber(r),r instanceof Error?r:Math.floor(r)},exports.ISO={CEILING:exports.CEILING},exports.LCM=function(){var r=utils.parseNumberArray(utils.flatten(arguments));if(r instanceof Error)return r;for(var e,n,t,u,i=1;void 0!==(t=r.pop());)for(;t>1;){if(t%2){for(e=3,n=Math.floor(Math.sqrt(t));e<=n&&t%e;e+=2);u=e<=n?e:t}else u=2;for(t/=u,i*=u,e=r.length;e;r[--e]%u===0&&1===(r[e]/=u)&&r.splice(e,1));}return i},exports.LN=function(r){return r=utils.parseNumber(r),r instanceof Error?r:Math.log(r)},exports.LOG=function(r,e){return r=utils.parseNumber(r),e=utils.parseNumber(e),utils.anyIsError(r,e)?error.value:(e=void 0===e?10:e,Math.log(r)/Math.log(e))},exports.LOG10=function(r){return r=utils.parseNumber(r),r instanceof Error?r:Math.log(r)/Math.log(10)},exports.MDETERM=function(r){return r=utils.parseMatrix(r),r instanceof Error?r:numeric.det(r)},exports.MINVERSE=function(r){return r=utils.parseMatrix(r),r instanceof Error?r:numeric.inv(r)},exports.MMULT=function(r,e){return r=utils.parseMatrix(r),e=utils.parseMatrix(e),utils.anyIsError(r,e)?error.value:numeric.dot(r,e)},exports.MOD=function(r,e){if(r=utils.parseNumber(r),e=utils.parseNumber(e),utils.anyIsError(r,e))return error.value;if(0===e)return error.div0;var n=Math.abs(r%e);return e>0?n:-n},exports.MROUND=function(r,e){return r=utils.parseNumber(r),e=utils.parseNumber(e),utils.anyIsError(r,e)?error.value:r*e<0?error.num:Math.round(r/e)*e},exports.MULTINOMIAL=function(){var r=utils.parseNumberArray(utils.flatten(arguments));if(r instanceof Error)return r;for(var e=0,n=1,t=0;t0?e:-e},exports.PI=function(){return Math.PI},exports.POWER=function(r,e){if(r=utils.parseNumber(r),e=utils.parseNumber(e),utils.anyIsError(r,e))return error.value;var n=Math.pow(r,e);return isNaN(n)?error.num:n},exports.PRODUCT=function(){var r=utils.parseNumberArray(utils.flatten(arguments));if(r instanceof Error)return r;for(var e=1,n=0;n0?1:-1;return n*Math.floor(Math.abs(r)*Math.pow(10,e))/Math.pow(10,e)},exports.ROUNDUP=function(r,e){if(r=utils.parseNumber(r),e=utils.parseNumber(e),utils.anyIsError(r,e))return error.value;var n=r>0?1:-1;return n*Math.ceil(Math.abs(r)*Math.pow(10,e))/Math.pow(10,e)},exports.SEC=function(r){return r=utils.parseNumber(r),r instanceof Error?r:1/Math.cos(r)},exports.SECH=function(r){return r=utils.parseNumber(r),r instanceof Error?r:2/(Math.exp(r)+Math.exp(-r))},exports.SERIESSUM=function(r,e,n,t){if(r=utils.parseNumber(r),e=utils.parseNumber(e),n=utils.parseNumber(n),t=utils.parseNumberArray(t),utils.anyIsError(r,e,n,t))return error.value;for(var u=t[0]*Math.pow(r,e),i=1;i=e)},exports.LT=function(r,e){return 2!==arguments.length?error.na:(r=utils.parseNumber(r),e=utils.parseNumber(e),utils.anyIsError(r,e)?error.error:r0?1:-1;return n*Math.floor(Math.abs(r)*Math.pow(10,e))/Math.pow(10,e)}},function(module,exports,__webpack_require__){(function(global){"use strict";var numeric=exports;"undefined"!=typeof global&&(global.numeric=numeric),numeric.version="1.2.6",numeric.bench=function(r,e){var n,t,u,i;for("undefined"==typeof e&&(e=15),u=.5,n=new Date;;){for(u*=2,i=u;i>3;i-=4)r(),r(),r(),r();for(;i>0;)r(),i--;if(t=new Date,t-n>e)break}for(i=u;i>3;i-=4)r(),r(),r(),r();for(;i>0;)r(),i--;return t=new Date,1e3*(3*u-1)/(t-n)},numeric._myIndexOf=function(r){var e,n=this.length;for(e=0;enumeric.largeArray)return t.push("...Large Array..."),!0;var f=!1;for(t.push("["),u=0;u0&&(t.push(","),f&&t.push("\n ")),f=n(r[u]);return t.push("]"),!0}t.push("{");var f=!1;for(u in r)r.hasOwnProperty(u)&&(f&&t.push(",\n"),f=!0,t.push(u),t.push(": \n"),n(r[u]));return t.push("}"),!0}var t=[];return n(r),t.join("")},numeric.parseDate=function(r){function e(r){if("string"==typeof r)return Date.parse(r.replace(/-/g,"/"));if(!(r instanceof Array))throw new Error("parseDate: parameter must be arrays of strings");var n,t=[];for(n=0;n0){for(u[s]=[],e=0;e>2,a=((3&n)<<4)+(t>>4),o=((15&t)<<2)+(u>>6),s=63&u,e+1>=f?o=s=64:e+2>=f&&(s=64),c+=l.charAt(i)+l.charAt(a)+l.charAt(o)+l.charAt(s);return c}function n(r,e,n){"undefined"==typeof e&&(e=0),"undefined"==typeof n&&(n=r.length);var t,u=[0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,285281116,2405801727,4167216745,1634467795,376229701,2685067896,3608007406,1308918612,956543938,2808555105,3495958263,1231636301,1047427035,2932959818,3654703836,1088359270,936918e3,2847714899,3736837829,1202900863,817233897,3183342108,3401237130,1404277552,615818150,3134207493,3453421203,1423857449,601450431,3009837614,3294710456,1567103746,711928724,3020668471,3272380065,1510334235,755167117],i=-1,a=0;r.length;for(t=e;t>>8^u[a];return i^-1}var t,u,i,a,o,s,f,l,c,m,p=r[0].length,h=r[0][0].length,g=[137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,h>>24&255,h>>16&255,h>>8&255,255&h,p>>24&255,p>>16&255,p>>8&255,255&p,8,2,0,0,0,-1,-2,-3,-4,-5,-6,-7,-8,73,68,65,84,8,29];for(m=n(g,12,29),g[29]=m>>24&255,g[30]=m>>16&255,g[31]=m>>8&255,g[32]=255&m,t=1,u=0,f=0;f>8&255,g.push(o),g.push(s),g.push(255&~o),g.push(255&~s),0===f&&g.push(0),l=0;l255?255:o<0?0:Math.round(o),t=(t+o)%65521,u=(u+t)%65521,g.push(o);g.push(0)}return c=(u<<16)+t,g.push(c>>24&255),g.push(c>>16&255),g.push(c>>8&255),g.push(255&c),a=g.length-41,g[33]=a>>24&255,g[34]=a>>16&255,g[35]=a>>8&255,g[36]=255&a,m=n(g,37),g.push(m>>24&255),g.push(m>>16&255),g.push(m>>8&255),g.push(255&m),g.push(0),g.push(0),g.push(0),g.push(0),g.push(73),g.push(69),g.push(78),g.push(68),g.push(174),g.push(66),g.push(96),g.push(130),"data:image/png;base64,"+e(g)},numeric._dim=function(r){for(var e=[];"object"==typeof r;)e.push(r.length),r=r[0];return e},numeric.dim=function(r){var e,n;return"object"==typeof r?(e=r[0],"object"==typeof e?(n=e[0],"object"==typeof n?numeric._dim(r):[r.length,e.length]):[r.length]):[]},numeric.mapreduce=function(r,e){return Function("x","accum","_s","_k",'if(typeof accum === "undefined") accum = '+e+';\nif(typeof x === "number") { var xi = x; '+r+'; return accum; }\nif(typeof _s === "undefined") _s = numeric.dim(x);\nif(typeof _k === "undefined") _k = 0;\nvar _n = _s[_k];\nvar i,xi;\nif(_k < _s.length-1) {\n for(i=_n-1;i>=0;i--) {\n accum = arguments.callee(x[i],accum,_s,_k+1);\n } return accum;\n}\nfor(i=_n-1;i>=1;i-=2) { \n xi = x[i];\n '+r+";\n xi = x[i-1];\n "+r+";\n}\nif(i === 0) {\n xi = x[i];\n "+r+"\n}\nreturn accum;")},numeric.mapreduce2=function(r,e){return Function("x","var n = x.length;\nvar i,xi;\n"+e+";\nfor(i=n-1;i!==-1;--i) { \n xi = x[i];\n "+r+";\n}\nreturn accum;")},numeric.same=function r(e,n){var t,u;if(!(e instanceof Array&&n instanceof Array))return!1;if(u=e.length,u!==n.length)return!1;for(t=0;t=0;t-=2)i[t+1]=e,i[t]=e;return t===-1&&(i[0]=e),i}for(t=u-1;t>=0;t--)i[t]=numeric.rep(r,e,n+1);return i},numeric.dotMMsmall=function(r,e){var n,t,u,i,a,o,s,f,l,c,m;for(i=r.length,a=e.length,o=e[0].length,s=Array(i),n=i-1;n>=0;n--){for(f=Array(o),l=r[n],u=o-1;u>=0;u--){for(c=l[a-1]*e[a-1][u],t=a-2;t>=1;t-=2)m=t-1,c+=l[t]*e[t][u]+l[m]*e[m][u];0===t&&(c+=l[0]*e[0][u]),f[u]=c}s[n]=f}return s},numeric._getCol=function(r,e,n){var t,u=r.length;for(t=u-1;t>0;--t)n[t]=r[t][e],--t,n[t]=r[t][e];0===t&&(n[0]=r[0][e])},numeric.dotMMbig=function(r,e){var n,t,u,i,a=numeric._getCol,o=e.length,s=Array(o),f=r.length,l=e[0].length,c=new Array(f),m=numeric.dotVV;for(--o,--f,t=f;t!==-1;--t)c[t]=Array(l);for(--l,t=l;t!==-1;--t)for(a(e,t,s),u=f;u!==-1;--u)i=0,n=r[u],c[u][t]=m(n,s);return c},numeric.dotMV=function(r,e){var n,t=r.length,u=(e.length,Array(t)),i=numeric.dotVV;for(n=t-1;n>=0;n--)u[n]=i(r[n],e);return u},numeric.dotVM=function(r,e){var n,t,u,i,a,o,s;for(u=r.length,i=e[0].length,a=Array(i),t=i-1;t>=0;t--){for(o=r[u-1]*e[u-1][t],n=u-2;n>=1;n-=2)s=n-1,o+=r[n]*e[n][t]+r[s]*e[s][t];0===n&&(o+=r[0]*e[0][t]),a[t]=o}return a},numeric.dotVV=function(r,e){var n,t,u=r.length,i=r[u-1]*e[u-1];for(n=u-2;n>=1;n-=2)t=n-1,i+=r[n]*e[n]+r[t]*e[t];return 0===n&&(i+=r[0]*e[0]),i},numeric.dot=function(r,e){var n=numeric.dim;switch(1e3*n(r).length+n(e).length){case 2002:return e.length<10?numeric.dotMMsmall(r,e):numeric.dotMMbig(r,e);case 2001:return numeric.dotMV(r,e);case 1002:return numeric.dotVM(r,e);case 1001:return numeric.dotVV(r,e);case 1e3:return numeric.mulVS(r,e);case 1:return numeric.mulSV(r,e);case 0:return r*e;default:throw new Error("numeric.dot only works on vectors and matrices")}},numeric.diag=function(r){var e,n,t,u,i=r.length,a=Array(i);for(e=i-1;e>=0;e--){for(u=Array(i),n=e+2,t=i-1;t>=n;t-=2)u[t]=0,u[t-1]=0;for(t>e&&(u[t]=0),u[e]=r[e],t=e-1;t>=1;t-=2)u[t]=0,u[t-1]=0;0===t&&(u[0]=0),a[e]=u}return a},numeric.getDiag=function(r){var e,n=Math.min(r.length,r[0].length),t=Array(n);for(e=n-1;e>=1;--e)t[e]=r[e][e],--e,t[e]=r[e][e];return 0===e&&(t[0]=r[0][0]),t},numeric.identity=function(r){return numeric.diag(numeric.rep([r],1))},numeric.pointwise=function(r,e,n){"undefined"==typeof n&&(n="");var t,u,i=[],a=/\[i\]$/,o="",s=!1;for(t=0;t=0;i--) ret[i] = arguments.callee("+r.join(",")+",_s,_k+1);\n return ret;\n}\n"+n+"\nfor(i=_n-1;i!==-1;--i) {\n "+e+"\n}\nreturn ret;",Function.apply(null,i)},numeric.pointwise2=function(r,e,n){"undefined"==typeof n&&(n="");var t,u,i=[],a=/\[i\]$/,o="",s=!1;for(t=0;t=0;a--)e("object"==typeof r?r[a]:r,"object"==typeof n?n[a]:n,t,u+1,i)},numeric._biforeach2=function n(r,e,t,u,i){if(u===t.length-1)return i(r,e);var a,o=t[u],s=Array(o);for(a=o-1;a>=0;--a)s[a]=n("object"==typeof r?r[a]:r,"object"==typeof e?e[a]:e,t,u+1,i);return s},numeric._foreach=function t(r,e,n,u){if(n===e.length-1)return void u(r);var i,a=e[n];for(i=a-1;i>=0;i--)t(r[i],e,n+1,u)},numeric._foreach2=function u(r,e,n,t){if(n===e.length-1)return t(r);var i,a=e[n],o=Array(a);for(i=a-1;i>=0;i--)o[i]=u(r[i],e,n+1,t);return o},numeric.ops2={add:"+",sub:"-",mul:"*",div:"/",mod:"%",and:"&&",or:"||",eq:"===",neq:"!==",lt:"<",gt:">",leq:"<=",geq:">=",band:"&",bor:"|",bxor:"^",lshift:"<<",rshift:">>",rrshift:">>>"},numeric.opseq={addeq:"+=",subeq:"-=",muleq:"*=",diveq:"/=",modeq:"%=",lshifteq:"<<=",rshifteq:">>=",rrshifteq:">>>=",bandeq:"&=",boreq:"|=",bxoreq:"^="},numeric.mathfuns=["abs","acos","asin","atan","ceil","cos","exp","floor","log","round","sin","sqrt","tan","isNaN","isFinite"],numeric.mathfuns2=["atan2","pow","max","min"],numeric.ops1={neg:"-",not:"!",bnot:"~",clone:""},numeric.mapreducers={any:["if(xi) return true;","var accum = false;"],all:["if(!xi) return false;","var accum = true;"],sum:["accum += xi;","var accum = 0;"],prod:["accum *= xi;","var accum = 1;"],norm2Squared:["accum += xi*xi;","var accum = 0;"],norminf:["accum = max(accum,abs(xi));","var accum = 0, max = Math.max, abs = Math.abs;"],norm1:["accum += abs(xi)","var accum = 0, abs = Math.abs;"],sup:["accum = max(accum,xi);","var accum = -Infinity, max = Math.max;"],inf:["accum = min(accum,xi);","var accum = Infinity, min = Math.min;"]},function(){var r,e;for(r=0;rg&&(h=i,g=o);for(n=m[h],m[h]=m[a],m[a]=n,u=p[h],p[h]=p[a],p[a]=u,r=n[a],o=a;o!==c;++o)n[o]/=r;for(o=c-1;o!==-1;--o)u[o]/=r;for(i=l-1;i!==-1;--i)if(i!==a){for(e=m[i],t=p[i],r=e[a],o=a+1;o!==c;++o)e[o]-=n[o]*r;for(o=c-1;o>0;--o)t[o]-=u[o]*r,--o,t[o]-=u[o]*r;0===o&&(t[0]-=u[0]*r)}}return p},numeric.det=function(r){var e=numeric.dim(r);if(2!==e.length||e[0]!==e[1])throw new Error("numeric: det() only works on square matrices");var n,t,u,i,a,o,s,f,l=e[0],c=1,m=numeric.clone(r);for(t=0;tMath.abs(m[u][t])&&(u=n);for(u!==t&&(s=m[u],m[u]=m[t],m[t]=s,c*=-1),i=m[t],n=t+1;n=1;e-=2){for(u=r[e],t=r[e-1],n=o-1;n>=1;--n)i=s[n],i[e]=u[n],i[e-1]=t[n],--n,i=s[n],i[e]=u[n],i[e-1]=t[n];0===n&&(i=s[0],i[e]=u[0],i[e-1]=t[0])}if(0===e){for(t=r[0],n=o-1;n>=1;--n)s[n][0]=t[n],--n,s[n][0]=t[n];0===n&&(s[0][0]=t[0])}return s},numeric.negtranspose=function(r){var e,n,t,u,i,a=r.length,o=r[0].length,s=Array(o);for(n=0;n=1;e-=2){for(u=r[e],t=r[e-1],n=o-1;n>=1;--n)i=s[n],i[e]=-u[n],i[e-1]=-t[n],--n,i=s[n],i[e]=-u[n],i[e-1]=-t[n];0===n&&(i=s[0],i[e]=-u[0],i[e-1]=-t[0])}if(0===e){for(t=r[0],n=o-1;n>=1;--n)s[n][0]=-t[n],--n,s[n][0]=-t[n];0===n&&(s[0][0]=-t[0])}return s},numeric._random=function i(r,e){var n,t,u=r[e],a=Array(u);if(e===r.length-1){for(t=Math.random,n=u-1;n>=1;n-=2)a[n]=t(),a[n-1]=t();return 0===n&&(a[0]=t()),a}for(n=u-1;n>=0;n--)a[n]=i(r,e+1);return a},numeric.random=function(r){return numeric._random(r,0)},numeric.norm2=function(r){return Math.sqrt(numeric.norm2Squared(r))},numeric.linspace=function(r,e,n){if("undefined"==typeof n&&(n=Math.max(Math.round(e-r)+1,1)),n<2)return 1===n?[r]:[];var t,u=Array(n);for(n--,t=n;t>=0;t--)u[t]=(t*e+(n-t)*r)/n;return u},numeric.getBlock=function(r,e,n){function t(r,i){var a,o=e[i],s=n[i]-o,f=Array(s);if(i===u.length-1){for(a=s;a>=0;a--)f[a]=r[a+o];return f}for(a=s;a>=0;a--)f[a]=t(r[a+o],i+1);return f}var u=numeric.dim(r);return t(r,0)},numeric.setBlock=function(r,e,n,t){function u(r,t,a){var o,s=e[a],f=n[a]-s;if(a===i.length-1)for(o=f;o>=0;o--)r[o+s]=t[o];for(o=f;o>=0;o--)u(r[o+s],t[o],a+1)}var i=numeric.dim(r);return u(r,t,0),r},numeric.getRange=function(r,e,n){var t,u,i,a,o=e.length,s=n.length,f=Array(o);for(t=o-1;t!==-1;--t)for(f[t]=Array(s),i=f[t],a=r[e[t]],u=s-1;u!==-1;--u)i[u]=a[n[u]];return f},numeric.blockMatrix=function(r){var e=numeric.dim(r);if(e.length<4)return numeric.blockMatrix([r]);var n,t,u,i,a,o=e[0],s=e[1];for(n=0,t=0,u=0;u=0;i--){for(u=Array(f),o=r[i],a=f-1;a>=3;--a)u[a]=o*e[a],--a,u[a]=o*e[a],--a,u[a]=o*e[a],--a,u[a]=o*e[a];for(;a>=0;)u[a]=o*e[a],--a;l[i]=u}return l},numeric.T=function(r,e){this.x=r,this.y=e},numeric.t=function(r,e){return new numeric.T(r,e)},numeric.Tbinop=function(r,e,n,t,u){numeric.indexOf;if("string"!=typeof u){var i;u="";for(i in numeric)numeric.hasOwnProperty(i)&&(r.indexOf(i)>=0||e.indexOf(i)>=0||n.indexOf(i)>=0||t.indexOf(i)>=0)&&i.length>1&&(u+="var "+i+" = numeric."+i+";\n")}return Function(["y"],"var x = this;\nif(!(y instanceof numeric.T)) { y = new numeric.T(y); }\n"+u+"\nif(x.y) { if(y.y) { return new numeric.T("+t+");\n }\n return new numeric.T("+n+");\n}\nif(y.y) {\n return new numeric.T("+e+");\n}\nreturn new numeric.T("+r+");\n")},numeric.T.prototype.add=numeric.Tbinop("add(x.x,y.x)","add(x.x,y.x),y.y","add(x.x,y.x),x.y","add(x.x,y.x),add(x.y,y.y)"),numeric.T.prototype.sub=numeric.Tbinop("sub(x.x,y.x)","sub(x.x,y.x),neg(y.y)","sub(x.x,y.x),x.y","sub(x.x,y.x),sub(x.y,y.y)"),numeric.T.prototype.mul=numeric.Tbinop("mul(x.x,y.x)","mul(x.x,y.x),mul(x.x,y.y)","mul(x.x,y.x),mul(x.y,y.x)","sub(mul(x.x,y.x),mul(x.y,y.y)),add(mul(x.x,y.y),mul(x.y,y.x))"),numeric.T.prototype.reciprocal=function(){var r=numeric.mul,e=numeric.div;if(this.y){var n=numeric.add(r(this.x,this.x),r(this.y,this.y));return new numeric.T(e(this.x,n),e(numeric.neg(this.y),n))}return new T(e(1,this.x))},numeric.T.prototype.div=function a(r){if(r instanceof numeric.T||(r=new numeric.T(r)),r.y)return this.mul(r.reciprocal());var a=numeric.div;return this.y?new numeric.T(a(this.x,r.x),a(this.y,r.x)):new numeric.T(a(this.x,r.x))},numeric.T.prototype.dot=numeric.Tbinop("dot(x.x,y.x)","dot(x.x,y.x),dot(x.x,y.y)","dot(x.x,y.x),dot(x.y,y.x)","sub(dot(x.x,y.x),dot(x.y,y.y)),add(dot(x.x,y.y),dot(x.y,y.x))"),numeric.T.prototype.transpose=function(){var r=numeric.transpose,e=this.x,n=this.y;return n?new numeric.T(r(e),r(n)):new numeric.T(r(e))},numeric.T.prototype.transjugate=function(){var r=numeric.transpose,e=this.x,n=this.y;return n?new numeric.T(r(e),numeric.negtranspose(n)):new numeric.T(r(e))},numeric.Tunop=function(r,e,n){return"string"!=typeof n&&(n=""),Function("var x = this;\n"+n+"\nif(x.y) { "+e+";\n}\n"+r+";\n")},numeric.T.prototype.exp=numeric.Tunop("return new numeric.T(ex)","return new numeric.T(mul(cos(x.y),ex),mul(sin(x.y),ex))","var ex = numeric.exp(x.x), cos = numeric.cos, sin = numeric.sin, mul = numeric.mul;"),numeric.T.prototype.conj=numeric.Tunop("return new numeric.T(x.x);","return new numeric.T(x.x,numeric.neg(x.y));"),numeric.T.prototype.neg=numeric.Tunop("return new numeric.T(neg(x.x));","return new numeric.T(neg(x.x),neg(x.y));","var neg = numeric.neg;"),numeric.T.prototype.sin=numeric.Tunop("return new numeric.T(numeric.sin(x.x))","return x.exp().sub(x.neg().exp()).div(new numeric.T(0,2));"),numeric.T.prototype.cos=numeric.Tunop("return new numeric.T(numeric.cos(x.x))","return x.exp().add(x.neg().exp()).div(2);"),numeric.T.prototype.abs=numeric.Tunop("return new numeric.T(numeric.abs(x.x));","return new numeric.T(numeric.sqrt(numeric.add(mul(x.x,x.x),mul(x.y,x.y))));","var mul = numeric.mul;"),numeric.T.prototype.log=numeric.Tunop("return new numeric.T(numeric.log(x.x));","var theta = new numeric.T(numeric.atan2(x.y,x.x)), r = x.abs();\nreturn new numeric.T(numeric.log(r.x),theta.x);"),numeric.T.prototype.norm2=numeric.Tunop("return numeric.norm2(x.x);","var f = numeric.norm2Squared;\nreturn Math.sqrt(f(x.x)+f(x.y));"),numeric.T.prototype.inv=function(){var r=this;if("undefined"==typeof r.y)return new numeric.T(numeric.inv(r.x));var e,n,t,u,i,a,o,s,f,l,c,e,n,t,m,p,h,g,v,d,y,b=r.x.length,N=numeric.identity(b),E=numeric.rep([b,b],0),x=numeric.clone(r.x),M=numeric.clone(r.y);for(e=0;em&&(t=n,m=p);for(t!==e&&(y=x[e],x[e]=x[t],x[t]=y,y=M[e],M[e]=M[t],M[t]=y,y=N[e],N[e]=N[t],N[t]=y,y=E[e],E[e]=E[t],E[t]=y),u=x[e],i=M[e],s=N[e],f=E[e],h=u[e],g=i[e],n=e+1;n0;e--)for(s=N[e],f=E[e],n=e-1;n>=0;n--)for(l=N[n],c=E[n],h=x[n][e],g=M[n][e],t=b-1;t>=0;t--)v=s[t],d=f[t],l[t]-=h*v-g*d,c[t]-=h*d+g*v;return new numeric.T(N,E)},numeric.T.prototype.get=function(r){var e,n=this.x,t=this.y,u=0,i=r.length;if(t){for(;u=0?1:-1,t=n*numeric.norm2(r);e[0]+=t;var u=numeric.norm2(e);if(0===u)throw new Error("eig: internal error");return numeric.div(e,u)},numeric.toUpperHessenberg=function(r){var e=numeric.dim(r);if(2!==e.length||e[0]!==e[1])throw new Error("numeric: toUpperHessenberg() only works on square matrices");var n,t,u,i,a,o,s,f,l,c,m=e[0],p=numeric.clone(r),h=numeric.identity(m);for(t=0;t0){for(a=numeric.house(i),o=numeric.getBlock(p,[t+1,t],[m-1,m-1]),s=numeric.tensor(a,numeric.dot(a,o)),n=t+1;n=4*s){var T,w;T=.5*(f+Math.sqrt(f*f-4*s)),w=.5*(f-Math.sqrt(f*f-4*s)),l=numeric.add(numeric.sub(numeric.dot(l,l),numeric.mul(l,T+w)),numeric.diag(numeric.rep([3],T*w)))}else l=numeric.add(numeric.sub(numeric.dot(l,l),numeric.mul(l,f)),numeric.diag(numeric.rep([3],s)));for(n=[l[0][0],l[1][0],l[2][0]],t=numeric.house(n),p=[r[0],r[1],r[2]],h=numeric.tensor(t,numeric.dot(t,p)),v=0;v<3;v++)for(m=r[v],g=h[v],y=0;y=0?(p=l<0?-.5*(l-w(m)):-.5*(l+w(m)),d=(a-p)*(a-p)+o*o,y=s*s+(f-p)*(f-p),d>y?(d=w(d),g=(a-p)/d,v=o/d):(y=w(y),g=s/y,v=(f-p)/y),u=new E([[v,-g],[g,v]]),A.setRows(n,i,u.dot(A.getRows(n,i)))):(p=-.5*l,h=.5*w(-m),d=(a-p)*(a-p)+o*o,y=s*s+(f-p)*(f-p),d>y?(d=w(d+h*h),g=(a-p)/d,v=o/d,p=0,h/=d):(y=w(y+h*h),g=s/y,v=(f-p)/y,p=h/y,h=0),u=new E([[v,-g],[g,v]],[[p,h],[h,-p]]),A.setRows(n,i,u.dot(A.getRows(n,i))))}var S=A.dot(r).dot(A.transjugate()),x=r.length,R=numeric.T.identity(x);for(i=0;i0)for(t=i-1;t>=0;t--){var O=S.get([t,t]),D=S.get([i,i]);numeric.neq(O.x,D.x)||numeric.neq(O.y,D.y)?(p=S.getRow(t).getBlock([t],[i-1]),h=R.getRow(i).getBlock([t],[i-1]),R.set([i,t],S.get([t,i]).neg().sub(p.dot(h)).div(O.sub(D)))):R.setRow(i,R.getRow(t))}for(i=0;i=a.length;)a[a.length]=0;0!==n[u]&&a[u]++}}var e=a.length,o=Array(e+1);for(o[0]=0,t=0;t=s){if(u[l]=p[f],0===f)return;++l,--f,o=c[f],s=m[f]}else a=i[n[o]],0===t[a]?(t[a]=1,c[f]=o,++f,p[f]=a,o=e[a],m[f]=s=e[a+1]):++o},numeric.ccsLPSolve=function(r,e,n,t,u,i,a){var o,s,f,l,c,m,p,h,g,v=r[0],d=r[1],y=r[2],b=(v.length-1,e[0]),N=e[1],E=e[2];for(s=b[u],f=b[u+1],t.length=0,o=s;oi&&(a=u,i=o));for(E(y[n])=f){if(u[c]=i[h[l]],0===l)return;++c,--l,s=m[l],f=p[l]}else o=n[s],0===t[o]?(t[o]=1,m[l]=s,++l,h[l]=o,o=i[o],s=e[o],p[l]=f=e[o+1]):++s}},numeric.ccsLPSolve0=function(r,e,n,t,u,i,a,o){var s,f,l,c,m,p,h,g,v,d=r[0],y=r[1],b=r[2],N=(d.length-1,e[0]),E=e[1],x=e[2];for(f=N[u],l=N[u+1],t.length=0,s=f;si&&(a=u,i=o));for(E(y[x[n]])e[n]&&(e[n]=r.length);var t;for(t in r)r.hasOwnProperty(t)&&s(r[t],e,n+1);return e},numeric.sclone=function f(r,e,n){"undefined"==typeof e&&(e=0),"undefined"==typeof n&&(n=numeric.sdim(r).length);var t,u=Array(r.length);if(e===n-1){for(t in r)r.hasOwnProperty(t)&&(u[t]=r[t]);return u}for(t in r)r.hasOwnProperty(t)&&(u[t]=f(r[t],e+1,n));return u},numeric.sdiag=function(r){var e,n,t=r.length,u=Array(t);for(e=t-1;e>=1;e-=2)n=e-1,u[e]=[],u[e][e]=r[e],u[n]=[],u[n][n]=r[n];return 0===e&&(u[0]=[],u[0][0]=r[e]),u},numeric.sidentity=function(r){return numeric.sdiag(numeric.rep([r],1))},numeric.stranspose=function(r){var e,n,t,u=[];r.length;for(e in r)if(r.hasOwnProperty(e)){t=r[e];for(n in t)t.hasOwnProperty(n)&&("object"!=typeof u[n]&&(u[n]=[]),u[n][e]=t[n])}return u},numeric.sLUP=function(r,e){throw new Error("The function numeric.sLUP had a bug in it and has been removed. Please use the new numeric.ccsLUP function instead.")},numeric.sdotMM=function(r,e){var n,t,u,i,a,o,s,f=r.length,l=(e.length,numeric.stranspose(e)),c=l.length,m=Array(f);for(u=f-1;u>=0;u--){for(s=[],n=r[u],a=c-1;a>=0;a--){o=0,t=l[a];for(i in n)n.hasOwnProperty(i)&&i in t&&(o+=n[i]*t[i]);o&&(s[a]=o)}m[u]=s}return m},numeric.sdotMV=function(r,e){var n,t,u,i,a=r.length,o=Array(a);for(t=a-1;t>=0;t--){n=r[t],i=0;for(u in n)n.hasOwnProperty(u)&&e[u]&&(i+=n[u]*e[u]);i&&(o[t]=i)}return o},numeric.sdotVM=function(r,e){var n,t,u,i,a=[];for(n in r)if(r.hasOwnProperty(n)){u=e[n],i=r[n];for(t in u)u.hasOwnProperty(t)&&(a[t]||(a[t]=0),a[t]+=i*u[t])}return a},numeric.sdotVV=function(r,e){var n,t=0;for(n in r)r[n]&&e[n]&&(t+=r[n]*e[n]);return t},numeric.sdot=function(r,e){var n=numeric.sdim(r).length,t=numeric.sdim(e).length,u=1e3*n+t;switch(u){case 0:return r*e;case 1001:return numeric.sdotVV(r,e);case 2001:return numeric.sdotMV(r,e);case 1002:return numeric.sdotVM(r,e);case 2002:return numeric.sdotMM(r,e);default:throw new Error("numeric.sdot not implemented for tensors of order "+n+" and "+t)}},numeric.sscatter=function(r){var e,n,t,u,i=r[0].length,a=r.length,o=[];for(n=i-1;n>=0;--n)if(r[a-1][n]){for(u=o,t=0;t=0;--u)e[u]=[];for(u=t;u>=0;--u)e[u].push(n[u]);e[t+1].push(i)}}else l(i,e,n);return n.length>t&&n.pop(),e},numeric.cLU=function(r){var e,n,t,u,i,a,o=r[0],s=r[1],f=r[2],l=o.length,c=0;for(e=0;ec&&(c=o[e]);c++;var m,p,h,g=Array(c),v=Array(c),d=numeric.rep([c],1/0),y=numeric.rep([c],-(1/0));for(t=0;ty[e]&&(y[e]=n);for(e=0;ey[e+1]&&(y[e+1]=y[e]);for(e=c-1;e>=1;e--)d[e]=0;n--){for(;c[t]>n;)a[n]-=m[t]*a[c[t]],t--;a[n]/=m[t],t--}return a},numeric.cgrid=function(r,e){"number"==typeof r&&(r=[r,r]);var n,t,u,i=numeric.rep(r,-1);if("function"!=typeof e)switch(e){case"L":e=function(e,n){return e>=r[0]/2||nu&&(u=i[t]);for(u++,n=numeric.rep([u],0),t=0;t1;)t=a((e+n)/2),u[t]<=r?e=t:n=t;return this._at(r,e)}var o,i=r.length,s=Array(i);for(o=i-1;o!==-1;--o)s[o]=this.at(r[o]);return s},numeric.Spline.prototype.diff=function(){var r,e,n,t=this.x,u=this.yl,i=this.yr,a=this.kl,o=this.kr,s=u.length,f=a,l=o,c=Array(s),m=Array(s),p=numeric.add,h=numeric.mul,g=numeric.div,v=numeric.sub;for(r=s-1;r!==-1;--r)e=t[r+1]-t[r],n=v(i[r+1],u[r]),c[r]=g(p(h(n,6),h(a[r],-4*e),h(o[r+1],-2*e)),e*e),m[r+1]=g(p(h(n,-6),h(a[r],2*e),h(o[r+1],4*e)),e*e);return new numeric.Spline(t,f,l,c,m)},numeric.Spline.prototype.roots=function(){function r(r){return r*r}var e=[],n=this.x,t=this.yl,u=this.yr,i=this.kl,a=this.kr;"number"==typeof t[0]&&(t=[t],u=[u],i=[i],a=[a]);var o,s,f,l,c,m,p,h,g,v,d,y,b,N,E,x,M,I,A,T,w,S,R,O,D=t.length,C=n.length-1,e=Array(D),L=Math.sqrt;for(o=0;o!==D;++o){for(l=t[o],c=u[o],m=i[o],p=a[o],h=[],s=0;s!==C;s++){for(s>0&&c[s]*l[s]<0&&h.push(n[s]),x=n[s+1]-n[s],M=n[s],d=l[s],y=c[s+1],g=m[s]/x,v=p[s+1]/x,E=r(g-v+3*(d-y))+12*v*d,b=v+3*d+2*g-3*y,N=3*(v+g+2*(d-y)),E<=0?(A=b/N,I=A>n[s]&&An[s]&&An[s]&&T0)S=R,A=T;else{for(var P=0;;){if(O=(A*R-T*S)/(A-T),O<=S||O>=R)break;if(w=this._at(O,s),w*T>0)R=O,T=w,P===-1&&(A*=.5),P=-1;else{if(!(w*A>0))break;S=O,A=w,1===P&&(T*=.5),P=1}}h.push(O),S=I[f+1],A=this._at(S,s)}else h.push(S),S=R,A=T;0===T&&h.push(R)}e[o]=h}return"number"==typeof this.yl[0]?e[0]:e},numeric.spline=function(r,e,n,t){var u,i=r.length,a=[],o=[],s=[],f=numeric.sub,l=numeric.mul,c=numeric.add;for(u=i-2;u>=0;u--)o[u]=r[u+1]-r[u],s[u]=f(e[u+1],e[u]);"string"!=typeof n&&"string"!=typeof t||(n=t="periodic");var m=[[],[],[]];switch(typeof n){case"undefined":a[0]=l(3/(o[0]*o[0]),s[0]),m[0].push(0,0),m[1].push(0,1),m[2].push(2/o[0],1/o[0]);break;case"string":a[0]=c(l(3/(o[i-2]*o[i-2]),s[i-2]),l(3/(o[0]*o[0]),s[0])),m[0].push(0,0,0),m[1].push(i-2,0,1),m[2].push(1/o[i-2],2/o[i-2]+2/o[0],1/o[0]);break;default:a[0]=n,m[0].push(0),m[1].push(0),m[2].push(1)}for(u=1;u20)throw new Error("Numerical gradient fails");if(g[u]=e[u]+E,i=r(g),g[u]=e[u]-E,a=r(g),g[u]=e[u],isNaN(i)||isNaN(a))E/=16;else{if(v[u]=(i-a)/(2*E),s=e[u]-E,f=e[u],l=e[u]+E,c=(i-t)/E,m=(t-a)/E,p=h(y(v[u]),y(t),y(i),y(a),y(s),y(f),y(l),1e-8),o=b(h(y(c-v[u]),y(m-v[u]),y(c-m))/p,E/p),!(o>d))break;E/=16}}return v},numeric.uncmin=function(r,e,n,t,u,i,a){var o=numeric.gradient;"undefined"==typeof a&&(a={}),"undefined"==typeof n&&(n=1e-8),"undefined"==typeof t&&(t=function(e){return o(r,e)}),"undefined"==typeof u&&(u=1e3),e=numeric.clone(e);var s,f,l=e.length,c=r(e);if(isNaN(c))throw new Error("uncmin: f(x0) is a NaN!");var m=Math.max,p=numeric.norm2;n=m(n,numeric.epsilon);var h,g,v,d,y,b,N,E,x,M,I=a.Hinv||numeric.identity(l),A=numeric.dot,T=(numeric.inv,numeric.sub),w=numeric.add,S=numeric.tensor,R=numeric.div,O=numeric.mul,D=numeric.all,C=numeric.isFinite,L=numeric.neg,P=0,j="";for(g=t(e);P=.1*x*f||isNaN(s));)x*=.5,++P;if(x*M1;)t=u(.5*(e+n)),o[t]<=r?e=t:n=t;return this._at(r,e)},numeric.dopri=function(r,e,n,t,u,i,a){"undefined"==typeof u&&(u=1e-6),"undefined"==typeof i&&(i=1e3);var o,s,f,l,c,m,p,h,g,v,d,y,b,N=[r],E=[n],x=[t(r,n)],M=[],I=.2,A=[.075,.225],T=[44/45,-56/15,32/9],w=[19372/6561,-25360/2187,64448/6561,-212/729],S=[9017/3168,-355/33,46732/5247,49/176,-5103/18656],R=[35/384,0,500/1113,125/192,-2187/6784,11/84],O=[.10013431883002395,0,.3918321794184259,-.02982460176594817,.05893268337240795,-.04497888809104361,.023904308236133973],D=[.2,.3,.8,8/9,1,1],C=[-71/57600,0,71/16695,-71/1920,17253/339200,-22/525,.025],L=0,P=(e-r)/10,j=0,_=numeric.add,V=numeric.mul,F=(Math.max,Math.min),U=Math.abs,k=numeric.norminf,q=Math.pow,G=numeric.any,B=numeric.lt,Y=numeric.and,X=(numeric.sub,new numeric.Dopri(N,E,x,M,(-1),""));for("function"==typeof a&&(d=a(r,n));re&&(P=e-r),o=t(r+D[0]*P,_(n,V(I*P,x[L]))),s=t(r+D[1]*P,_(_(n,V(A[0]*P,x[L])),V(A[1]*P,o))),f=t(r+D[2]*P,_(_(_(n,V(T[0]*P,x[L])),V(T[1]*P,o)),V(T[2]*P,s))),l=t(r+D[3]*P,_(_(_(_(n,V(w[0]*P,x[L])),V(w[1]*P,o)),V(w[2]*P,s)),V(w[3]*P,f))),c=t(r+D[4]*P,_(_(_(_(_(n,V(S[0]*P,x[L])),V(S[1]*P,o)),V(S[2]*P,s)),V(S[3]*P,f)),V(S[4]*P,l))),g=_(_(_(_(_(n,V(x[L],P*R[0])),V(s,P*R[2])),V(f,P*R[3])),V(l,P*R[4])),V(c,P*R[5])),m=t(r+P,g),p=_(_(_(_(_(V(x[L],P*C[0]),V(s,P*C[2])),V(f,P*C[3])),V(l,P*C[4])),V(c,P*C[5])),V(m,P*C[6])),v="number"==typeof p?U(p):k(p),v>u){if(P=.2*P*q(u/v,.25),r+P===r){X.msg="Step size became too small";break}}else{if(M[L]=_(_(_(_(_(_(n,V(x[L],P*O[0])),V(s,P*O[2])),V(f,P*O[3])),V(l,P*O[4])),V(c,P*O[5])),V(m,P*O[6])),++L,N[L]=r+P,E[L]=g,x[L]=m,"function"==typeof a){var H,Q,K=r,W=r+.5*P;if(y=a(W,M[L-1]),b=Y(B(d,0),B(0,y)),G(b)||(K=W,W=r+P,d=y,y=a(W,g),b=Y(B(d,0),B(0,y))),G(b)){for(var z,Z,$=0,J=1,rr=1;;){if("number"==typeof d)Q=(rr*y*K-J*d*W)/(rr*y-J*d);else for(Q=W,h=d.length-1;h!==-1;--h)d[h]<0&&y[h]>0&&(Q=F(Q,(rr*y[h]*K-J*d[h]*W)/(rr*y[h]-J*d[h])));if(Q<=K||Q>=W)break;H=X._at(Q,L-1),Z=a(Q,H),z=Y(B(d,0),B(0,Z)),G(z)?(W=Q,y=Z,b=z,rr=1,$===-1?J*=.5:J=1,$=-1):(K=Q,d=Z,J=1,1===$?rr*=.5:rr=1,$=1)}return g=X._at(.5*(r+Q),L-1),X.f[L]=t(Q,H),X.x[L]=Q,X.y[L]=H,X.ymid[L-1]=g,X.events=b,X.iterations=j,X}}r+=P,n=g,d=y,P=F(.8*P*q(u/v,.25),4*P)}return X.iterations=j,X},numeric.LU=function(r,e){e=e||!1;var n,t,u,i,a,o,s,f,l,c=Math.abs,m=r.length,p=m-1,h=new Array(m);for(e||(r=numeric.clone(r)),u=0;u=0;--n){for(i=o[n],t=n+1;t_)&&(E=_),l=v(r,m(E,S)),s=h(j,R),L=d-1;L!==-1;--L)s[L][L]+=1;P=O(s,g(l,E),!0);var V=g(D,h(e,P)),F=1;for(L=y-1;L!==-1;--L)V[L]<0&&(F=A(F,-.999*V[L]));if(o=p(i,m(P,F)),D=p(n,h(e,o)),!T(w(D,0)))return{solution:i,message:"",iterations:f};if(i=o,E=0);if(b)return{solution:o,message:"Unbounded",iterations:f}}return{solution:i,message:"maximum iteration count exceeded",iterations:f}},numeric._solveLP=function(r,e,n,t,u){var i,a=r.length,o=n.length,s=(numeric.sum,numeric.log,numeric.mul,numeric.sub),f=numeric.dot,l=(numeric.div,numeric.add,numeric.rep([a],0).concat([1])),c=numeric.rep([o,1],-1),m=numeric.blockMatrix([[e,c]]),p=n,i=numeric.rep([a],0).concat(Math.max(0,numeric.sup(numeric.neg(n)))+1),h=numeric.__solveLP(l,m,p,t,u,i,!1),g=numeric.clone(h.solution);g.length=a;var v=numeric.inf(s(n,f(e,g)));if(v<0)return{solution:NaN,message:"Infeasible",iterations:h.iterations};var d=numeric.__solveLP(r,e,n,t,u-h.iterations,g,!0);return d.iterations+=h.iterations,d},numeric.solveLP=function(r,e,n,t,u,i,a){if("undefined"==typeof a&&(a=1e3),"undefined"==typeof i&&(i=numeric.epsilon),"undefined"==typeof t)return numeric._solveLP(r,e,n,i,a);var o,s=t.length,f=t[0].length,l=e.length,c=numeric.echelonize(t),m=numeric.rep([f],0),p=c.P,h=[];for(o=p.length-1;o!==-1;--o)m[p[o]]=1;for(o=f-1;o!==-1;--o)0===m[o]&&h.push(o);var g=numeric.getRange,v=numeric.linspace(0,s-1),d=numeric.linspace(0,l-1),y=g(t,v,h),b=g(e,d,p),N=g(e,d,h),E=numeric.dot,x=numeric.sub,M=E(b,c.I),I=x(N,E(M,y)),A=x(n,E(M,u)),T=Array(p.length),w=Array(h.length);for(o=p.length-1;o!==-1;--o)T[o]=r[p[o]];for(o=h.length-1;o!==-1;--o)w[o]=r[h[o]];var S=x(w,E(T,E(c.I,y))),R=numeric._solveLP(S,I,A,i,a),O=R.solution;if(O!==O)return R;var D=E(c.I,x(u,E(y,O))),C=Array(r.length);for(o=p.length-1;o!==-1;--o)C[p[o]]=D[o];for(o=h.length-1;o!==-1;--o)C[h[o]]=O[o];return{solution:C,message:R.message,iterations:R.iterations}},numeric.MPStoLP=function(r){function e(e){throw new Error("MPStoLP: "+e+"\nLine "+n+": "+r[n]+"\nCurrent state: "+o[a]+"\n")}r instanceof String&&r.split("\n");var n,t,u,i,a=0,o=["Initial state","NAME","ROWS","COLUMNS","RHS","BOUNDS","ENDATA"],s=r.length,f=0,l={},c=[],m=0,p={},h=0,g=[],v=[],d=[];for(n=0;n=i;)r/=2,e/=2,o>>>=1;return(r+o)/e},l},a=e.pow(n,t),u=e.pow(2,u),i=2*u,f(e.random(),r)}([],numeric.seedrandom,256,6,52),function(r){function e(r){if("object"!=typeof r)return r;var n,t=[],u=r.length;for(n=0;np)d[T]=U;else if(d[T]=-Math.abs(U),U>0){for(A=1;A<=a;A+=1)f[A][I]=-f[A][I];l[I]=-l[I]}}for(I=1;I<=g;I+=1)d[L+h[I]]=0;for(j=0,F=0,I=1;I<=m;I+=1)d[L+I]=1;I-=1){for(U=d[I],T=C+I*(I+3)/2,w=T-I,A=I+1;A<=g;A+=1)U-=d[T]*d[D+A],T+=A;if(U/=d[w],d[D+I]=U,h[I]p)d[L+j]=U;else if(d[L+j]=-Math.abs(U),U>0){for(A=1;A<=a;A+=1)f[A][j]=-f[A][j];l[j]=-l[j]}return 700}for(g+=1,h[g]=j,T=C+(g-1)*g/2+1,I=1;I<=g-1;I+=1)d[T]=d[I],T+=1;if(g===a)d[T]=d[a];else{for(I=a;I>=g+1&&0!==d[I]&&(G=Math.max(Math.abs(d[I-1]),Math.abs(d[I])),B=Math.min(Math.abs(d[I-1]),Math.abs(d[I])),F=d[I-1]>=0?Math.abs(G*Math.sqrt(1+B*B/(G*G))):-Math.abs(G*Math.sqrt(1+B*B/(G*G))),G=d[I-1]/F,B=d[I]/F,1!==G);I-=1)if(0===G)for(d[I-1]=B*F,A=1;A<=a;A+=1)F=r[A][I-1],r[A][I-1]=r[A][I],r[A][I]=F;else for(d[I-1]=F,Y=B/(1+G),A=1;A<=a;A+=1)F=G*r[A][I-1]+B*r[A][I],r[A][I]=Y*(r[A][I-1]+F)-r[A][I],r[A][I-1]=F;d[T]=d[g]}return 0}function E(){if(T=C+R*(R+1)/2+1,w=T+R,0===d[w])return 798;if(G=Math.max(Math.abs(d[w-1]),Math.abs(d[w])),B=Math.min(Math.abs(d[w-1]),Math.abs(d[w])),F=d[w-1]>=0?Math.abs(G*Math.sqrt(1+B*B/(G*G))):-Math.abs(G*Math.sqrt(1+B*B/(G*G))),G=d[w-1]/F,B=d[w]/F,1===G)return 798;if(0===G){for(I=R+1;I<=g;I+=1)F=d[w-1],d[w-1]=d[w],d[w]=F,w+=I;for(I=1;I<=a;I+=1)F=r[I][R],r[I][R]=r[I][R+1],r[I][R+1]=F}else{for(Y=B/(1+G),I=R+1;I<=g;I+=1)F=G*d[w-1]+B*d[w],d[w]=Y*(d[w-1]+F)-d[w],d[w-1]=F,w+=I;for(I=1;I<=a;I+=1)F=G*r[I][R]+B*r[I][R+1],r[I][R+1]=Y*(r[I][R]+F)-r[I][R+1],r[I][R]=F}return 0}function x(){for(w=T-R,I=1;I<=R;I+=1)d[w]=d[T],T+=1,w+=1;return d[P+R]=d[P+R+1],h[R]=h[R+1],R+=1,Re?r*Math.sqrt(1+e*e/r/r):0==e?r:e*Math.sqrt(1+r*r/e/e)}var n,t=numeric.epsilon,u=1e-64/t,i=50,a=0,o=0,s=0,f=0,l=0,c=numeric.clone(r),m=c.length,p=c[0].length;if(m=0&&(y=-y),b=d*y-M,c[o][o]=d-y,s=l;s=0&&(y=-y),b=d*y-M,c[o][o+1]=d-y,s=l;sN&&(N=E)}for(o=p-1;o!=-1;o+=-1){if(0!=y){for(b=y*c[o][o+1],s=l;s=i-1)throw"Error: no convergence.";for(N=g[l],E=g[f-1],y=h[f-1],b=h[f],d=((E-x)*(E+x)+(y-b)*(y+b))/(2*b*E),y=e(d,1),d=d<0?((N-x)*(N+x)+b*(E/(d-y)-b))/N:((N-x)*(N+x)+b*(E/(d+y)-b))/N,a=1,M=1,o=l+1;o=0;s--)if(g[s]=n)return t;t++}},exports.CHISQ={},exports.CHISQ.DIST=function(r,e,n){return r=utils.parseNumber(r),e=utils.parseNumber(e),utils.anyIsError(r,e)?error.value:n?jStat.chisquare.cdf(r,e):jStat.chisquare.pdf(r,e)},exports.CHISQ.DIST.RT=function(r,e){return!r|!e?error.na:r<1||e>Math.pow(10,10)?error.num:"number"!=typeof r||"number"!=typeof e?error.value:1-jStat.chisquare.cdf(r,e)},exports.CHISQ.INV=function(r,e){return r=utils.parseNumber(r),e=utils.parseNumber(e),utils.anyIsError(r,e)?error.value:jStat.chisquare.inv(r,e)},exports.CHISQ.INV.RT=function(r,e){return!r|!e?error.na:r<0||r>1||e<1||e>Math.pow(10,10)?error.num:"number"!=typeof r||"number"!=typeof e?error.value:jStat.chisquare.inv(1-r,e)},exports.CHISQ.TEST=function(r,e){function n(r,e){var n=Math.exp(-.5*r);e%2===1&&(n*=Math.sqrt(2*r/l));for(var t=e;t>=2;)n=n*r/t,t-=2;for(var u=n,i=e;u>1e-10*n;)i+=2,u=u*r/i,n+=u;return 1-n}if(2!==arguments.length)return error.na;if(!(r instanceof Array&&e instanceof Array))return error.value;if(r.length!==e.length)return error.value;if(r[0]&&e[0]&&r[0].length!==e[0].length)return error.value;var t,u,i,a=r.length;for(u=0;u=!]/.test(criteria)||(criteria='=="'+criteria+'"');for(var matches=0,i=0;i=!]/.test(criteria)||(criteria='=="'+criteria+'"');for(var j=0;j1?error.num:jStat.centralF.inv(r,e,n)},exports.F.INV.RT=function(r,e,n){return 3!==arguments.length?error.na:r<0||r>1||e<1||e>Math.pow(10,10)||n<1||n>Math.pow(10,10)?error.num:"number"!=typeof r||"number"!=typeof e||"number"!=typeof n?error.value:jStat.centralF.inv(1-r,e,n)},exports.F.TEST=function(r,e){if(!r||!e)return error.na;if(!(r instanceof Array&&e instanceof Array))return error.na;if(r.length<2||e.length<2)return error.div0;var n=function(r,e){for(var n=0,t=0;te[i-1]&&r[a]<=e[i]&&(u[i]+=1):i===t&&r[a]>e[t-1]&&(u[t]+=1)}return u},exports.GAMMA=function(r){return r=utils.parseNumber(r),r instanceof Error?r:0===r?error.num:parseInt(r,10)===r&&r<0?error.num:jStat.gammafn(r)},exports.GAMMA.DIST=function(r,e,n,t){return 4!==arguments.length?error.na:r<0||e<=0||n<=0?error.value:"number"!=typeof r||"number"!=typeof e||"number"!=typeof n?error.value:t?jStat.gamma.cdf(r,e,n,!0):jStat.gamma.pdf(r,e,n,!1)},exports.GAMMA.INV=function(r,e,n){return 3!==arguments.length?error.na:r<0||r>1||e<=0||n<=0?error.num:"number"!=typeof r||"number"!=typeof e||"number"!=typeof n?error.value:jStat.gamma.inv(r,e,n)},exports.GAMMALN=function(r){return r=utils.parseNumber(r),r instanceof Error?r:jStat.gammaln(r)},exports.GAMMALN.PRECISE=function(r){return 1!==arguments.length?error.na:r<=0?error.num:"number"!=typeof r?error.value:jStat.gammaln(r)},exports.GAUSS=function(r){return r=utils.parseNumber(r),r instanceof Error?r:jStat.normal.cdf(r,0,1)-.5},exports.GEOMEAN=function(){var r=utils.parseNumberArray(utils.flatten(arguments));return r instanceof Error?r:jStat.geomean(r)},exports.GROWTH=function(r,e,n,t){if(r=utils.parseNumberArray(r),r instanceof Error)return r;var u;if(void 0===e)for(e=[],u=1;u<=r.length;u++)e.push(u);if(void 0===n)for(n=[],u=1;u<=r.length;u++)n.push(u);if(e=utils.parseNumberArray(e),n=utils.parseNumberArray(n),utils.anyIsError(e,n))return error.value;void 0===t&&(t=!0);var i=r.length,a=0,o=0,s=0,f=0;for(u=0;ui&&(i=t[e],u=[]),t[e]===i&&(u[u.length]=e);return u},exports.MODE.SNGL=function(){var r=utils.parseNumberArray(utils.flatten(arguments));return r instanceof Error?r:exports.MODE.MULT(r).sort(function(r,e){return r-e})[0]},exports.NEGBINOM={},exports.NEGBINOM.DIST=function(r,e,n,t){return r=utils.parseNumber(r),e=utils.parseNumber(e),n=utils.parseNumber(n),utils.anyIsError(r,e,n)?error.value:t?jStat.negbin.cdf(r,e,n):jStat.negbin.pdf(r,e,n)},exports.NORM={},exports.NORM.DIST=function(r,e,n,t){return r=utils.parseNumber(r),e=utils.parseNumber(e),n=utils.parseNumber(n),utils.anyIsError(r,e,n)?error.value:n<=0?error.num:t?jStat.normal.cdf(r,e,n):jStat.normal.pdf(r,e,n)},exports.NORM.INV=function(r,e,n){return r=utils.parseNumber(r),e=utils.parseNumber(e),n=utils.parseNumber(n),utils.anyIsError(r,e,n)?error.value:jStat.normal.inv(r,e,n)},exports.NORM.S={},exports.NORM.S.DIST=function(r,e){return r=utils.parseNumber(r),r instanceof Error?error.value:e?jStat.normal.cdf(r,0,1):jStat.normal.pdf(r,0,1)},exports.NORM.S.INV=function(r){return r=utils.parseNumber(r),r instanceof Error?error.value:jStat.normal.inv(r,0,1)},exports.PEARSON=function(r,e){if(e=utils.parseNumberArray(utils.flatten(e)),r=utils.parseNumberArray(utils.flatten(r)),utils.anyIsError(e,r))return error.value;for(var n=jStat.mean(r),t=jStat.mean(e),u=r.length,i=0,a=0,o=0,s=0;s1-1/(n+1))return error.num;var t=e*(n+1)-1,u=Math.floor(t);return utils.cleanFloat(t===u?r[t]:r[u]+(t-u)*(r[u+1]-r[u]))},exports.PERCENTILE.INC=function(r,e){if(r=utils.parseNumberArray(utils.flatten(r)),e=utils.parseNumber(e),utils.anyIsError(r,e))return error.value;r=r.sort(function(r,e){return r-e});var n=r.length,t=e*(n-1),u=Math.floor(t);return utils.cleanFloat(t===u?r[t]:r[u]+(t-u)*(r[u+1]-r[u]))},exports.PERCENTRANK={},exports.PERCENTRANK.EXC=function(r,e,n){if(n=void 0===n?3:n,r=utils.parseNumberArray(utils.flatten(r)),e=utils.parseNumber(e),n=utils.parseNumber(n),utils.anyIsError(r,e,n))return error.value;r=r.sort(function(r,e){return r-e});for(var t=misc.UNIQUE.apply(null,r),u=r.length,i=t.length,a=Math.pow(10,n),o=0,s=!1,f=0;!s&&f=t[f]&&(e=t[f]&&(e=0?e[r.indexOf(n)]:0;for(var u=r.sort(function(r,e){return r-e}),i=u.length,a=0,o=0;o=n&&u[o]<=t&&(a+=e[r.indexOf(u[o])]);return a},exports.QUARTILE={},exports.QUARTILE.EXC=function(r,e){if(r=utils.parseNumberArray(utils.flatten(r)),e=utils.parseNumber(e),utils.anyIsError(r,e))return error.value;switch(e){case 1:return exports.PERCENTILE.EXC(r,.25);case 2:return exports.PERCENTILE.EXC(r,.5);case 3:return exports.PERCENTILE.EXC(r,.75);default:return error.num}},exports.QUARTILE.INC=function(r,e){if(r=utils.parseNumberArray(utils.flatten(r)),e=utils.parseNumber(e),utils.anyIsError(r,e))return error.value;switch(e){case 1:return exports.PERCENTILE.INC(r,.25);case 2:return exports.PERCENTILE.INC(r,.5);case 3:return exports.PERCENTILE.INC(r,.75);default:return error.num}},exports.RANK={},exports.RANK.AVG=function(r,e,n){if(r=utils.parseNumber(r),e=utils.parseNumberArray(utils.flatten(e)),utils.anyIsError(r,e))return error.value;e=utils.flatten(e),n=n||!1;var t=n?function(r,e){return r-e}:function(r,e){return e-r};e=e.sort(t);for(var u=e.length,i=0,a=0;a1?(2*e.indexOf(r)+i+1)/2:e.indexOf(r)+1},exports.RANK.EQ=function(r,e,n){if(r=utils.parseNumber(r),e=utils.parseNumberArray(utils.flatten(e)),utils.anyIsError(r,e))return error.value;n=n||!1;var t=n?function(r,e){return r-e}:function(r,e){return e-r};return e=e.sort(t),e.indexOf(r)+1},exports.ROW=function(r,e){if(2!==arguments.length)return error.na;if(e<0)return error.num;if(!(r instanceof Array)||"number"!=typeof e)return error.value;if(0!==r.length)return jStat.row(r,e)},exports.ROWS=function(r){return 1!==arguments.length?error.na:r instanceof Array?0===r.length?0:jStat.rows(r):error.value},exports.RSQ=function(r,e){return r=utils.parseNumberArray(utils.flatten(r)),e=utils.parseNumberArray(utils.flatten(e)),utils.anyIsError(r,e)?error.value:Math.pow(exports.PEARSON(r,e),2)},exports.SKEW=function(){var r=utils.parseNumberArray(utils.flatten(arguments));if(r instanceof Error)return r;for(var e=jStat.mean(r),n=r.length,t=0,u=0;u1||e<1?error.num:utils.anyIsError(r,e)?error.value:Math.abs(jStat.studentt.inv(r/2,e))},exports.T.TEST=function(r,e){if(r=utils.parseNumberArray(utils.flatten(r)),e=utils.parseNumberArray(utils.flatten(e)),utils.anyIsError(r,e))return error.value;var n,t=jStat.mean(r),u=jStat.mean(e),i=0,a=0;for(n=0;n-1;)r[e]="TRUE";for(var n=0;(n=r.indexOf(!1))>-1;)r[n]="FALSE";return r.join("")},e.DBCS=function(){throw new Error("DBCS is not implemented")},e.DOLLAR=function(r,e){if(e=void 0===e?2:e,r=t.parseNumber(r),e=t.parseNumber(e),t.anyIsError(r,e))return u.value;var n="";return e<=0?(r=Math.round(r*Math.pow(10,e))/Math.pow(10,e),n="($0,0)"):e>0&&(n="($0,0."+new Array(e+1).join("0")+")"),i(r).format(n)},e.EXACT=function(r,e){return r===e},e.FIND=function(r,e,n){return n=void 0===n?0:n,e?e.indexOf(r,n-1)+1:null},e.FIXED=function(r,e,n){if(e=void 0===e?2:e,n=void 0!==n&&n,r=t.parseNumber(r),e=t.parseNumber(e),t.anyIsError(r,e))return u.value;var a=n?"0":"0,0";return e<=0?r=Math.round(r*Math.pow(10,e))/Math.pow(10,e):e>0&&(a+="."+new Array(e+1).join("0")),i(r).format(a)},e.HTML2TEXT=function(r){var e="";return r&&(r instanceof Array?r.forEach(function(r){""!==e&&(e+="\n"),e+=r.replace(/<(?:.|\n)*?>/gm,"")}):e=r.replace(/<(?:.|\n)*?>/gm,"")),e},e.LEFT=function(r,e){return e=void 0===e?1:e,e=t.parseNumber(e),e instanceof Error||"string"!=typeof r?u.value:r?r.substring(0,e):null},e.LEN=function(r){return 0===arguments.length?u.error:"string"==typeof r?r?r.length:0:r.length?r.length:u.value},e.LOWER=function(r){return"string"!=typeof r?u.value:r?r.toLowerCase():r},e.MID=function(r,e,n){if(e=t.parseNumber(e),n=t.parseNumber(n),t.anyIsError(e,n)||"string"!=typeof r)return n;var u=e-1,i=u+n;return r.substring(u,i)},e.NUMBERVALUE=function(r,e,n){return e="undefined"==typeof e?".":e,n="undefined"==typeof n?",":n,Number(r.replace(e,".").replace(n,""))},e.PRONETIC=function(){throw new Error("PRONETIC is not implemented")},e.PROPER=function(r){return void 0===r||0===r.length?u.value:(r===!0&&(r="TRUE"),r===!1&&(r="FALSE"),isNaN(r)&&"number"==typeof r?u.value:("number"==typeof r&&(r=""+r),r.replace(/\w\S*/g,function(r){return r.charAt(0).toUpperCase()+r.substr(1).toLowerCase()})))},e.REGEXEXTRACT=function(r,e){var n=r.match(new RegExp(e));return n?n[n.length>1?n.length-1:0]:null},e.REGEXMATCH=function(r,e,n){var t=r.match(new RegExp(e));return n?t:!!t},e.REGEXREPLACE=function(r,e,n){return r.replace(new RegExp(e),n)},e.REPLACE=function(r,e,n,i){return e=t.parseNumber(e),n=t.parseNumber(n),t.anyIsError(e,n)||"string"!=typeof r||"string"!=typeof i?u.value:r.substr(0,e-1)+i+r.substr(e-1+n)},e.REPT=function(r,e){return e=t.parseNumber(e),e instanceof Error?e:new Array(e+1).join(r)},e.RIGHT=function(r,e){return e=void 0===e?1:e,e=t.parseNumber(e),e instanceof Error?e:r?r.substring(r.length-e):null},e.SEARCH=function(r,e,n){var t;return"string"!=typeof r||"string"!=typeof e?u.value:(n=void 0===n?0:n,t=e.toLowerCase().indexOf(r.toLowerCase(),n-1)+1,0===t?u.value:t)},e.SPLIT=function(r,e){return r.split(e)},e.SUBSTITUTE=function(r,e,n,t){if(!(r&&e&&n))return r;if(void 0===t)return r.replace(new RegExp(e,"g"),n);for(var u=0,i=0;r.indexOf(e,u)>0;)if(u=r.indexOf(e,u+1),i++,i===t)return r.substring(0,u)+n+r.substring(u+e.length)},e.T=function(r){return"string"==typeof r?r:""},e.TEXT=function(r,e){return r=t.parseNumber(r),t.anyIsError(r)?u.na:i(r).format(e)},e.TRIM=function(r){return"string"!=typeof r?u.value:r.replace(/ +/g," ").trim()},e.UNICHAR=this.CHAR,e.UNICODE=this.CODE,e.UPPER=function(r){return"string"!=typeof r?u.value:r.toUpperCase()},e.VALUE=function(r){return"string"!=typeof r?u.value:i().unformat(r)}},function(r,e,n){var t,u;/*! + * numeral.js + * version : 1.5.3 + * author : Adam Draper + * license : MIT + * http://adamwdraper.github.com/Numeral-js/ + */ +(function(){function n(r){this._value=r}function i(r,e,n,t){var u,i,a=Math.pow(10,e);return i=(n(r*a)/a).toFixed(e),t&&(u=new RegExp("0{1,"+t+"}$"),i=i.replace(u,"")),i}function a(r,e,n){var t;return t=e.indexOf("$")>-1?s(r,e,n):e.indexOf("%")>-1?f(r,e,n):e.indexOf(":")>-1?l(r,e):m(r._value,e,n)}function o(r,e){var n,t,u,i,a,o=e,s=["KB","MB","GB","TB","PB","EB","ZB","YB"],f=!1;if(e.indexOf(":")>-1)r._value=c(e);else if(e===N)r._value=0;else{for("."!==y[b].delimiters.decimal&&(e=e.replace(/\./g,"").replace(y[b].delimiters.decimal,".")),n=new RegExp("[^a-zA-Z]"+y[b].abbreviations.thousand+"(?:\\)|(\\"+y[b].currency.symbol+")?(?:\\))?)?$"),t=new RegExp("[^a-zA-Z]"+y[b].abbreviations.million+"(?:\\)|(\\"+y[b].currency.symbol+")?(?:\\))?)?$"),u=new RegExp("[^a-zA-Z]"+y[b].abbreviations.billion+"(?:\\)|(\\"+y[b].currency.symbol+")?(?:\\))?)?$"),i=new RegExp("[^a-zA-Z]"+y[b].abbreviations.trillion+"(?:\\)|(\\"+y[b].currency.symbol+")?(?:\\))?)?$"),a=0;a<=s.length&&!(f=e.indexOf(s[a])>-1&&Math.pow(1024,a+1));a++);r._value=(f?f:1)*(o.match(n)?Math.pow(10,3):1)*(o.match(t)?Math.pow(10,6):1)*(o.match(u)?Math.pow(10,9):1)*(o.match(i)?Math.pow(10,12):1)*(e.indexOf("%")>-1?.01:1)*((e.split("-").length+Math.min(e.split("(").length-1,e.split(")").length-1))%2?1:-1)*Number(e.replace(/[^0-9\.]+/g,"")),r._value=f?Math.ceil(r._value):r._value}return r._value}function s(r,e,n){var t,u,i=e.indexOf("$"),a=e.indexOf("("),o=e.indexOf("-"),s="";return e.indexOf(" $")>-1?(s=" ",e=e.replace(" $","")):e.indexOf("$ ")>-1?(s=" ",e=e.replace("$ ","")):e=e.replace("$",""),u=m(r._value,e,n),i<=1?u.indexOf("(")>-1||u.indexOf("-")>-1?(u=u.split(""),t=1,(i-1?(u=u.split(""),u.splice(-1,0,s+y[b].currency.symbol),u=u.join("")):u=u+s+y[b].currency.symbol,u}function f(r,e,n){var t,u="",i=100*r._value;return e.indexOf(" %")>-1?(u=" ",e=e.replace(" %","")):e=e.replace("%",""),t=m(i,e,n),t.indexOf(")")>-1?(t=t.split(""),t.splice(-1,0,u+"%"),t=t.join("")):t=t+u+"%",t}function l(r){var e=Math.floor(r._value/60/60),n=Math.floor((r._value-60*e*60)/60),t=Math.round(r._value-60*e*60-60*n);return e+":"+(n<10?"0"+n:n)+":"+(t<10?"0"+t:t)}function c(r){var e=r.split(":"),n=0;return 3===e.length?(n+=60*Number(e[0])*60,n+=60*Number(e[1]),n+=Number(e[2])):2===e.length&&(n+=60*Number(e[0]),n+=Number(e[1])),Number(n)}function m(r,e,n){var t,u,a,o,s,f,l=!1,c=!1,m=!1,p="",h=!1,g=!1,v=!1,d=!1,E=!1,x="",M="",I=Math.abs(r),A=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],T="",w=!1;if(0===r&&null!==N)return N;if(e.indexOf("(")>-1?(l=!0,e=e.slice(1,-1)):e.indexOf("+")>-1&&(c=!0,e=e.replace(/\+/g,"")),e.indexOf("a")>-1&&(h=e.indexOf("aK")>=0,g=e.indexOf("aM")>=0,v=e.indexOf("aB")>=0,d=e.indexOf("aT")>=0,E=h||g||v||d,e.indexOf(" a")>-1?(p=" ",e=e.replace(" a","")):e=e.replace("a",""),I>=Math.pow(10,12)&&!E||d?(p+=y[b].abbreviations.trillion,r/=Math.pow(10,12)):I=Math.pow(10,9)&&!E||v?(p+=y[b].abbreviations.billion,r/=Math.pow(10,9)):I=Math.pow(10,6)&&!E||g?(p+=y[b].abbreviations.million,r/=Math.pow(10,6)):(I=Math.pow(10,3)&&!E||h)&&(p+=y[b].abbreviations.thousand,r/=Math.pow(10,3))),e.indexOf("b")>-1)for(e.indexOf(" b")>-1?(x=" ",e=e.replace(" b","")):e=e.replace("b",""),a=0;a<=A.length;a++)if(t=Math.pow(1024,a),u=Math.pow(1024,a+1),r>=t&&r0&&(r/=t);break}return e.indexOf("o")>-1&&(e.indexOf(" o")>-1?(M=" ",e=e.replace(" o","")):e=e.replace("o",""),M+=y[b].ordinal(r)),e.indexOf("[.]")>-1&&(m=!0,e=e.replace("[.]",".")),o=r.toString().split(".")[0],s=e.split(".")[1],f=e.indexOf(","),s?(s.indexOf("[")>-1?(s=s.replace("]",""),s=s.split("["),T=i(r,s[0].length+s[1].length,n,s[1].length)):T=i(r,s.length,n),o=T.split(".")[0],T=T.split(".")[1].length?y[b].delimiters.decimal+T.split(".")[1]:"",m&&0===Number(T.slice(1))&&(T="")):o=i(r,null,n),o.indexOf("-")>-1&&(o=o.slice(1),w=!0),f>-1&&(o=o.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+y[b].delimiters.thousands)),0===e.indexOf(".")&&(o=""),(l&&w?"(":"")+(!l&&w?"-":"")+(!w&&c?"+":"")+o+T+(M?M:"")+(p?p:"")+(x?x:"")+(l&&w?")":"")}function p(r,e){y[r]=e}function h(r){var e=r.toString().split(".");return e.length<2?1:Math.pow(10,e[1].length)}function g(){var r=Array.prototype.slice.call(arguments);return r.reduce(function(r,e){var n=h(r),t=h(e);return n>t?n:t},-(1/0))}var v,d="1.5.3",y={},b="en",N=null,E="0,0",x="undefined"!=typeof r&&r.exports;v=function(r){return v.isNumeral(r)?r=r.value():0===r||"undefined"==typeof r?r=0:Number(r)||(r=v.fn.unformat(r)),new n(Number(r))},v.version=d,v.isNumeral=function(r){return r instanceof n},v.language=function(r,e){if(!r)return b;if(r&&!e){if(!y[r])throw new Error("Unknown language : "+r);b=r}return!e&&y[r]||p(r,e),v},v.languageData=function(r){if(!r)return y[b];if(!y[r])throw new Error("Unknown language : "+r);return y[r]},v.language("en",{delimiters:{thousands:",",decimal:"."},abbreviations:{thousand:"k",million:"m",billion:"b",trillion:"t"},ordinal:function(r){var e=r%10;return 1===~~(r%100/10)?"th":1===e?"st":2===e?"nd":3===e?"rd":"th"},currency:{symbol:"$"}}),v.zeroFormat=function(r){N="string"==typeof r?r:null},v.defaultFormat=function(r){E="string"==typeof r?r:"0.0"},"function"!=typeof Array.prototype.reduce&&(Array.prototype.reduce=function(r,e){"use strict";if(null===this||"undefined"==typeof this)throw new TypeError("Array.prototype.reduce called on null or undefined");if("function"!=typeof r)throw new TypeError(r+" is not a function");var n,t,u=this.length>>>0,i=!1;for(1n;++n)this.hasOwnProperty(n)&&(i?t=r(t,this[n],n,this):(t=this[n],i=!0));if(!i)throw new TypeError("Reduce of empty array with no initial value");return t}),v.fn=n.prototype={clone:function(){return v(this)},format:function(r,e){return a(this,r?r:E,void 0!==e?e:Math.round)},unformat:function(r){return"[object Number]"===Object.prototype.toString.call(r)?r:o(this,r?r:E)},value:function(){return this._value},valueOf:function(){return this._value},set:function(r){return this._value=Number(r),this},add:function(r){function e(r,e,t,u){return r+n*e}var n=g.call(null,this._value,r);return this._value=[this._value,r].reduce(e,0)/n,this},subtract:function(r){function e(r,e,t,u){return r-n*e}var n=g.call(null,this._value,r);return this._value=[r].reduce(e,this._value*n)/n,this},multiply:function(r){function e(r,e,n,t){var u=g(r,e);return r*u*(e*u)/(u*u)}return this._value=[this._value,r].reduce(e,1),this},divide:function(r){function e(r,e,n,t){var u=g(r,e);return r*u/(e*u)}return this._value=[this._value,r].reduce(e),this},difference:function(r){return Math.abs(v(this._value).subtract(r).value())}},x&&(r.exports=v),"undefined"==typeof ender&&(this.numeral=v),t=[],u=function(){return v}.apply(e,t),!(void 0!==u&&(r.exports=u))}).call(this)},function(r,e){this.j$=this.jStat=function(r,e){function n(e,n){var t=e>n?e:n;return r.pow(10,17-~~(r.log(t>0?t:-t)*r.LOG10E))}function t(r){return"[object Function]"===m.call(r)}function u(r){return"number"==typeof r&&r===r}function i(r){return l.apply([],r)}function a(){return new a._init(arguments)}function o(){return 0}function s(){return 1}function f(r,e){return r===e?1:0}var l=Array.prototype.concat,c=Array.prototype.slice,m=Object.prototype.toString,p=Array.isArray||function(r){return"[object Array]"===m.call(r)};a.fn=a.prototype,a._init=function(r){var e;if(p(r[0]))if(p(r[0][0])){for(t(r[1])&&(r[0]=a.map(r[0],r[1])),e=0;e=0;e--,t++)n[t]=[r[t][e]];return n},a.transpose=function(r){var e,n,t,u,i,a=[];for(p(r[0])||(r=[r]),n=r.length,t=r[0].length,i=0;i1?c.call(this):c.call(this)[0]},h.map=function(r,e){return a(a.map(this,r,e))},h.alter=function(r){return a.alter(this,r),this},function(r){for(var e=0;e=0;)a+=r[e];return a},r.sumsqrd=function(r){for(var e=0,n=r.length;--n>=0;)e+=r[n]*r[n];return e},r.sumsqerr=function(e){for(var n,t=r.mean(e),u=0,i=e.length;--i>=0;)n=e[i]-t,u+=n*n;return u},r.product=function(r){for(var e=1,n=r.length;--n>=0;)e*=r[n];return e},r.min=function(r){for(var e=r[0],n=0;++ne&&(e=r[n]);return e},r.mean=function(e){return r.sum(e)/e.length},r.meansqerr=function(e){return r.sumsqerr(e)/e.length},r.geomean=function(n){return e.pow(r.product(n),1/n.length)},r.median=function(r){var e=r.length,t=r.slice().sort(n);return 1&e?t[e/2|0]:(t[e/2-1]+t[e/2])/2},r.cumsum=function(r){var e,n=r.length,t=new Array(n);for(t[0]=r[0],e=1;ea?(s=[u[e]],a=i,o=0):i===a&&(s.push(u[e]),o++),i=1);return 0===o?s[0]:s},r.range=function(e){return r.max(e)-r.min(e)},r.variance=function(e,n){return r.sumsqerr(e)/(e.length-(n?1:0))},r.stdev=function(n,t){return e.sqrt(r.variance(n,t))},r.meandev=function(n){var t,u=0,i=r.mean(n);for(t=n.length-1;t>=0;t--)u+=e.abs(n[t]-i);return u/n.length},r.meddev=function(n){var t,u=0,i=r.median(n);for(t=n.length-1;t>=0;t--)u+=e.abs(n[t]-i);return u/n.length},r.coeffvar=function(e){return r.stdev(e)/r.mean(e)},r.quartiles=function(r){var t=r.length,u=r.slice().sort(n);return[u[e.round(t/4)-1],u[e.round(t/2)-1],u[e.round(3*t/4)-1]]},r.quantiles=function(r,u,i,a){var o,s,f,l,c,m,p=r.slice().sort(n),h=[u.length],g=r.length;for("undefined"==typeof i&&(i=3/8),"undefined"==typeof a&&(a=3/8),o=0;o1){for(o=e===!0?this:this.transpose();a1){for(s=n===!0?this:this.transpose();o1){for(a=a.transpose();tm)for(n=0;n=1?n:1/n)+.4*n+17);if(t<0||n<=0)return NaN;if(t170||t>170?e.exp(r.combinationln(n,t)):r.factorial(n)/r.factorial(t)/r.factorial(n-t)},r.combinationln=function(e,n){return r.factorialln(e)-r.factorialln(n)-r.factorialln(e-n)},r.permutation=function(e,n){return r.factorial(e)/r.factorial(e-n)},r.betafn=function(n,t){if(!(n<=0||t<=0))return n+t>170?e.exp(r.betaln(n,t)):r.gammafn(n)*r.gammafn(t)/r.gammafn(n+t)},r.betaln=function(e,n){return r.gammaln(e)+r.gammaln(n)-r.gammaln(e+n)},r.betacf=function(r,n,t){var u,i,a,o,s=1e-30,f=1,l=n+t,c=n+1,m=n-1,p=1,h=1-l*r/c;for(e.abs(h)=1)return e.max(100,t+100*e.sqrt(t));if(n<=0)return 0;for(t>1?(f=e.log(m),l=e.exp(m*(f-1)-h),s=n<.5?n:1-n,a=e.sqrt(-2*e.log(s)),u=(2.30753+.27061*a)/(1+a*(.99229+.04481*a))-a,n<.5&&(u=-u),u=e.max(.001,t*e.pow(1-1/(9*t)-u/(3*e.sqrt(t)),3))):(a=1-t*(.253+.12*t),u=n1?l*e.exp(-(u-m)+m*(e.log(u)-f)):e.exp(-u+m*e.log(u)-h),o=i/a,u-=a=o/(1-.5*e.min(1,o*((t-1)/u-1))),u<=0&&(u=.5*(u+a)),e.abs(a)0;o--)u=f,f=t*f-l+a[o],l=u;return i=n*e.exp(-r*r+.5*(a[0]+t*f)-l),s?i-1:1-i},r.erfc=function(e){return 1-r.erf(e)},r.erfcinv=function(n){var t,u,i,a,o=0;if(n>=2)return-100;if(n<=0)return 100;for(a=n<1?n:2-n,i=e.sqrt(-2*e.log(a/2)),t=-.70711*((2.30753+.27061*i)/(1+i*(.99229+.04481*i))-i);o<2;o++)u=r.erfc(t)-a,t+=u/(1.1283791670955126*e.exp(-t*t)-t*u);return n<1?t:-t},r.ibetainv=function(n,t,u){var i,a,o,s,f,l,c,m,p,h,g,v=1e-8,d=t-1,y=u-1,b=0;if(n<=0)return 0;if(n>=1)return 1;for(t>=1&&u>=1?(o=n<.5?n:1-n,s=e.sqrt(-2*e.log(o)),c=(2.30753+.27061*s)/(1+s*(.99229+.04481*s))-s,n<.5&&(c=-c),m=(c*c-3)/6,p=2/(1/(2*t-1)+1/(2*u-1)),h=c*e.sqrt(m+p)/p-(1/(2*u-1)-1/(2*t-1))*(m+5/6-2/(3*p)),c=t/(t+u*e.exp(2*h))):(i=e.log(t/(t+u)),a=e.log(u/(t+u)),s=e.exp(t*i)/t,f=e.exp(u*a)/u,h=s+f,c=n=1&&(c=.5*(c+s+1)),e.abs(s)0)break}return c},r.ibeta=function(n,t,u){var i=0===n||1===n?0:e.exp(r.gammaln(t+u)-r.gammaln(t)-r.gammaln(u)+t*e.log(n)+u*e.log(1-n));return!(n<0||n>1)&&(n<(t+1)/(t+u+2)?i*r.betacf(n,t,u)/t:1-i*r.betacf(1-n,u,t)/u)},r.randn=function(n,t){var u,i,a,o,s;if(t||(t=n),n)return r.create(n,t,function(){return r.randn()});do u=e.random(),i=1.7156*(e.random()-.5),a=u-.449871,o=e.abs(i)+.386595,s=a*a+o*(.196*o-.25472*a);while(s>.27597&&(s>.27846||i*i>-4*e.log(u)*u*u));return i/u},r.randg=function(n,t,u){var i,a,o,s,f,l,c=n;if(u||(u=t),n||(n=1),t)return l=r.zeros(t,u),l.alter(function(){return r.randg(n)}),l;n<1&&(n+=1),i=n-1/3,a=1/e.sqrt(9*i);do{do f=r.randn(),s=1+a*f;while(s<=0);s=s*s*s,o=e.random()}while(o>1-.331*e.pow(f,4)&&e.log(o)>.5*f*f+i*(1-s+e.log(s)));if(n==c)return i*s;do o=e.random();while(0===o);return e.pow(o,1/c)*i*s},function(e){for(var n=0;n1||n<0?0:1==t&&1==u?1:t<512||u<512?e.pow(n,t-1)*e.pow(1-n,u-1)/r.betafn(t,u):e.exp((t-1)*e.log(n)+(u-1)*e.log(1-n)-r.betaln(t,u))},cdf:function(e,n,t){return e>1||e<0?1*(e>1):r.ibeta(e,n,t)},inv:function(e,n,t){return r.ibetainv(e,n,t)},mean:function(r,e){return r/(r+e)},median:function(r,e){throw new Error("median not yet implemented")},mode:function(r,n){return r*n/(e.pow(r+n,2)*(r+n+1))},sample:function(e,n){var t=r.randg(e);return t/(t+r.randg(n))},variance:function(r,n){return r*n/(e.pow(r+n,2)*(r+n+1))}}),r.extend(r.centralF,{pdf:function(n,t,u){if(!(n<0))return e.sqrt(e.pow(t*n,t)*e.pow(u,u)/e.pow(t*n+u,t+u))/(n*r.betafn(t/2,u/2))},cdf:function(e,n,t){return r.ibeta(n*e/(n*e+t),n/2,t/2)},inv:function(e,n,t){return t/(n*(1/r.ibetainv(e,n/2,t/2)-1))},mean:function(r,e){return e>2?e/(e-2):void 0},mode:function(r,e){return r>2?e*(r-2)/(r*(e+2)):void 0},sample:function(e,n){var t=2*r.randg(e/2),u=2*r.randg(n/2);return t/e/(u/n)},variance:function(r,e){if(!(e<=4))return 2*e*e*(r+e-2)/(r*(e-2)*(e-2)*(e-4))}}),r.extend(r.cauchy,{pdf:function(r,n,t){return t/(e.pow(r-n,2)+e.pow(t,2))/e.PI},cdf:function(r,n,t){return e.atan((r-n)/t)/e.PI+.5},inv:function(r,n,t){return n+t*e.tan(e.PI*(r-.5))},median:function(r,e){return r},mode:function(r,e){return r},sample:function(n,t){return r.randn()*e.sqrt(1/(2*r.randg(.5)))*t+n}}),r.extend(r.chisquare,{pdf:function(n,t){return e.exp((t/2-1)*e.log(n)-n/2-t/2*e.log(2)-r.gammaln(t/2))},cdf:function(e,n){return r.gammap(n/2,e/2)},inv:function(e,n){return 2*r.gammapinv(e,.5*n)},mean:function(r){return r},median:function(r){return r*e.pow(1-2/(9*r),3)},mode:function(r){return r-2>0?r-2:0},sample:function(e){return 2*r.randg(e/2)},variance:function(r){return 2*r}}),r.extend(r.exponential,{pdf:function(r,n){return r<0?0:n*e.exp(-n*r)},cdf:function(r,n){return r<0?0:1-e.exp(-n*r)},inv:function(r,n){return-e.log(1-r)/n},mean:function(r){return 1/r},median:function(r){return 1/r*e.log(2)},mode:function(r){return 0},sample:function(r){return-1/r*e.log(e.random())},variance:function(r){return e.pow(r,-2)}}),r.extend(r.gamma,{pdf:function(n,t,u){return e.exp((t-1)*e.log(n)-n/u-r.gammaln(t)-t*e.log(u))},cdf:function(e,n,t){return r.gammap(n,e/t)},inv:function(e,n,t){return r.gammapinv(e,n)*t},mean:function(r,e){return r*e},mode:function(r,e){if(r>1)return(r-1)*e},sample:function(e,n){return r.randg(e)*n},variance:function(r,e){return r*e*e}}),r.extend(r.invgamma,{pdf:function(n,t,u){return e.exp(-(t+1)*e.log(n)-u/n-r.gammaln(t)+t*e.log(u))},cdf:function(e,n,t){return 1-r.gammap(n,t/e)},inv:function(e,n,t){return t/r.gammapinv(1-e,n)},mean:function(r,e){return r>1?e/(r-1):void 0},mode:function(r,e){return e/(r+1)},sample:function(e,n){return n/r.randg(e)},variance:function(r,e){if(!(r<=2))return e*e/((r-1)*(r-1)*(r-2))}}),r.extend(r.kumaraswamy,{pdf:function(r,n,t){return e.exp(e.log(n)+e.log(t)+(n-1)*e.log(r)+(t-1)*e.log(1-e.pow(r,n)))},cdf:function(r,n,t){return 1-e.pow(1-e.pow(r,n),t)},mean:function(e,n){return n*r.gammafn(1+1/e)*r.gammafn(n)/r.gammafn(1+1/e+n)},median:function(r,n){return e.pow(1-e.pow(2,-1/n),1/r)},mode:function(r,n){if(r>=1&&n>=1&&1!==r&&1!==n)return e.pow((r-1)/(r*n-1),1/r)},variance:function(r,e){throw new Error("variance not yet implemented")}}),r.extend(r.lognormal,{pdf:function(r,n,t){return e.exp(-e.log(r)-.5*e.log(2*e.PI)-e.log(t)-e.pow(e.log(r)-n,2)/(2*t*t))},cdf:function(n,t,u){return.5+.5*r.erf((e.log(n)-t)/e.sqrt(2*u*u))},inv:function(n,t,u){return e.exp(-1.4142135623730951*u*r.erfcinv(2*n)+t)},mean:function(r,n){return e.exp(r+n*n/2)},median:function(r,n){return e.exp(r)},mode:function(r,n){return e.exp(r-n*n)},sample:function(n,t){return e.exp(r.randn()*t+n)},variance:function(r,n){return(e.exp(n*n)-1)*e.exp(2*r+n*n)}}),r.extend(r.normal,{pdf:function(r,n,t){return e.exp(-.5*e.log(2*e.PI)-e.log(t)-e.pow(r-n,2)/(2*t*t))},cdf:function(n,t,u){return.5*(1+r.erf((n-t)/e.sqrt(2*u*u)))},inv:function(e,n,t){return-1.4142135623730951*t*r.erfcinv(2*e)+n},mean:function(r,e){return r},median:function(r,e){return r},mode:function(r,e){return r},sample:function(e,n){return r.randn()*n+e},variance:function(r,e){return e*e}}),r.extend(r.pareto,{pdf:function(r,n,t){if(!(r<=n))return t*e.pow(n,t)/e.pow(r,t+1)},cdf:function(r,n,t){return 1-e.pow(n/r,t)},mean:function(r,n){if(!(n<=1))return n*e.pow(r,n)/(n-1)},median:function(r,n){return r*(n*e.SQRT2)},mode:function(r,e){return r},variance:function(r,n){if(!(n<=2))return r*r*n/(e.pow(n-1,2)*(n-2))}}),r.extend(r.studentt,{pdf:function(n,t){return r.gammafn((t+1)/2)/(e.sqrt(t*e.PI)*r.gammafn(t/2))*e.pow(1+n*n/t,-((t+1)/2))},cdf:function(n,t){var u=t/2;return r.ibeta((n+e.sqrt(n*n+t))/(2*e.sqrt(n*n+t)),u,u)},inv:function(n,t){var u=r.ibetainv(2*e.min(n,1-n),.5*t,.5);return u=e.sqrt(t*(1-u)/u),n>.5?u:-u},mean:function(r){return r>1?0:void 0},median:function(r){return 0},mode:function(r){return 0},sample:function(n){return r.randn()*e.sqrt(n/(2*r.randg(n/2)))},variance:function(r){return r>2?r/(r-2):r>1?1/0:void 0}}),r.extend(r.weibull,{pdf:function(r,n,t){return r<0?0:t/n*e.pow(r/n,t-1)*e.exp(-e.pow(r/n,t))},cdf:function(r,n,t){return r<0?0:1-e.exp(-e.pow(r/n,t))},inv:function(r,n,t){return n*e.pow(-e.log(1-r),1/t)},mean:function(e,n){return e*r.gammafn(1+1/n)},median:function(r,n){return r*e.pow(e.log(2),1/n)},mode:function(r,n){if(!(n<=1))return r*e.pow((n-1)/n,1/n)},sample:function(r,n){return r*e.pow(-e.log(e.random()),1/n)},variance:function(n,t){return n*n*r.gammafn(1+2/t)-e.pow(this.mean(n,t),2)}}),r.extend(r.uniform,{pdf:function(r,e,n){return rn?0:1/(n-e)},cdf:function(r,e,n){return ri||n>u)return 0;if(2*u>t)return 2*i>t?r.hypgeom.pdf(t-u-i+n,t,t-u,t-i):r.hypgeom.pdf(i-n,t,t-u,i);if(2*i>t)return r.hypgeom.pdf(u-n,t,u,t-i);if(u1&&o=i||n>=u)return 1;if(2*u>t)return 2*i>t?r.hypgeom.cdf(t-u-i+n,t,t-u,t-i):1-r.hypgeom.cdf(i-n-1,t,t-u,i);if(2*i>t)return 1-r.hypgeom.cdf(u-n-1,t,u,t-i);if(u1&&su);return t-1}}),r.extend(r.triangular,{pdf:function(r,e,n,t){return n<=e||tn?void 0:rn?0:r<=t?2*(r-e)/((n-e)*(t-e)):2*(n-r)/((n-e)*(n-t))},cdf:function(r,n,t,u){if(!(t<=n||ut))return r(r+n)/2?r+e.sqrt((n-r)*(t-r))/e.sqrt(2):void 0},mode:function(r,e,n){return n},sample:function(r,n,t){var u=e.random();return u<(t-r)/(n-r)?r+e.sqrt(u*(n-r)*(t-r)):n-e.sqrt((1-u)*(n-r)*(n-t))},variance:function(r,e,n){return(r*r+e*e+n*n-r*e-r*n-e*n)/18}})}(this.jStat,Math),function(r,e){var n=Array.prototype.push,t=r.utils.isArray;r.extend({add:function(e,n){return t(n)?(t(n[0])||(n=[n]),r.map(e,function(r,e,t){return r+n[e][t]})):r.map(e,function(r){return r+n})},subtract:function(e,n){return t(n)?(t(n[0])||(n=[n]),r.map(e,function(r,e,t){return r-n[e][t]||0})):r.map(e,function(r){return r-n})},divide:function(e,n){return t(n)?(t(n[0])||(n=[n]),r.multiply(e,r.inv(n))):r.map(e,function(r){return r/n})},multiply:function(e,n){var u,i,a,o,s=e.length,f=e[0].length,l=r.zeros(s,a=t(n)?n[0].length:f),c=0;if(t(n)){for(;c=0;s--){for(p=0,f=s+1;f<=l-1;f++)p=h[f]*n[s][f];h[s]=(n[s][u-1]-p)/n[s][s]}return h},gauss_jordan:function(n,t){for(var u=r.aug(n,t),i=u.length,a=u[0].length,o=0;oe.abs(u[s][o])&&(s=f);var l=u[o];u[o]=u[s],u[s]=l;for(var f=o+1;f=0;o--){c=u[o][o];for(var f=0;fo-1;m--)u[f][m]-=u[o][m]*u[f][o]/c;u[o][o]/=c;for(var m=i;mc?(p[l][c]=n[l][c],h[l][c]=g[l][c]=0):li;)a=f,f=r.add(r.multiply(s,a),o),l++;return f},gauss_seidel:function(n,t,u,i){for(var a,o,s,f,l,c=0,m=n.length,p=[],h=[],g=[];ca?(p[c][a]=n[c][a],h[c][a]=g[c][a]=0):ci;)o=l,l=r.add(r.multiply(f,o),s),c+=1;return l},SOR:function(n,t,u,i,a){for(var o,s,f,l,c,m=0,p=n.length,h=[],g=[],v=[];mo?(h[m][o]=n[m][o],g[m][o]=v[m][o]=0):mi;)s=c,c=r.add(r.multiply(l,s),f),m++;return c},householder:function(n){for(var t,u,i,a,o,s=n.length,f=n[0].length,l=0,c=[],m=[];l0?-1:1,t=o*e.sqrt(t),u=e.sqrt((t*t-n[l+1][l]*t)/2),c=r.zeros(s,1),c[l+1][0]=(n[l+1][l]-t)/(2*u),i=l+2;i0?-1:1,i=s*e.sqrt(i),a=e.sqrt((i*i-n[m+1][m]*i)/2),p=r.zeros(l,1),p[m+1][0]=(n[m+1][m]-i)/(2*a),o=m+2;o=0;m--){for(f=0,u=m+1;u<=c-1;u++)f=g[u]*n[m][u];g[m]=t[m][0]/n[m][m]}return g},jacobi:function(n){for(var t,u,i,a,o,s,f,l,c=1,m=0,p=n.length,h=r.identity(p,p),g=[];1===c;){for(m++,s=n[0][1],a=0,o=1,u=0;u0?e.PI/4:-e.PI/4:e.atan(2*n[a][o]/(n[a][a]-n[o][o]))/2,l=r.identity(p,p),l[a][a]=e.cos(f),l[a][o]=-e.sin(f),l[o][a]=e.sin(f),l[o][o]=e.cos(f),h=r.multiply(h,l),t=r.multiply(r.multiply(r.inv(l),n),l),n=t,c=0,u=1;u.001&&(c=1)}for(u=0;u=c;)a=i(r,t+u),o=i(r,t),p[m]=(n[a]-2*n[o]+n[2*o-a])/(u*u),u/=2,m++;for(f=p.length,s=1;1!=f;){for(l=0;lt);u++);return u-=1,n[u]+(t-e[u])*m[u]+r.sq(t-e[u])*l[u]+(t-e[u])*r.sq(t-e[u])*p[u]},gauss_quadrature:function(){throw new Error("gauss_quadrature not yet implemented")},PCA:function(e){var n,t,u=e.length,i=e[0].length,a=0,o=[],s=[],f=[],l=[],c=[],m=[],p=[],h=[],g=[],v=[];for(a=0;a=0||"number"==typeof r&&(isNaN(r)||!isFinite(r))},e.ISERROR=function(r){return e.ISERR(r)||r===t.na},e.ISEVEN=function(r){return!(1&Math.floor(Math.abs(r)))},e.ISFORMULA=function(){throw new Error("ISFORMULA is not implemented")},e.ISLOGICAL=function(r){return r===!0||r===!1},e.ISNA=function(r){return r===t.na},e.ISNONTEXT=function(r){return"string"!=typeof r},e.ISNUMBER=function(r){return"number"==typeof r&&!isNaN(r)&&isFinite(r)},e.ISODD=function(r){return!!(1&Math.floor(Math.abs(r)))},e.ISREF=function(){throw new Error("ISREF is not implemented")},e.ISTEXT=function(r){return"string"==typeof r},e.N=function(r){return this.ISNUMBER(r)?r:r instanceof Date?r.getTime():r===!0?1:r===!1?0:this.ISERROR(r)?r:0},e.NA=function(){return t.na},e.SHEET=function(){throw new Error("SHEET is not implemented")},e.SHEETS=function(){throw new Error("SHEETS is not implemented")},e.TYPE=function(r){return this.ISNUMBER(r)?1:this.ISTEXT(r)?2:this.ISLOGICAL(r)?4:this.ISERROR(r)?16:Array.isArray(r)?64:void 0}},function(r,e,n){function t(r){return/^[01]{1,10}$/.test(r)}var u=n(5),i=n(9).jStat,a=n(7),o=n(4),s=n(13);e.BESSELI=function(r,e){return r=o.parseNumber(r),e=o.parseNumber(e),o.anyIsError(r,e)?u.value:s.besseli(r,e)},e.BESSELJ=function(r,e){return r=o.parseNumber(r),e=o.parseNumber(e),o.anyIsError(r,e)?u.value:s.besselj(r,e)},e.BESSELK=function(r,e){return r=o.parseNumber(r),e=o.parseNumber(e),o.anyIsError(r,e)?u.value:s.besselk(r,e)},e.BESSELY=function(r,e){return r=o.parseNumber(r),e=o.parseNumber(e),o.anyIsError(r,e)?u.value:s.bessely(r,e)},e.BIN2DEC=function(r){if(!t(r))return u.num;var e=parseInt(r,2),n=r.toString();return 10===n.length&&"1"===n.substring(0,1)?parseInt(n.substring(1),2)-512:e},e.BIN2HEX=function(r,e){if(!t(r))return u.num;var n=r.toString();if(10===n.length&&"1"===n.substring(0,1))return(0xfffffffe00+parseInt(n.substring(1),2)).toString(16);var i=parseInt(r,2).toString(16);return void 0===e?i:isNaN(e)?u.value:e<0?u.num:(e=Math.floor(e),e>=i.length?a.REPT("0",e-i.length)+i:u.num)},e.BIN2OCT=function(r,e){if(!t(r))return u.num;var n=r.toString();if(10===n.length&&"1"===n.substring(0,1))return(1073741312+parseInt(n.substring(1),2)).toString(8);var i=parseInt(r,2).toString(8);return void 0===e?i:isNaN(e)?u.value:e<0?u.num:(e=Math.floor(e),e>=i.length?a.REPT("0",e-i.length)+i:u.num)},e.BITAND=function(r,e){return r=o.parseNumber(r),e=o.parseNumber(e),o.anyIsError(r,e)?u.value:r<0||e<0?u.num:Math.floor(r)!==r||Math.floor(e)!==e?u.num:r>0xffffffffffff||e>0xffffffffffff?u.num:r&e},e.BITLSHIFT=function(r,e){return r=o.parseNumber(r),e=o.parseNumber(e),o.anyIsError(r,e)?u.value:r<0?u.num:Math.floor(r)!==r?u.num:r>0xffffffffffff?u.num:Math.abs(e)>53?u.num:e>=0?r<>-e},e.BITOR=function(r,e){return r=o.parseNumber(r),e=o.parseNumber(e),o.anyIsError(r,e)?u.value:r<0||e<0?u.num:Math.floor(r)!==r||Math.floor(e)!==e?u.num:r>0xffffffffffff||e>0xffffffffffff?u.num:r|e},e.BITRSHIFT=function(r,e){return r=o.parseNumber(r),e=o.parseNumber(e),o.anyIsError(r,e)?u.value:r<0?u.num:Math.floor(r)!==r?u.num:r>0xffffffffffff?u.num:Math.abs(e)>53?u.num:e>=0?r>>e:r<<-e},e.BITXOR=function(r,e){return r=o.parseNumber(r),e=o.parseNumber(e),o.anyIsError(r,e)?u.value:r<0||e<0?u.num:Math.floor(r)!==r||Math.floor(e)!==e?u.num:r>0xffffffffffff||e>0xffffffffffff?u.num:r^e},e.COMPLEX=function(r,e,n){if(r=o.parseNumber(r),e=o.parseNumber(e),o.anyIsError(r,e))return r;if(n=void 0===n?"i":n,"i"!==n&&"j"!==n)return u.value;if(0===r&&0===e)return 0;if(0===r)return 1===e?n:e.toString()+n;if(0===e)return r.toString();var t=e>0?"+":"";return r.toString()+t+(1===e?n:e.toString()+n)},e.CONVERT=function(r,e,n){if(r=o.parseNumber(r),r instanceof Error)return r;for(var t,i=[["a.u. of action","?",null,"action",!1,!1,1.05457168181818e-34],["a.u. of charge","e",null,"electric_charge",!1,!1,1.60217653141414e-19],["a.u. of energy","Eh",null,"energy",!1,!1,4.35974417757576e-18],["a.u. of length","a?",null,"length",!1,!1,5.29177210818182e-11],["a.u. of mass","m?",null,"mass",!1,!1,9.10938261616162e-31],["a.u. of time","?/Eh",null,"time",!1,!1,2.41888432650516e-17],["admiralty knot","admkn",null,"speed",!1,!0,.514773333],["ampere","A",null,"electric_current",!0,!1,1],["ampere per meter","A/m",null,"magnetic_field_intensity",!0,!1,1],["ångström","Å",["ang"],"length",!1,!0,1e-10],["are","ar",null,"area",!1,!0,100],["astronomical unit","ua",null,"length",!1,!1,1.49597870691667e-11],["bar","bar",null,"pressure",!1,!1,1e5],["barn","b",null,"area",!1,!1,1e-28],["becquerel","Bq",null,"radioactivity",!0,!1,1],["bit","bit",["b"],"information",!1,!0,1],["btu","BTU",["btu"],"energy",!1,!0,1055.05585262],["byte","byte",null,"information",!1,!0,8],["candela","cd",null,"luminous_intensity",!0,!1,1],["candela per square metre","cd/m?",null,"luminance",!0,!1,1],["coulomb","C",null,"electric_charge",!0,!1,1],["cubic ångström","ang3",["ang^3"],"volume",!1,!0,1e-30],["cubic foot","ft3",["ft^3"],"volume",!1,!0,.028316846592],["cubic inch","in3",["in^3"],"volume",!1,!0,16387064e-12],["cubic light-year","ly3",["ly^3"],"volume",!1,!0,8.46786664623715e-47],["cubic metre","m?",null,"volume",!0,!0,1],["cubic mile","mi3",["mi^3"],"volume",!1,!0,4168181825.44058],["cubic nautical mile","Nmi3",["Nmi^3"],"volume",!1,!0,6352182208],["cubic Pica","Pica3",["Picapt3","Pica^3","Picapt^3"],"volume",!1,!0,7.58660370370369e-8],["cubic yard","yd3",["yd^3"],"volume",!1,!0,.764554857984],["cup","cup",null,"volume",!1,!0,.0002365882365],["dalton","Da",["u"],"mass",!1,!1,1.66053886282828e-27],["day","d",["day"],"time",!1,!0,86400],["degree","°",null,"angle",!1,!1,.0174532925199433],["degrees Rankine","Rank",null,"temperature",!1,!0,.555555555555556],["dyne","dyn",["dy"],"force",!1,!0,1e-5],["electronvolt","eV",["ev"],"energy",!1,!0,1.60217656514141],["ell","ell",null,"length",!1,!0,1.143],["erg","erg",["e"],"energy",!1,!0,1e-7],["farad","F",null,"electric_capacitance",!0,!1,1],["fluid ounce","oz",null,"volume",!1,!0,295735295625e-16],["foot","ft",null,"length",!1,!0,.3048],["foot-pound","flb",null,"energy",!1,!0,1.3558179483314],["gal","Gal",null,"acceleration",!1,!1,.01],["gallon","gal",null,"volume",!1,!0,.003785411784],["gauss","G",["ga"],"magnetic_flux_density",!1,!0,1],["grain","grain",null,"mass",!1,!0,647989e-10],["gram","g",null,"mass",!1,!0,.001],["gray","Gy",null,"absorbed_dose",!0,!1,1],["gross registered ton","GRT",["regton"],"volume",!1,!0,2.8316846592],["hectare","ha",null,"area",!1,!0,1e4],["henry","H",null,"inductance",!0,!1,1],["hertz","Hz",null,"frequency",!0,!1,1],["horsepower","HP",["h"],"power",!1,!0,745.69987158227],["horsepower-hour","HPh",["hh","hph"],"energy",!1,!0,2684519.538],["hour","h",["hr"],"time",!1,!0,3600],["imperial gallon (U.K.)","uk_gal",null,"volume",!1,!0,.00454609],["imperial hundredweight","lcwt",["uk_cwt","hweight"],"mass",!1,!0,50.802345],["imperial quart (U.K)","uk_qt",null,"volume",!1,!0,.0011365225],["imperial ton","brton",["uk_ton","LTON"],"mass",!1,!0,1016.046909],["inch","in",null,"length",!1,!0,.0254],["international acre","uk_acre",null,"area",!1,!0,4046.8564224],["IT calorie","cal",null,"energy",!1,!0,4.1868],["joule","J",null,"energy",!0,!0,1],["katal","kat",null,"catalytic_activity",!0,!1,1],["kelvin","K",["kel"],"temperature",!0,!0,1],["kilogram","kg",null,"mass",!0,!0,1],["knot","kn",null,"speed",!1,!0,.514444444444444],["light-year","ly",null,"length",!1,!0,9460730472580800],["litre","L",["l","lt"],"volume",!1,!0,.001],["lumen","lm",null,"luminous_flux",!0,!1,1],["lux","lx",null,"illuminance",!0,!1,1],["maxwell","Mx",null,"magnetic_flux",!1,!1,1e-18],["measurement ton","MTON",null,"volume",!1,!0,1.13267386368],["meter per hour","m/h",["m/hr"],"speed",!1,!0,.00027777777777778],["meter per second","m/s",["m/sec"],"speed",!0,!0,1],["meter per second squared","m?s??",null,"acceleration",!0,!1,1],["parsec","pc",["parsec"],"length",!1,!0,0x6da012f958ee1c],["meter squared per second","m?/s",null,"kinematic_viscosity",!0,!1,1],["metre","m",null,"length",!0,!0,1],["miles per hour","mph",null,"speed",!1,!0,.44704],["millimetre of mercury","mmHg",null,"pressure",!1,!1,133.322],["minute","?",null,"angle",!1,!1,.000290888208665722],["minute","min",["mn"],"time",!1,!0,60],["modern teaspoon","tspm",null,"volume",!1,!0,5e-6],["mole","mol",null,"amount_of_substance",!0,!1,1],["morgen","Morgen",null,"area",!1,!0,2500],["n.u. of action","?",null,"action",!1,!1,1.05457168181818e-34],["n.u. of mass","m?",null,"mass",!1,!1,9.10938261616162e-31],["n.u. of speed","c?",null,"speed",!1,!1,299792458],["n.u. of time","?/(me?c??)",null,"time",!1,!1,1.28808866778687e-21],["nautical mile","M",["Nmi"],"length",!1,!0,1852],["newton","N",null,"force",!0,!0,1],["œrsted","Oe ",null,"magnetic_field_intensity",!1,!1,79.5774715459477],["ohm","Ω",null,"electric_resistance",!0,!1,1],["ounce mass","ozm",null,"mass",!1,!0,.028349523125],["pascal","Pa",null,"pressure",!0,!1,1],["pascal second","Pa?s",null,"dynamic_viscosity",!0,!1,1],["pferdestärke","PS",null,"power",!1,!0,735.49875],["phot","ph",null,"illuminance",!1,!1,1e-4],["pica (1/6 inch)","pica",null,"length",!1,!0,.00035277777777778],["pica (1/72 inch)","Pica",["Picapt"],"length",!1,!0,.00423333333333333],["poise","P",null,"dynamic_viscosity",!1,!1,.1],["pond","pond",null,"force",!1,!0,.00980665],["pound force","lbf",null,"force",!1,!0,4.4482216152605],["pound mass","lbm",null,"mass",!1,!0,.45359237],["quart","qt",null,"volume",!1,!0,.000946352946],["radian","rad",null,"angle",!0,!1,1],["second","?",null,"angle",!1,!1,484813681109536e-20],["second","s",["sec"],"time",!0,!0,1],["short hundredweight","cwt",["shweight"],"mass",!1,!0,45.359237],["siemens","S",null,"electrical_conductance",!0,!1,1],["sievert","Sv",null,"equivalent_dose",!0,!1,1],["slug","sg",null,"mass",!1,!0,14.59390294],["square ångström","ang2",["ang^2"],"area",!1,!0,1e-20],["square foot","ft2",["ft^2"],"area",!1,!0,.09290304],["square inch","in2",["in^2"],"area",!1,!0,64516e-8],["square light-year","ly2",["ly^2"],"area",!1,!0,8.95054210748189e31],["square meter","m?",null,"area",!0,!0,1],["square mile","mi2",["mi^2"],"area",!1,!0,2589988.110336],["square nautical mile","Nmi2",["Nmi^2"],"area",!1,!0,3429904],["square Pica","Pica2",["Picapt2","Pica^2","Picapt^2"],"area",!1,!0,1792111111111e-17],["square yard","yd2",["yd^2"],"area",!1,!0,.83612736],["statute mile","mi",null,"length",!1,!0,1609.344],["steradian","sr",null,"solid_angle",!0,!1,1],["stilb","sb",null,"luminance",!1,!1,1e-4],["stokes","St",null,"kinematic_viscosity",!1,!1,1e-4],["stone","stone",null,"mass",!1,!0,6.35029318],["tablespoon","tbs",null,"volume",!1,!0,147868e-10],["teaspoon","tsp",null,"volume",!1,!0,492892e-11],["tesla","T",null,"magnetic_flux_density",!0,!0,1],["thermodynamic calorie","c",null,"energy",!1,!0,4.184],["ton","ton",null,"mass",!1,!0,907.18474],["tonne","t",null,"mass",!1,!1,1e3],["U.K. pint","uk_pt",null,"volume",!1,!0,.00056826125],["U.S. bushel","bushel",null,"volume",!1,!0,.03523907],["U.S. oil barrel","barrel",null,"volume",!1,!0,.158987295],["U.S. pint","pt",["us_pt"],"volume",!1,!0,.000473176473],["U.S. survey mile","survey_mi",null,"length",!1,!0,1609.347219],["U.S. survey/statute acre","us_acre",null,"area",!1,!0,4046.87261],["volt","V",null,"voltage",!0,!1,1],["watt","W",null,"power",!0,!0,1],["watt-hour","Wh",["wh"],"energy",!1,!0,3600],["weber","Wb",null,"magnetic_flux",!0,!1,1],["yard","yd",null,"length",!1,!0,.9144],["year","yr",null,"time",!1,!0,31557600]],a={Yi:["yobi",80,1.2089258196146292e24,"Yi","yotta"],Zi:["zebi",70,0x400000000000000000,"Zi","zetta"],Ei:["exbi",60,0x1000000000000000,"Ei","exa"],Pi:["pebi",50,0x4000000000000,"Pi","peta"],Ti:["tebi",40,1099511627776,"Ti","tera"],Gi:["gibi",30,1073741824,"Gi","giga"],Mi:["mebi",20,1048576,"Mi","mega"],ki:["kibi",10,1024,"ki","kilo"]},s={Y:["yotta",1e24,"Y"],Z:["zetta",1e21,"Z"],E:["exa",1e18,"E"],P:["peta",1e15,"P"],T:["tera",1e12,"T"],G:["giga",1e9,"G"],M:["mega",1e6,"M"],k:["kilo",1e3,"k"],h:["hecto",100,"h"],e:["dekao",10,"e"],d:["deci",.1,"d"],c:["centi",.01,"c"],m:["milli",.001,"m"],u:["micro",1e-6,"u"],n:["nano",1e-9,"n"],p:["pico",1e-12,"p"],f:["femto",1e-15,"f"],a:["atto",1e-18,"a"],z:["zepto",1e-21,"z"],y:["yocto",1e-24,"y"]},f=null,l=null,c=e,m=n,p=1,h=1,g=0;g=0)&&(f=i[g]),(i[g][1]===m||t.indexOf(m)>=0)&&(l=i[g]);if(null===f){var v=a[e.substring(0,2)],d=s[e.substring(0,1)];"da"===e.substring(0,2)&&(d=["dekao",10,"da"]),v?(p=v[2],c=e.substring(2)):d&&(p=d[1],c=e.substring(d[2].length));for(var y=0;y=0)&&(f=i[y])}if(null===l){var b=a[n.substring(0,2)],N=s[n.substring(0,1)];"da"===n.substring(0,2)&&(N=["dekao",10,"da"]),b?(h=b[2],m=n.substring(2)):N&&(h=N[1],m=n.substring(N[2].length));for(var E=0;E=0)&&(l=i[E])}return null===f||null===l?u.na:f[3]!==l[3]?u.na:r*f[6]*p/(l[6]*h)},e.DEC2BIN=function(r,e){if(r=o.parseNumber(r),r instanceof Error)return r;if(!/^-?[0-9]{1,3}$/.test(r)||r<-512||r>511)return u.num;if(r<0)return"1"+a.REPT("0",9-(512+r).toString(2).length)+(512+r).toString(2);var n=parseInt(r,10).toString(2);return"undefined"==typeof e?n:isNaN(e)?u.value:e<0?u.num:(e=Math.floor(e),e>=n.length?a.REPT("0",e-n.length)+n:u.num)},e.DEC2HEX=function(r,e){if(r=o.parseNumber(r),r instanceof Error)return r;if(!/^-?[0-9]{1,12}$/.test(r)||r<-549755813888||r>549755813887)return u.num;if(r<0)return(1099511627776+r).toString(16);var n=parseInt(r,10).toString(16);return"undefined"==typeof e?n:isNaN(e)?u.value:e<0?u.num:(e=Math.floor(e),e>=n.length?a.REPT("0",e-n.length)+n:u.num)},e.DEC2OCT=function(r,e){if(r=o.parseNumber(r),r instanceof Error)return r;if(!/^-?[0-9]{1,9}$/.test(r)||r<-536870912||r>536870911)return u.num;if(r<0)return(1073741824+r).toString(8);var n=parseInt(r,10).toString(8);return"undefined"==typeof e?n:isNaN(e)?u.value:e<0?u.num:(e=Math.floor(e),e>=n.length?a.REPT("0",e-n.length)+n:u.num)},e.DELTA=function(r,e){return e=void 0===e?0:e,r=o.parseNumber(r),e=o.parseNumber(e),o.anyIsError(r,e)?u.value:r===e?1:0},e.ERF=function(r,e){return e=void 0===e?0:e,r=o.parseNumber(r),e=o.parseNumber(e),o.anyIsError(r,e)?u.value:i.erf(r)},e.ERF.PRECISE=function(){throw new Error("ERF.PRECISE is not implemented")},e.ERFC=function(r){return isNaN(r)?u.value:i.erfc(r)},e.ERFC.PRECISE=function(){throw new Error("ERFC.PRECISE is not implemented")},e.GESTEP=function(r,e){return e=e||0,r=o.parseNumber(r),o.anyIsError(e,r)?r:r>=e?1:0},e.HEX2BIN=function(r,e){if(!/^[0-9A-Fa-f]{1,10}$/.test(r))return u.num;var n=10===r.length&&"f"===r.substring(0,1).toLowerCase(),t=n?parseInt(r,16)-1099511627776:parseInt(r,16);if(t<-512||t>511)return u.num;if(n)return"1"+a.REPT("0",9-(512+t).toString(2).length)+(512+t).toString(2);var i=t.toString(2);return void 0===e?i:isNaN(e)?u.value:e<0?u.num:(e=Math.floor(e),e>=i.length?a.REPT("0",e-i.length)+i:u.num)},e.HEX2DEC=function(r){if(!/^[0-9A-Fa-f]{1,10}$/.test(r))return u.num;var e=parseInt(r,16);return e>=549755813888?e-1099511627776:e},e.HEX2OCT=function(r,e){if(!/^[0-9A-Fa-f]{1,10}$/.test(r))return u.num;var n=parseInt(r,16);if(n>536870911&&n<0xffe0000000)return u.num;if(n>=0xffe0000000)return(n-0xffc0000000).toString(8);var t=n.toString(8);return void 0===e?t:isNaN(e)?u.value:e<0?u.num:(e=Math.floor(e),e>=t.length?a.REPT("0",e-t.length)+t:u.num)},e.IMABS=function(r){var n=e.IMREAL(r),t=e.IMAGINARY(r);return o.anyIsError(n,t)?u.value:Math.sqrt(Math.pow(n,2)+Math.pow(t,2))},e.IMAGINARY=function(r){if(void 0===r||r===!0||r===!1)return u.value;if(0===r||"0"===r)return 0;if(["i","j"].indexOf(r)>=0)return 1;r=r.replace("+i","+1i").replace("-i","-1i").replace("+j","+1j").replace("-j","-1j");var e=r.indexOf("+"),n=r.indexOf("-");0===e&&(e=r.indexOf("+",1)),0===n&&(n=r.indexOf("-",1));var t=r.substring(r.length-1,r.length),i="i"===t||"j"===t;return e>=0||n>=0?i?e>=0?isNaN(r.substring(0,e))||isNaN(r.substring(e+1,r.length-1))?u.num:Number(r.substring(e+1,r.length-1)):isNaN(r.substring(0,n))||isNaN(r.substring(n+1,r.length-1))?u.num:-Number(r.substring(n+1,r.length-1)):u.num:i?isNaN(r.substring(0,r.length-1))?u.num:r.substring(0,r.length-1):isNaN(r)?u.num:0},e.IMARGUMENT=function(r){var n=e.IMREAL(r),t=e.IMAGINARY(r);return o.anyIsError(n,t)?u.value:0===n&&0===t?u.div0:0===n&&t>0?Math.PI/2:0===n&&t<0?-Math.PI/2:0===t&&n>0?0:0===t&&n<0?-Math.PI:n>0?Math.atan(t/n):n<0&&t>=0?Math.atan(t/n)+Math.PI:Math.atan(t/n)-Math.PI},e.IMCONJUGATE=function(r){var n=e.IMREAL(r),t=e.IMAGINARY(r);if(o.anyIsError(n,t))return u.value;var i=r.substring(r.length-1);return i="i"===i||"j"===i?i:"i",0!==t?e.COMPLEX(n,-t,i):r},e.IMCOS=function(r){var n=e.IMREAL(r),t=e.IMAGINARY(r);if(o.anyIsError(n,t))return u.value;var i=r.substring(r.length-1);return i="i"===i||"j"===i?i:"i",e.COMPLEX(Math.cos(n)*(Math.exp(t)+Math.exp(-t))/2,-Math.sin(n)*(Math.exp(t)-Math.exp(-t))/2,i)},e.IMCOSH=function(r){var n=e.IMREAL(r),t=e.IMAGINARY(r);if(o.anyIsError(n,t))return u.value;var i=r.substring(r.length-1);return i="i"===i||"j"===i?i:"i",e.COMPLEX(Math.cos(t)*(Math.exp(n)+Math.exp(-n))/2,Math.sin(t)*(Math.exp(n)-Math.exp(-n))/2,i)},e.IMCOT=function(r){var n=e.IMREAL(r),t=e.IMAGINARY(r);return o.anyIsError(n,t)?u.value:e.IMDIV(e.IMCOS(r),e.IMSIN(r))},e.IMDIV=function(r,n){var t=e.IMREAL(r),i=e.IMAGINARY(r),a=e.IMREAL(n),s=e.IMAGINARY(n);if(o.anyIsError(t,i,a,s))return u.value;var f=r.substring(r.length-1),l=n.substring(n.length-1),c="i";if("j"===f?c="j":"j"===l&&(c="j"),0===a&&0===s)return u.num;var m=a*a+s*s;return e.COMPLEX((t*a+i*s)/m,(i*a-t*s)/m,c)},e.IMEXP=function(r){var n=e.IMREAL(r),t=e.IMAGINARY(r);if(o.anyIsError(n,t))return u.value;var i=r.substring(r.length-1);i="i"===i||"j"===i?i:"i";var a=Math.exp(n);return e.COMPLEX(a*Math.cos(t),a*Math.sin(t),i)},e.IMLN=function(r){var n=e.IMREAL(r),t=e.IMAGINARY(r);if(o.anyIsError(n,t))return u.value;var i=r.substring(r.length-1);return i="i"===i||"j"===i?i:"i",e.COMPLEX(Math.log(Math.sqrt(n*n+t*t)),Math.atan(t/n),i)},e.IMLOG10=function(r){var n=e.IMREAL(r),t=e.IMAGINARY(r);if(o.anyIsError(n,t))return u.value;var i=r.substring(r.length-1);return i="i"===i||"j"===i?i:"i",e.COMPLEX(Math.log(Math.sqrt(n*n+t*t))/Math.log(10),Math.atan(t/n)/Math.log(10),i)},e.IMLOG2=function(r){var n=e.IMREAL(r),t=e.IMAGINARY(r);if(o.anyIsError(n,t))return u.value;var i=r.substring(r.length-1);return i="i"===i||"j"===i?i:"i",e.COMPLEX(Math.log(Math.sqrt(n*n+t*t))/Math.log(2),Math.atan(t/n)/Math.log(2),i)},e.IMPOWER=function(r,n){n=o.parseNumber(n);var t=e.IMREAL(r),i=e.IMAGINARY(r);if(o.anyIsError(n,t,i))return u.value;var a=r.substring(r.length-1);a="i"===a||"j"===a?a:"i";var s=Math.pow(e.IMABS(r),n),f=e.IMARGUMENT(r);return e.COMPLEX(s*Math.cos(n*f),s*Math.sin(n*f),a)},e.IMPRODUCT=function(){for(var r=arguments[0],n=1;n=0)return 0;var e=r.indexOf("+"),n=r.indexOf("-");0===e&&(e=r.indexOf("+",1)),0===n&&(n=r.indexOf("-",1));var t=r.substring(r.length-1,r.length),i="i"===t||"j"===t;return e>=0||n>=0?i?e>=0?isNaN(r.substring(0,e))||isNaN(r.substring(e+1,r.length-1))?u.num:Number(r.substring(0,e)):isNaN(r.substring(0,n))||isNaN(r.substring(n+1,r.length-1))?u.num:Number(r.substring(0,n)):u.num:i?isNaN(r.substring(0,r.length-1))?u.num:0:isNaN(r)?u.num:r},e.IMSEC=function(r){if(r===!0||r===!1)return u.value;var n=e.IMREAL(r),t=e.IMAGINARY(r);return o.anyIsError(n,t)?u.value:e.IMDIV("1",e.IMCOS(r))},e.IMSECH=function(r){var n=e.IMREAL(r),t=e.IMAGINARY(r);return o.anyIsError(n,t)?u.value:e.IMDIV("1",e.IMCOSH(r))},e.IMSIN=function(r){var n=e.IMREAL(r),t=e.IMAGINARY(r);if(o.anyIsError(n,t))return u.value;var i=r.substring(r.length-1);return i="i"===i||"j"===i?i:"i",e.COMPLEX(Math.sin(n)*(Math.exp(t)+Math.exp(-t))/2,Math.cos(n)*(Math.exp(t)-Math.exp(-t))/2,i)},e.IMSINH=function(r){var n=e.IMREAL(r),t=e.IMAGINARY(r);if(o.anyIsError(n,t))return u.value;var i=r.substring(r.length-1);return i="i"===i||"j"===i?i:"i",e.COMPLEX(Math.cos(t)*(Math.exp(n)-Math.exp(-n))/2,Math.sin(t)*(Math.exp(n)+Math.exp(-n))/2,i)},e.IMSQRT=function(r){var n=e.IMREAL(r),t=e.IMAGINARY(r);if(o.anyIsError(n,t))return u.value;var i=r.substring(r.length-1);i="i"===i||"j"===i?i:"i";var a=Math.sqrt(e.IMABS(r)),s=e.IMARGUMENT(r);return e.COMPLEX(a*Math.cos(s/2),a*Math.sin(s/2),i)},e.IMCSC=function(r){if(r===!0||r===!1)return u.value;var n=e.IMREAL(r),t=e.IMAGINARY(r);return o.anyIsError(n,t)?u.num:e.IMDIV("1",e.IMSIN(r))},e.IMCSCH=function(r){if(r===!0||r===!1)return u.value;var n=e.IMREAL(r),t=e.IMAGINARY(r);return o.anyIsError(n,t)?u.num:e.IMDIV("1",e.IMSINH(r))},e.IMSUB=function(r,e){var n=this.IMREAL(r),t=this.IMAGINARY(r),i=this.IMREAL(e),a=this.IMAGINARY(e);if(o.anyIsError(n,t,i,a))return u.value;var s=r.substring(r.length-1),f=e.substring(e.length-1),l="i";return"j"===s?l="j":"j"===f&&(l="j"),this.COMPLEX(n-i,t-a,l)},e.IMSUM=function(){for(var r=o.flatten(arguments),e=r[0],n=1;n511)return u.num;if(n)return"1"+a.REPT("0",9-(512+t).toString(2).length)+(512+t).toString(2);var i=t.toString(2);return"undefined"==typeof e?i:isNaN(e)?u.value:e<0?u.num:(e=Math.floor(e),e>=i.length?a.REPT("0",e-i.length)+i:u.num)},e.OCT2DEC=function(r){if(!/^[0-7]{1,10}$/.test(r))return u.num;var e=parseInt(r,8);return e>=536870912?e-1073741824:e; +},e.OCT2HEX=function(r,e){if(!/^[0-7]{1,10}$/.test(r))return u.num;var n=parseInt(r,8);if(n>=536870912)return"ff"+(n+3221225472).toString(16);var t=n.toString(16);return void 0===e?t:isNaN(e)?u.value:e<0?u.num:(e=Math.floor(e),e>=t.length?a.REPT("0",e-t.length)+t:u.num)}},function(r,e,n){function t(r,e){return r.reduce(function(r,n){return e*r+n},0)}function u(r,e,n,t,u){u||(u=-1);var i,a=2/r;if(0===e)return n;if(1===e)return t;for(var o=1;o!=e;++o)i=t*o*a+u*n,n=t,t=i;return t}function i(r,e,n,t,i){return function(a,o){if(0===o)return r(a);if(1===o)return e(a);if(o<0)throw n+": Order ("+o+") must be nonnegative";if(1==t&&0===a)throw n+": Undefined when x == 0";if(2==t&&a<=0)throw n+": Undefined when x <= 0";var s=r(a),f=e(a);return u(a,o,s,f,i)}}var a=Math,o=function(){function r(r){var e,u,l,c=r*r,m=a.abs(r)-.785398164;return a.abs(r)<8?(u=t(n,c),l=t(i,c),e=u/l):(c=64/c,u=t(o,c),l=t(s,c),e=a.sqrt(f/a.abs(r))*(a.cos(m)*u-a.sin(m)*l*8/a.abs(r))),e}function e(r){var e,n,u,i=r*r,o=a.abs(r)-2.356194491;return Math.abs(r)<8?(n=r*t(l,i),u=t(c,i),e=n/u):(i=64/i,n=t(m,i),u=t(p,i),e=a.sqrt(f/a.abs(r))*(a.cos(o)*n-a.sin(o)*u*8/a.abs(r)),r<0&&(e=-e)),e}var n=[57568490574,-13362590354,651619640.7,-11214424.18,77392.33017,-184.9052456].reverse(),i=[57568490411,1029532985,9494680.718,59272.64853,267.8532712,1].reverse(),o=[1,-.001098628627,2734510407e-14,-2073370639e-15,2.093887211e-7].reverse(),s=[-.01562499995,.0001430488765,-6911147651e-15,7.621095161e-7,-9.34935152e-8].reverse(),f=.636619772,l=[72362614232,-7895059235,242396853.1,-2972611.439,15704.4826,-30.16036606].reverse(),c=[144725228442,2300535178,18583304.74,99447.43394,376.9991397,1].reverse(),m=[1,.00183105,-3516396496e-14,2457520174e-15,-2.40337019e-7].reverse(),p=[.04687499995,-.0002002690873,8449199096e-15,-8.8228987e-7,1.05787412e-7].reverse();return function(n,t){if(t=Math.round(t),0===t)return r(a.abs(n));if(1===t)return e(a.abs(n));if(t<0)throw"BESSELJ: Order ("+t+") must be nonnegative";if(0===a.abs(n))return 0;var i,o,s,f,l,c,m,p,h=2/a.abs(n);if(a.abs(n)>t)i=u(n,t,r(a.abs(n)),e(a.abs(n)),-1);else{for(s=2*a.floor((t+a.floor(a.sqrt(40*t)))/2),f=0,c=i=l=0,m=1,o=s;o>0;o--)p=o*h*m-c,c=m,m=p,a.abs(m)>1e10&&(m*=1e-10,c*=1e-10,i*=1e-10,l*=1e-10),f&&(l+=m),f=!f,o==t&&(i=c);l=2*l-m,i/=l}return n<0&&t%2?-i:i}}(),s=function(){function r(r){var e,i,c,m=r*r,p=r-.785398164;return r<8?(i=t(n,m),c=t(u,m),e=i/c+l*o(r,0)*a.log(r)):(m=64/m,i=t(s,m),c=t(f,m),e=a.sqrt(l/r)*(a.sin(p)*i+a.cos(p)*c*8/r)),e}function e(r){var e,n,u,i=r*r,s=r-2.356194491;return r<8?(n=r*t(c,i),u=t(m,i),e=n/u+l*(o(r,1)*a.log(r)-1/r)):(i=64/i,n=t(p,i),u=t(h,i),e=a.sqrt(l/r)*(a.sin(s)*n+a.cos(s)*u*8/r)),e}var n=[-2957821389,7062834065,-512359803.6,10879881.29,-86327.92757,228.4622733].reverse(),u=[40076544269,745249964.8,7189466.438,47447.2647,226.1030244,1].reverse(),s=[1,-.001098628627,2734510407e-14,-2073370639e-15,2.093887211e-7].reverse(),f=[-.01562499995,.0001430488765,-6911147651e-15,7.621095161e-7,-9.34945152e-8].reverse(),l=.636619772,c=[-4900604943e3,127527439e4,-51534381390,734926455.1,-4237922.726,8511.937935].reverse(),m=[249958057e5,424441966400,3733650367,22459040.02,102042.605,354.9632885,1].reverse(),p=[1,.00183105,-3516396496e-14,2457520174e-15,-2.40337019e-7].reverse(),h=[.04687499995,-.0002002690873,8449199096e-15,-8.8228987e-7,1.05787412e-7].reverse();return i(r,e,"BESSELY",1,-1)}(),f=function(){function r(r){return r<=3.75?t(n,r*r/14.0625):a.exp(a.abs(r))/a.sqrt(a.abs(r))*t(u,3.75/a.abs(r))}function e(r){return r<3.75?r*t(i,r*r/14.0625):(r<0?-1:1)*a.exp(a.abs(r))/a.sqrt(a.abs(r))*t(o,3.75/a.abs(r))}var n=[1,3.5156229,3.0899424,1.2067492,.2659732,.0360768,.0045813].reverse(),u=[.39894228,.01328592,.00225319,-.00157565,.00916281,-.02057706,.02635537,-.01647633,.00392377].reverse(),i=[.5,.87890594,.51498869,.15084934,.02658733,.00301532,32411e-8].reverse(),o=[.39894228,-.03988024,-.00362018,.00163801,-.01031555,.02282967,-.02895312,.01787654,-.00420059].reverse();return function s(n,t){if(t=Math.round(t),0===t)return r(n);if(1==t)return e(n);if(t<0)throw"BESSELI Order ("+t+") must be nonnegative";if(0===a.abs(n))return 0;var u,i,o,f,l,c,m=2/a.abs(n);for(o=2*a.round((t+a.round(a.sqrt(40*t)))/2),f=u=0,l=1,i=o;i>0;i--)c=i*m*l+f,f=l,l=c,a.abs(l)>1e10&&(l*=1e-10,f*=1e-10,u*=1e-10),i==t&&(u=f);return u*=s(n,0)/l,n<0&&t%2?-u:u}}(),l=function(){function r(r){return r<=2?-a.log(r/2)*f(r,0)+t(n,r*r/4):a.exp(-r)/a.sqrt(r)*t(u,2/r)}function e(r){return r<=2?a.log(r/2)*f(r,1)+1/r*t(o,r*r/4):a.exp(-r)/a.sqrt(r)*t(s,2/r)}var n=[-.57721566,.4227842,.23069756,.0348859,.00262698,1075e-7,74e-7].reverse(),u=[1.25331414,-.07832358,.02189568,-.01062446,.00587872,-.0025154,53208e-8].reverse(),o=[1,.15443144,-.67278579,-.18156897,-.01919402,-.00110404,-4686e-8].reverse(),s=[1.25331414,.23498619,-.0365562,.01504268,-.00780353,.00325614,-68245e-8].reverse();return i(r,e,"BESSELK",2,1)}();e.besselj=o,e.bessely=s,e.besseli=f,e.besselk=l},function(r,e,n){function t(r){return 1===new Date(r,1,29).getMonth()}function u(r,e){return Math.ceil((e-r)/1e3/60/60/24)}function i(r){var e=r>-22038912e5?2:1;return(r-s)/864e5+e}var a=n(5),o=n(4),s=new Date(1900,0,1),f=[void 0,0,1,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,1,2,3,4,5,6,0],l=[[],[1,2,3,4,5,6,7],[7,1,2,3,4,5,6],[6,0,1,2,3,4,5],[],[],[],[],[],[],[],[7,1,2,3,4,5,6],[6,7,1,2,3,4,5],[5,6,7,1,2,3,4],[4,5,6,7,1,2,3],[3,4,5,6,7,1,2],[2,3,4,5,6,7,1],[1,2,3,4,5,6,7]],c=[[],[6,0],[0,1],[1,2],[2,3],[3,4],[4,5],[5,6],void 0,void 0,void 0,[0,0],[1,1],[2,2],[3,3],[4,4],[5,5],[6,6]];e.DATE=function(r,e,n){if(r=o.parseNumber(r),e=o.parseNumber(e),n=o.parseNumber(n),o.anyIsError(r,e,n))return a.value;if(r<0||e<0||n<0)return a.num;var t=new Date(r,e-1,n);return t},e.DATEVALUE=function(r){if("string"!=typeof r)return a.value;var e=Date.parse(r);return isNaN(e)?a.value:e<=-22038912e5?(e-s)/864e5+1:(e-s)/864e5+2},e.DAY=function(r){var e=o.parseDate(r);return e instanceof Error?e:e.getDate()},e.DAYS=function(r,e){return r=o.parseDate(r),e=o.parseDate(e),r instanceof Error?r:e instanceof Error?e:i(r)-i(e)},e.DAYS360=function(r,e,n){if(n=o.parseBool(n),r=o.parseDate(r),e=o.parseDate(e),r instanceof Error)return r;if(e instanceof Error)return e;if(n instanceof Error)return n;var t,u,i=r.getMonth(),a=e.getMonth();if(n)t=31===r.getDate()?30:r.getDate(),u=31===e.getDate()?30:e.getDate();else{var s=new Date(r.getFullYear(),i+1,0).getDate(),f=new Date(e.getFullYear(),a+1,0).getDate();t=r.getDate()===s?30:r.getDate(),e.getDate()===f?t<30?(a++,u=1):u=30:u=e.getDate()}return 360*(e.getFullYear()-r.getFullYear())+30*(a-i)+(u-t)},e.EDATE=function(r,e){return r=o.parseDate(r),r instanceof Error?r:isNaN(e)?a.value:(e=parseInt(e,10),r.setMonth(r.getMonth()+e),i(r))},e.EOMONTH=function(r,e){return r=o.parseDate(r),r instanceof Error?r:isNaN(e)?a.value:(e=parseInt(e,10),i(new Date(r.getFullYear(),r.getMonth()+e+1,0)))},e.HOUR=function(r){return r=o.parseDate(r),r instanceof Error?r:r.getHours()},e.INTERVAL=function(r){if("number"!=typeof r&&"string"!=typeof r)return a.value;r=parseInt(r,10);var e=Math.floor(r/94608e4);r%=94608e4;var n=Math.floor(r/2592e3);r%=2592e3;var t=Math.floor(r/86400);r%=86400;var u=Math.floor(r/3600);r%=3600;var i=Math.floor(r/60);r%=60;var o=r;return e=e>0?e+"Y":"",n=n>0?n+"M":"",t=t>0?t+"D":"",u=u>0?u+"H":"",i=i>0?i+"M":"",o=o>0?o+"S":"","P"+e+n+t+"T"+u+i+o},e.ISOWEEKNUM=function(r){if(r=o.parseDate(r),r instanceof Error)return r;r.setHours(0,0,0),r.setDate(r.getDate()+4-(r.getDay()||7));var e=new Date(r.getFullYear(),0,1);return Math.ceil(((r-e)/864e5+1)/7)},e.MINUTE=function(r){return r=o.parseDate(r),r instanceof Error?r:r.getMinutes()},e.MONTH=function(r){return r=o.parseDate(r),r instanceof Error?r:r.getMonth()+1},e.NETWORKDAYS=function(r,e,n){return this.NETWORKDAYS.INTL(r,e,1,n)},e.NETWORKDAYS.INTL=function(r,e,n,t){if(r=o.parseDate(r),r instanceof Error)return r;if(e=o.parseDate(e),e instanceof Error)return e;if(n=void 0===n?c[1]:c[n],!(n instanceof Array))return a.value;void 0===t?t=[]:t instanceof Array||(t=[t]);for(var u=0;u0?l.getUTCDay():l.getDay(),p=!1;m!==n[0]&&m!==n[1]||(p=!0);for(var h=0;h=u)return!0;var i=e.getFullYear(),a=new Date(i,2,1);return t(i)&&e>=a&&rl||a===l&&i>=f))return(s===c&&t(s)||m(r,e)||1===l&&29===f)&&(p=366),u(r,e)/p;var h=c-s+1,g=(new Date(c+1,0,1)-new Date(s,0,1))/1e3/60/60/24,v=g/h;return u(r,e)/v;case 2:return u(r,e)/360;case 3:return u(r,e)/365;case 4:return(f+30*l+360*c-(i+30*a+360*s))/360}}},function(module,exports,__webpack_require__){function compact(r){if(!r)return r;for(var e=[],n=0;nmaxCriteriaLength&&(maxCriteriaLength=criterias[i].length);for(var k=1;k1?error.num:u[t[0]]},exports.DMAX=function(r,e,n){if(isNaN(e)&&"string"!=typeof e)return error.value;var t=findResultIndex(r,n),u=[];if("string"==typeof e){var i=exports.FINDFIELD(r,e);u=utils.rest(r[i])}else u=utils.rest(r[e]);for(var a=u[t[0]],o=1;ou[t[o]]&&(a=u[t[o]]);return a},exports.DPRODUCT=function(r,e,n){if(isNaN(e)&&"string"!=typeof e)return error.value;var t=findResultIndex(r,n),u=[];if("string"==typeof e){var i=exports.FINDFIELD(r,e);u=utils.rest(r[i])}else u=utils.rest(r[e]);for(var a=[],o=0;o254?t.value:arguments.length0){var e=arguments[0],n=arguments.length-1,t=Math.floor(n/2),u=!1,i=n%2===0?null:arguments[arguments.length-1];if(t)for(var a=0;aa)return i.num;if(0!==s&&1!==s)return i.num;var f=e.PMT(r,n,t,0,s),l=0;1===u&&0===s&&(l=-t,u++);for(var c=u;c<=a;c++)l+=1===s?e.FV(r,c-2,f,t,1)-f:e.FV(r,c-1,f,t,0);return l*=r},e.CUMPRINC=function(r,n,t,u,a,s){if(r=o.parseNumber(r),n=o.parseNumber(n),t=o.parseNumber(t),o.anyIsError(r,n,t))return i.value;if(r<=0||n<=0||t<=0)return i.num;if(u<1||a<1||u>a)return i.num;if(0!==s&&1!==s)return i.num;var f=e.PMT(r,n,t,0,s),l=0;1===u&&(l=0===s?f+t*r:f,u++);for(var c=u;c<=a;c++)l+=s>0?f-(e.FV(r,c-2,f,t,1)-f)*r:f-e.FV(r,c-1,f,t,0)*r;return l},e.DB=function(r,e,n,t,u){if(u=void 0===u?12:u,r=o.parseNumber(r),e=o.parseNumber(e),n=o.parseNumber(n),t=o.parseNumber(t),u=o.parseNumber(u),o.anyIsError(r,e,n,t,u))return i.value;if(r<0||e<0||n<0||t<0)return i.num;if([1,2,3,4,5,6,7,8,9,10,11,12].indexOf(u)===-1)return i.num;if(t>n)return i.num;if(e>=r)return 0;for(var a=(1-Math.pow(e/r,1/n)).toFixed(3),s=r*a*u/12,f=s,l=0,c=t===n?n-1:t,m=2;m<=c;m++)l=(r-f)*a,f+=l;return 1===t?s:t===n?(r-f)*a:l},e.DDB=function(r,e,n,t,u){if(u=void 0===u?2:u,r=o.parseNumber(r),e=o.parseNumber(e),n=o.parseNumber(n),t=o.parseNumber(t),u=o.parseNumber(u),o.anyIsError(r,e,n,t,u))return i.value;if(r<0||e<0||n<0||t<0||u<=0)return i.num;if(t>n)return i.num;if(e>=r)return 0;for(var a=0,s=0,f=1;f<=t;f++)s=Math.min((r-a)*(u/n),r-e-a),a+=s;return s},e.DISC=function(){throw new Error("DISC is not implemented")},e.DOLLARDE=function(r,e){if(r=o.parseNumber(r),e=o.parseNumber(e),o.anyIsError(r,e))return i.value;if(e<0)return i.num;if(e>=0&&e<1)return i.div0;e=parseInt(e,10);var n=parseInt(r,10);n+=r%1*Math.pow(10,Math.ceil(Math.log(e)/Math.LN10))/e;var t=Math.pow(10,Math.ceil(Math.log(e)/Math.LN2)+1);return n=Math.round(n*t)/t},e.DOLLARFR=function(r,e){if(r=o.parseNumber(r),e=o.parseNumber(e),o.anyIsError(r,e))return i.value;if(e<0)return i.num;if(e>=0&&e<1)return i.div0;e=parseInt(e,10);var n=parseInt(r,10);return n+=r%1*Math.pow(10,-Math.ceil(Math.log(e)/Math.LN10))*e},e.DURATION=function(){throw new Error("DURATION is not implemented")},e.EFFECT=function(r,e){return r=o.parseNumber(r),e=o.parseNumber(e),o.anyIsError(r,e)?i.value:r<=0||e<1?i.num:(e=parseInt(e,10),Math.pow(1+r/e,e)-1)},e.FV=function(r,e,n,t,u){if(t=t||0,u=u||0,r=o.parseNumber(r),e=o.parseNumber(e),n=o.parseNumber(n),t=o.parseNumber(t),u=o.parseNumber(u),o.anyIsError(r,e,n,t,u))return i.value;var a;if(0===r)a=t+n*e;else{var s=Math.pow(1+r,e);a=1===u?t*s+n*(1+r)*(s-1)/r:t*s+n*(s-1)/r}return-a},e.FVSCHEDULE=function(r,e){if(r=o.parseNumber(r),e=o.parseNumberArray(o.flatten(e)),o.anyIsError(r,e))return i.value;for(var n=e.length,t=r,u=0;u0&&(a=!0),r[f]<0&&(s=!0);if(!a||!s)return i.num;e=void 0===e?.1:e;var l,c,m,p=e,h=1e-10,g=!0;do m=n(r,u,p),l=p-m/t(r,u,p),c=Math.abs(l-p),p=l,g=c>h&&Math.abs(m)>h;while(g);return p},e.ISPMT=function(r,e,n,t){return r=o.parseNumber(r),e=o.parseNumber(e),n=o.parseNumber(n),t=o.parseNumber(t),o.anyIsError(r,e,n,t)?i.value:t*r*(e/n-1)},e.MDURATION=function(){throw new Error("MDURATION is not implemented")},e.MIRR=function(r,n,t){if(r=o.parseNumberArray(o.flatten(r)),n=o.parseNumber(n),t=o.parseNumber(t),o.anyIsError(r,n,t))return i.value;for(var u=r.length,a=[],s=[],f=0;fm&&vn?i.num:(t=parseInt(t,10),(r-e)*(n-t+1)*2/(n*(n+1)))},e.TBILLEQ=function(r,e,n){return r=o.parseDate(r),e=o.parseDate(e),n=o.parseNumber(n),o.anyIsError(r,e,n)?i.value:n<=0?i.num:r>e?i.num:e-r>31536e6?i.num:365*n/(360-n*a.DAYS360(r,e,!1))},e.TBILLPRICE=function(r,e,n){return r=o.parseDate(r),e=o.parseDate(e),n=o.parseNumber(n),o.anyIsError(r,e,n)?i.value:n<=0?i.num:r>e?i.num:e-r>31536e6?i.num:100*(1-n*a.DAYS360(r,e,!1)/360)},e.TBILLYIELD=function(r,e,n){return r=o.parseDate(r),e=o.parseDate(e),n=o.parseNumber(n),o.anyIsError(r,e,n)?i.value:n<=0?i.num:r>e?i.num:e-r>31536e6?i.num:360*(100-n)/(n*a.DAYS360(r,e,!1))},e.VDB=function(){throw new Error("VDB is not implemented")},e.XIRR=function(r,e,n){if(r=o.parseNumberArray(o.flatten(r)),e=o.parseDateArray(o.flatten(e)),n=o.parseNumber(n),o.anyIsError(r,e,n))return i.value;for(var t=function(r,e,n){for(var t=n+1,u=r[0],i=1;i0&&(s=!0),r[l]<0&&(f=!0);if(!s||!f)return i.num;n=n||.1;var c,m,p,h=n,g=1e-10,v=!0;do p=t(r,e,h),c=h-p/u(r,e,h),m=Math.abs(c-h),h=c,v=m>g&&Math.abs(p)>g;while(v);return h},e.XNPV=function(r,e,n){if(r=o.parseNumber(r),e=o.parseNumberArray(o.flatten(e)),n=o.parseDateArray(o.flatten(n)),o.anyIsError(r,e,n))return i.value;for(var t=0,u=0;ui&&(u=a+1,i=e[a]):(u=a+1,i=e[a]))}else if(0===n){if("string"==typeof r){if(r=r.replace(/\?/g,"."),e[a].toLowerCase().match(r.toLowerCase()))return a+1}else if(e[a]===r)return a+1}else if(n===-1){if(e[a]===r)return a+1;e[a]>r&&(i?e[a]