Skip to content

Repository files navigation

Complex64

NPM versionBuild StatusCoverage StatusDependencies

Complex numbers (64-bit).

Installation

$ npm install dstructs-complex64

Usage

varComplex64=require('dstructs-complex64');

Complex64( real, imag )

64-bit complex number constructor, where real and imag correspond to the real and imaginary components, respectively.

varz=newComplex64(3,-2);// returns Complex64( 3 - 2i )

Properties

A Complex64 instance has the following properties...

real

A read-only property returning the real component.

varreal=z.real;// returns <number>

imag

A read-only property returning the imaginary component.

varimag=z.imag;// returns <number>

Methods

A Complex64 instance has the following methods...

Accessor Methods

These methods do not mutate a Complex64 instance and, instead, return some representation.

Complex64.prototype.toString()

Returns a string representation of a Complex64 instance.

varz=newComplex64(3,-2);varstr=z.toString();// returns '3 - 2i'

Complex64.prototype.toJSON()

Returns a JSON representation of a Complex64 instance. JSON#stringify implicitly calls this method when stringifying a Complex64 instance.

varz=newComplex64(3,-2);varjson=z.toJSON();/*	{ "type": "Complex64", "real": 3, "imag": -2	}*/

To a revive a Complex64 number from a JSON string,

// Complex64 reviver:varreviver=require('dstructs-complex64-reviver');varz=newComplex64(3,-2);// Stringify a complex number (implicitly calls `.toJSON`):varstr=JSON.stringify(z);// returns '{"type":"Complex64","real":3,"imag":-2}'// Revive a Complex64 instance from a JSON string:varz=JSON.parse(str,reviver);// returns Complex64( 3 - 2i )

Examples

varComplex64=require('dstructs-complex64');varz=newComplex64(3,-2);console.log('type: %s',typeofz);// returns 'object'console.log('str: %s',z);// returns '3 - 2i'console.log('real: %d',z.real);// returns 3console.log('imag: %d',z.imag);// returns -2console.log('JSON: %s',JSON.stringify(z));// returns {"type":"Complex64","real":3,"imag":-2}

To run the example code from the top-level application directory,

$ node ./examples/index.js

Tests

Unit

This repository uses tape for unit tests. To run the tests, execute the following command in the top-level application directory:

$ make test

All new feature development should have corresponding unit tests to validate correct functionality.

Test Coverage

This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:

$ make test-cov

Istanbul creates a ./reports/coverage directory. To access an HTML version of the report,

$ make view-cov

Browser Support

This repository uses Testling for browser testing. To run the tests in a (headless) local web browser, execute the following command in the top-level application directory:

$ make test-browsers

To view the tests in a local web browser,

$ make view-browser-tests

License

MIT license.

Copyright

Copyright © 2016. The Compute.io Authors.

About

Complex numbers (64-bit).

Resources

Stars

3 stars

Watchers

3 watching

Forks

Releases

Packages

Contributors

Languages