From c2917dca525979f923fc8e53e8fe15532ec08802 Mon Sep 17 00:00:00 2001 From: Dakota Blair Date: Wed, 21 Mar 2018 19:46:31 +0000 Subject: [PATCH] Fixed offset bug. --- lib/function/arithmetic/nthRoots.js | 2 +- test/function/arithmetic/nthRoots.test.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/function/arithmetic/nthRoots.js b/lib/function/arithmetic/nthRoots.js index 04941fb23..4ac81205c 100644 --- a/lib/function/arithmetic/nthRoots.js +++ b/lib/function/arithmetic/nthRoots.js @@ -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) { diff --git a/test/function/arithmetic/nthRoots.test.js b/test/function/arithmetic/nthRoots.test.js index aeca804ba..80cebc277 100644 --- a/test/function/arithmetic/nthRoots.test.js +++ b/test/function/arithmetic/nthRoots.test.js @@ -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),