Skip to content

HotdoGuy90/ComplexJS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

ComplexJS

A Javascript library that supports Complex Numbers.

Installation

To add it to your project just download the file and place it in or near the directory that has your "html" file. Then you can include it into your project like this:

<!--  Make sure to include this file before other script(s) earlier otherwise it/they won't have the ComplexJS library -->
<script src="/path/to/file/complex.js"></script>

Or you can just add it from the url like this:

<!--  Make sure to include this file before other script(s) earlier otherwise it/they won't have the ComplexJS library -->
<script src="https://cdn.jsdelivr.net/gh/HotdoGuy90/ComplexJS@master/complex.js"></script>

Usage

You can create a complex number easily just by creating a new "Complex" object:

var z = new Complex(1, 2); // Equivalent to 1+2i

To make the complex number's value able to be outputed use the show() method:

console.log(z.show()) // Outputs "(1+2i)"

To do arithmetic (since operators don't work), use the add(), subract(), multiply(), or divide() method:

/* They can't input regular numbers */
var sum = z.add(new Complex(3, 4)) // Outputs 4+6i
var dif = z.subtract(new Complex(3, 4)) // Outputs -2-2i
var pro = z.multiply(new Complex(3, 4)) // Outputs 3+8i
var quo = z.divide(new Complex(3, 4)) // Outputs 0.333+0.5i

To raise an exponent don't use Math.pow(), instead use the exponent() method:

/* This can input regular numbers */
var pow = z.exponent(2) // Outputs -3+4i

To find the modulus/absolute value, use the abs() method:

console.log(z.abs()) // Outputs √5

That is pretty much all, enjoy!

About

A Javascript library that supports Complex Numbers.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published