GD Complex
Import
import complex from "gd_complex"
var complex = require("../gd_complex.es5").complex;
Create
const c = complex(1, 2)
Chaining
Complex is designed to make sequences of operations a little easier and functional. To that end, functions are chainable as they either operate in place and return themselves, or remain immutable and return a new complex number that contains the result of the operation.
const y = complex(3, 4)
const x = complex(1, 2)
._sadd(3)
._smultiply(2)
._iadd(y)
Mutator Functions
These functions (prefixed with an underscore) will alter the complex number in place.
Scalar Operations
complex(1, 2)._sadd(3)
complex(1, 2)._ssubtract(5)
complex(1, 2)._smultiply(2)
complex(1, 2)._sdivide(2)
Complex Operations
complex(1, 2)._iadd(complex(1, 2))
complex(1, 2)._isubtract(complex(1, 2)),
complex(1, 2)._imultiply(complex(1, 2))
complex(1, 2)._idivide(complex(1, 3))
Static Functions
These functions do not modify the original complex number and always return a new number. In my opinion, lots more useful, but to each their own. Notice that these are the same as the Mutator Functions without the underscore.
Scalar Operations
complex(1, 2).sadd(3)
complex(1, 2).ssubtract(5)
complex(1, 2).smultiply(2)
complex(1, 2).sdivide(2)
Complex Operations
complex(1, 2).iadd(complex(1, 2))
complex(1, 2).isubtract(complex(1, 2)),
complex(1, 2).imultiply(complex(1, 2))
complex(1, 2).idivide(complex(1, 3))
Access Functions
complex(1, 2).value()
complex(1, 2).re()
complex(1, 2).im()
complex(1, 2).type()
Other Useful Functions
complex(1, 2).conjugate()
complex(1, 2).reciprocal()
complex(1, 2).normalize()
complex(1, 2).sqrLength()
complex(1, 2).length()
complex(1, 2).area()
complex(1, 2).clone()
complex(1, 2).angle()