Fixed offset bug.

This commit is contained in:
Dakota Blair 2018-03-21 19:46:31 +00:00
parent 13d1ad7a6a
commit c2917dca52
2 changed files with 12 additions and 1 deletions

View File

@ -42,7 +42,7 @@ function _nthComplexRoots(a, root) {
if (root % 1 !== 0) throw new Error('Root must be an integer');
if (a === 0 || a.abs() === 0) return [complex(0)];
var aIsNumeric = typeof(a) === 'number';
var offset = 0;
var offset;
// determine the offset (argument of a)/(pi/2)
if (aIsNumeric || a.re === 0 || a.im === 0) {
if (aIsNumeric) {

View File

@ -21,6 +21,17 @@ describe('nthRoots', function() {
});
});
it('should return the correct answer for Complex values', function() {
var roots = nthRoots(complex(3, 4), 2);
var roots1 = [
{ re: 2, im: 1 },
{ re: -2.0000000000000004, im: -0.9999999999999999}
];
roots.forEach(function (value, index, array) {
assert.deepEqual(value, roots1[index]);
});
});
var twos = [
complex(2, 0),
complex(0, 2),