Potato Floss Demo

Add up from 1 to 10,000,000:
Click button to start
WARNING: Your browser may be blocked when calculating directly

    function* calculate() {
      let sum = new Decimal(0);
      const max = new Decimal('10000000');
      for (let i = new Decimal(0); i.lt(max); i = i.plus(1)) {
        sum = sum.plus(i);
        if (i.mod(100).equals(0)) {
          yield `${i.mul(100).div(max).toFixed(1)}`;
        }
      }
      return sum;
    }

    const worker = new window.PotatoFloss(calculate, updateProgress);
    worker.start().then(sum => {
      result.innerHTML = sum.toString();
    });