numbers / numbers.js

Advanced Mathematics Library for Node.js and JavaScript
Apache License 2.0
1.76k stars 167 forks source link

Complex Powers, Roots and Trig Functions. #77

Closed mattfowler closed 11 years ago

mattfowler commented 11 years ago

Added several functions for complex numbers:

Also added to basic a method that will compare two floats given an epsilon. I used this in one test where this comparison was being done manually.

The complex number equals method can also be used to clean up some of the complex tests, for instance:

var res = A.subtract(B);

assert.equal(2, res.re);
assert.equal(4, res.im);

can become:

var res = A.subtract(B);
var expected = new Complex(2, 4);

assert.equal(true, expected.equals(res));

Which I'm not sure if you want to do everywhere, comparing the real and imaginary directly will give you a better error message.

It is probably a good idea to extend the assert library to have the following methods in the near future:

assert.equal(number, number, epsilon) assert.complexEqual(complex, complex, epsilon)

The implementations would contain separate asserts, so you would get better failure messages.