1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | export default function() {
|
9 | return new Adder;
|
10 | }
|
11 |
|
12 | function Adder() {
|
13 | this.reset();
|
14 | }
|
15 |
|
16 | Adder.prototype = {
|
17 | constructor: Adder,
|
18 | reset: function() {
|
19 | this.s =
|
20 | this.t = 0;
|
21 | },
|
22 | add: function(y) {
|
23 | add(temp, y, this.t);
|
24 | add(this, temp.s, this.s);
|
25 | if (this.s) this.t += temp.t;
|
26 | else this.s = temp.t;
|
27 | },
|
28 | valueOf: function() {
|
29 | return this.s;
|
30 | }
|
31 | };
|
32 |
|
33 | var temp = new Adder;
|
34 |
|
35 | function add(adder, a, b) {
|
36 | var x = adder.s = a + b,
|
37 | bv = x - a,
|
38 | av = x - bv;
|
39 | adder.t = (a - av) + (b - bv);
|
40 | }
|