Skip to content

Instantly share code, notes, and snippets.

@kkeeth
Last active July 31, 2016 13:40
Show Gist options
  • Select an option

  • Save kkeeth/32f350f27a3892a0a0cf2505b30a6aa1 to your computer and use it in GitHub Desktop.

Select an option

Save kkeeth/32f350f27a3892a0a0cf2505b30a6aa1 to your computer and use it in GitHub Desktop.
複素関数をプログラムで実装
// 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);
// 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