Question: I'm making a math library because 0.1 + 0.2 DOES NOT = 0.30000000000004. But I ran into a really weird problem

I have an array:

```
var array = [1,2,3,".",4,5,6];

```

I want to split it into two parts so I...

```
var part1 = array;
var part2 = array;

```

And then...

```
for (var i = 4; i < 7; i++) {
  part1[i] = 0;
};

```

So now part1 = 

```
[1,2,3,".",0,0,0]

```

As it should but then I arrive at this problem. After I...

```
for (i = 2; i > -1; i--) {
  part2[i] = 0;
};

```

Part1, part2 and array now = 

```
[0,0,0,".",0,0,0]

```

This shouldn't happen, part2 should =

```
[0,0,0,".",4,5,6]

```

But it doesn't

???

Answer: 
You have to copy the array:

```
var part1 = array.concat();// it is possible to use array.slice() too.
var part2 = array.concat();

```

If not, you are always modifying the same object, since part1 and part2 will have a reference to the array variable.

On the other hand, I would not recomend you to build your own math library just to resolve floating point issues in JS. [Have you read similar questions?](https://stackoverflow.com/questions/588004/is-floating-point-math-broken)
What is going wrong in your code is that you don't create a clone of the array: `array`, `part1`, and `part2` all point to the very same array. You can create a copy like `part1 = array.slice(0)`.

Instead of writing your own math library to solve floating point round-off errors, you can use for example BigNumbers in [math.js](http://mathjs.org):

```
// configure math.js to use BigNumbers by default
math.config({
  number: 'bignumber', // Default type of number: 'number' (default) or 'bignumber'
  precision: 64        // Number of significant digits for BigNumbers
});

// evaluate an expression
math.eval('0.1 + 0.2'); // BigNumber, 0.3

```

See docs on BigNumbers: <http://mathjs.org/docs/datatypes/bignumbers.html>