sjkaliski/numbers.js — pull request #77 by mattfowler (2012-12-24 18:52:34+00:00)
Title: Complex Powers, Roots and Trig Functions.

Added several functions for complex numbers:

- Power of a complex number to a number.
- Power of a complex number to a complex number.
- Get all roots of a complex number.
- Trig functions sine, cosine and tangent.
- Equals method for complex numbers with an epsilon.

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.