Last active
July 31, 2016 13:40
-
-
Save kkeeth/32f350f27a3892a0a0cf2505b30a6aa1 to your computer and use it in GitHub Desktop.
複素関数をプログラムで実装
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // define complex number | |
| var Complex = (function () { | |
| function Complex(x, y) { | |
| this.x = x; | |
| this.y = y; | |
| } | |
| return Complex; | |
| }()); | |
| // adding | |
| var addc = function (z, w) { | |
| return new Complex(z.x + w.x, z.y + w.y); | |
| }; | |
| // subtraction | |
| var subtractc = function (z, w) { | |
| return new Complex(z.x - w.x, z.y - w.y); | |
| }; | |
| // multiplication | |
| var multiplyc = function (z, w) { | |
| return new Complex(z.x * w.x, z.y * w.y); | |
| }; | |
| // division | |
| var dividec = function (z, w) { | |
| return new Complex(z.x / w.x, z.y / w.y); | |
| }; | |
| // equaling | |
| var equalc = function (z, w) { | |
| return (z.x === w.x) && (z.y === w.y); | |
| }; | |
| // example complex variable | |
| var z = new Complex(2, 3); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // define complex number | |
| class Complex { | |
| x: number; | |
| y: number; | |
| constructor (x: number, y: number) { | |
| this.x = x; | |
| this.y = y; | |
| } | |
| } | |
| // adding | |
| var addc = (z: Complex, w: Complex): Complex => { | |
| return new Complex(z.x + w.x, z.y + w.y); | |
| } | |
| // subtraction | |
| var subtractc = (z: Complex, w: Complex): Complex => { | |
| return new Complex(z.x - w.x, z.y - w.y); | |
| } | |
| // multiplication | |
| var multiplyc = (z: Complex, w: Complex): Complex => { | |
| return new Complex(z.x * w.x, z.y * w.y); | |
| } | |
| // division | |
| var dividec = (z: Complex, w: Complex): Complex => { | |
| return new Complex(z.x / w.x, z.y / w.y); | |
| } | |
| // equaling | |
| var equalc = (z: Complex, w: Complex): Boolean => { | |
| return (z.x === w.x) && (z.y === w.y); | |
| } | |
| // example complex variable | |
| var z = new Complex(2, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment