From d4dd539c4a5b2adc5f77c2fb0d038ecd1d0aefd0 Mon Sep 17 00:00:00 2001 From: Martin von Gagern Date: Tue, 18 Nov 2014 10:58:33 +0100 Subject: [PATCH] Fix reciprocal of a complex number with zero imaginary part. --- documentation.html | 4 ++++ src/documentation.html | 4 ++++ src/numeric.js | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/documentation.html b/documentation.html index 9767498..80ac39a 100644 --- a/documentation.html +++ b/documentation.html @@ -638,6 +638,10 @@

Complex linear algebra

OUT> {x:0.5588,y:-0.2353} IN> z.sub(w) OUT> {x:1, y:-4} +IN> z.reciprocal() +OUT> {x: 0.12, y: -0.16} +IN> numeric.t(2, 0).reciprocal() +OUT> {x: 0.5, y: 0} Complex vectors and matrices can also be handled: diff --git a/src/documentation.html b/src/documentation.html index 9767498..80ac39a 100644 --- a/src/documentation.html +++ b/src/documentation.html @@ -638,6 +638,10 @@

Complex linear algebra

OUT> {x:0.5588,y:-0.2353} IN> z.sub(w) OUT> {x:1, y:-4} +IN> z.reciprocal() +OUT> {x: 0.12, y: -0.16} +IN> numeric.t(2, 0).reciprocal() +OUT> {x: 0.5, y: 0} Complex vectors and matrices can also be handled: diff --git a/src/numeric.js b/src/numeric.js index 537b68f..336f081 100644 --- a/src/numeric.js +++ b/src/numeric.js @@ -1071,7 +1071,7 @@ numeric.T.prototype.reciprocal = function reciprocal() { var d = numeric.add(mul(this.x,this.x),mul(this.y,this.y)); return new numeric.T(div(this.x,d),div(numeric.neg(this.y),d)); } - return new T(div(1,this.x)); + return new numeric.T(div(1,this.x), 0); } numeric.T.prototype.div = function div(y) { if(!(y instanceof numeric.T)) y = new numeric.T(y);