Skip to content

Commit 537bd70

Browse files
committed
Merge pull request #1 from gagern/realReciprocal
Fix reciprocal of a complex number with zero imaginary part
2 parents 01c0a52 + d4dd539 commit 537bd70

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

documentation.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,10 @@ <h1>Complex linear algebra</h1>
11071107
OUT> {x:0.5588,y:-0.2353}
11081108
IN> z.sub(w)
11091109
OUT> {x:1, y:-4}
1110+
IN> z.reciprocal()
1111+
OUT> {x: 0.12, y: -0.16}
1112+
IN> numeric.t(2, 0).reciprocal()
1113+
OUT> {x: 0.5, y: 0}
11101114
</pre>
11111115

11121116
Complex vectors and matrices can also be handled:

src/documentation.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,10 @@ <h1>Complex linear algebra</h1>
11071107
OUT> {x:0.5588,y:-0.2353}
11081108
IN> z.sub(w)
11091109
OUT> {x:1, y:-4}
1110+
IN> z.reciprocal()
1111+
OUT> {x: 0.12, y: -0.16}
1112+
IN> numeric.t(2, 0).reciprocal()
1113+
OUT> {x: 0.5, y: 0}
11101114
</pre>
11111115

11121116
Complex vectors and matrices can also be handled:

src/numeric.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1377,7 +1377,7 @@ numeric.T.prototype.reciprocal = function reciprocal() {
13771377
var d = numeric.add(mul(this.x,this.x),mul(this.y,this.y));
13781378
return new numeric.T(div(this.x,d),div(numeric.neg(this.y),d));
13791379
}
1380-
return new T(div(1,this.x));
1380+
return new numeric.T(div(1,this.x), 0);
13811381
}
13821382
numeric.T.prototype.div = function div(y) {
13831383
if(!(y instanceof numeric.T)) y = new numeric.T(y);

0 commit comments

Comments
 (0)