Sha256: 5671107f47e2a423bd150c0101c7464e7656ddf8002e999621dac6c01e2e2f36

Contents?: true

Size: 990 Bytes

Versions: 5

Compression:

Stored size: 990 Bytes

Contents

// Adds floating point numbers with twice the normal precision.
// Reference: J. R. Shewchuk, Adaptive Precision Floating-Point Arithmetic and
// Fast Robust Geometric Predicates, Discrete & Computational Geometry 18(3)
// 305–363 (1997).
// Code adapted from GeographicLib by Charles F. F. Karney,
// http://geographiclib.sourceforge.net/
// See lib/geographiclib/LICENSE for details.

function d3_adder() {}

d3_adder.prototype = {
  s: 0, // rounded value
  t: 0, // exact error
  add: function(y) {
    d3_adderSum(y, this.t, d3_adderTemp);
    d3_adderSum(d3_adderTemp.s, this.s, this);
    if (this.s) this.t += d3_adderTemp.t;
    else this.s = d3_adderTemp.t;
  },
  reset: function() {
    this.s = this.t = 0;
  },
  valueOf: function() {
    return this.s;
  }
};

var d3_adderTemp = new d3_adder;

function d3_adderSum(a, b, o) {
  var x = o.s = a + b, // a + b
      bv = x - a, av = x - bv; // b_virtual & a_virtual
  o.t = (a - av) + (b - bv); // a_roundoff + b_roundoff
}

Version data entries

5 entries across 5 versions & 3 rubygems

Version Path
mdarray-sol-0.1.0-java node_modules/dc/node_modules/d3/src/math/adder.js
stripchart-0.0.3 lib/stripchart/public/components/d3/src/math/adder.js
stripmem-0.0.3 lib/stripmem/public/components/d3/src/math/adder.js
stripmem-0.0.2 lib/stripmem/public/components/d3/src/math/adder.js
stripmem-0.0.1 lib/stripmem/public/components/d3/src/math/adder.js