# Complex

Do calculations with Complex numbers

# Complex

Complex is a additional Type to deal with Complex Numbers in JavaScript. It provides several methods to add, multiply numbers as well as calculate the magnitude and angle in the complex plane.

You can get this package with NPM:

``````npm install Complex
``````

Complex can be built for the browser with wrapup or other tools that can generate browser JS from Node packages.

Testing is done with Mocha and Expect.js:

``````# install dependencies
npm install
# run the tests in node
./node_modules/.bin/mocha test/Complex.js
``````

or testing in the browser:

``````# install dependencies
npm install
# run a small node server
node ./test/server.js
# run tests
``````
1. real (number) the real part of the number
2. im (number) the imaginary part of the number

A in line function like Number.from.

1. real (number) the real part of the number
2. im (number, optional) the imaginary part of the number

Or

1. real (string) a string representation of the number, for example `1+4i`

Creates a complex instance from a polar representation: `r*e^(phi*i) = r (cos(phi) + i sin(phi))`

1. r (number) the radius/magnitude of the number
2. phi (number) the angle/phase of the number

A instance of the imaginary unit `i`

A instance for the real number `1`

Sets the real and imaginary properties a and b from `a + bi`

1. real (number) the real part of the number
2. im (number) the imaginary part of the number

Sets the a and b in `a + bi` from a polar representation.

1. r (number) the radius/magnitude of the number
2. phi (number) the angle/phase of the number

Sets the precision of the numbers. Similar to Number.prototype.toPrecision. Useful befor printing the number with the toString method.

1. k (number) An integer specifying the number of significant digits

Formats a number using fixed-point notation. Similar to Number.prototype.toFixed. Useful before printing the number with the toString method.

1. k (number) The number of digits to appear after the decimal point; this may be a value between 0 and 20, inclusive, and implementations may optionally support a larger range of values. If this argument is omitted, it is treated as 0

Finalizes the instance. The number will not change and any other method call will return a new instance. Very useful when a complex instance should stay constant. For example the Complex.i variable is a finalized instance.

Calculates the magnitude of the complex number

• abs

Calculates the angle with respect to the real axis, in radians.

• arg
• phase

Calculates the conjugate of the complex number (multiplies the imaginary part with -1)

Negates the number (multiplies both the real and imaginary part with -1)

Multiplies the number with a real or complex number

1. z (number, complex) the number to multiply with
• mult

Divides the number by a real or complex number

1. z (number, complex) the number to divide by
• div

Adds a real or complex number

1. z (number, complex) the number to add

Subtracts a real or complex number

1. z (number, complex) the number to subtract
• sub

Returns the base to the exponent

1. z (number, complex) the exponent

Returns the square root

Returns the natural logarithm (base `E`)

1. k (number) the actual answer has a multiplicity (`ln(z) = ln|z| + arg(z)`) where arg(z) can return the same for different angles (every 2*pi), with this argument you can define which answer is required

Calculates the `e^z` where the base is `E` and the exponential the complex number.

Calculates the sine of the complex number

Calculates the cosine of the complex number

Calculates the tangent of the complex number

Calculates the hyperbolic sine of the complex number

Calculates the hyperbolic cosine of the complex number

Calculates the hyperbolic tangent of the complex number

Returns a new Complex instance with the same real and imaginary properties

Returns a string representation of the complex number

Checks if the real and imaginary components are equal to the passed in compelex components.

1. z (number, complex) the complex number to compare with