How to use the decimal.js function in decimal

To help you get started, we’ve selected a few decimal examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github josdejong / mathjs / test / benchmark / factorial.js View on Github external
function bigFactorial (n) {
  if (n.isZero()) {
    return new BigNumber(1) // 0! is per definition 1
  }

  let res = new BigNumber(n)
  let value = n.toNumber() - 1 // number
  while (value > 1) {
    res = res.times(value)
    value--
  }

  return new BigNumber(res)
}
github CartoDB / Windshaft / lib / windshaft / utils / webmercator_helper.js View on Github external
function WebMercatorHelper (tileSize, maxGeosize) {
    this.tileSize = tileSize || 256;
    // 6378137: Earth equatorial radius defined by WGS-84 (webmercator)
    this.tileMaxGeosize = new Decimal(maxGeosize || 6378137.0 * Math.PI * 2);
}
github Beskhue / ClickerHeroesCalculator / calculator / js / calc.js View on Github external
function calculateHSCostToOptimalLevel() {
    var multiplier = Decimal.pow(0.95, data.outsiders["chor'gorloth"].level);
    
    var maxNumSteps = 2500; // Precision of approximation
    
    var totalCost = new Decimal(0);
    for (var k in data.ancients) {
        var oldLevel = data.ancients[k].level;
        if (data.ancients[k].extraInfo.optimalLevel) {
            var optimalLevel = data.ancients[k].extraInfo.optimalLevel;
            
            var diff = optimalLevel.minus(oldLevel);
            if (diff.lessThan(0)) {
                data.ancients[k].extraInfo.costToLevelToOptimal = new Decimal(0);
                continue;
            }
            
            var thisAncientCost = new Decimal(0);
            
            if(data.ancients[k].partialCostfn) {
                // We have defined the partial sum for this level cost formula,
                // use it instead of iterating
                thisAncientCost = data.ancients[k].partialCostfn(optimalLevel).minus(data.ancients[k].partialCostfn(oldLevel));
            } else {
                var numSteps = Decimal.min(maxNumSteps, diff);
                var stepSize = diff.dividedBy(numSteps);
                
                var temp = new Decimal(0);
                for(var step = 1; step <= numSteps; step++) {
                    var prevAddLevels = step.minus(1).times(stepSize).ceil();
github tinybike / fzero / index.js View on Github external
module.exports = function (f, bounds, options) {
    options = options || {};
    var mu = toDecimal(options.mu) || new Decimal("0.5");
    var eps = toDecimal(options.eps) || new Decimal("0.001");
    var tolx = toDecimal(options.tolx) || new Decimal(0);
    var maxiter = options.maxiter || 100;
    var maxfev = options.maxfev || maxiter;
    var verbose = options.verbose;

    // The default exit flag if exceeded number of iterations.
    var code = 0;
    var niter = 0;
    var nfev = 0;

    var x = new Decimal(NaN);
    var fval = new Decimal(NaN);
    var a = new Decimal(NaN);
    var fa = new Decimal(NaN);
    var b = new Decimal(NaN);
    var fb = new Decimal(NaN);
github josdejong / mathjs / test / benchmark / factorial.js View on Github external
.add(pad('new bigFactorial for big numbers'), function () {
    const res = betterFactorial(new BigNumber(600))
    results.push(res)
  })
  .on('cycle', function (event) {
github josdejong / mathjs / test / benchmark / factorial.js View on Github external
.add(pad('new bigFactorial'), function () {
    const res = betterFactorial(new BigNumber(8))
    results.push(res)
  })
  .add(pad('bigFactorial for big numbers'), function () {
github josdejong / mathjs / test / benchmark / factorial.js View on Github external
.add(pad('bigFactorial for big numbers'), function () {
    const res = bigFactorial(new BigNumber(600))
    results.push(res)
  })
  .add(pad('new bigFactorial for big numbers'), function () {
github josdejong / mathjs / test / benchmark / factorial.js View on Github external
.add(pad('bigFactorial for small numbers'), function () {
    const res = bigFactorial(new BigNumber(8))
    results.push(res)
  })
  .add(pad('new bigFactorial'), function () {
github tinybike / fzero / test / fzero.js View on Github external
f: function (n) {
            var q = [new Decimal("659.90262467263840222037"),
                     new Decimal("666.57262467263840222039")];
            var i = 0;
            var a = new Decimal("0.00790000000000000001");
            var xi = new Decimal("0.5");
            return lslmsr(n, q, i, a, xi);
        },
        label: "lslmsr(n, ['659.90262467263840222037', '666.57262467263840222039'], 0, '0.00790000000000000001', '0.5')",
github tinybike / fzero / index.js View on Github external
function toDecimal(x) {
    if (x && x.constructor !== Decimal) {
        if (x.toFixed && x.toFixed.constructor === Function) x = x.toFixed();
        x = new Decimal(x);
    }
    return x;
}

decimal

Simple decimal arithmetic for the browser and node.js!

MIT
Latest version published 13 years ago

Package Health Score

48 / 100
Full package analysis

Popular decimal functions