Complex numbers (64-bit).
$ npm install dstructs-complex64
var Complex64 = require( 'dstructs-complex64' );
64-bit complex number constructor
, where real
and imag
correspond to the real and imaginary components, respectively.
var z = new Complex64( 3, -2 );
// returns Complex64( 3 - 2i )
A Complex64
instance has the following properties...
A read-only property returning the real component.
var real = z.real;
// returns <number>
A read-only property returning the imaginary component.
var imag = z.imag;
// returns <number>
A Complex64
instance has the following methods...
These methods do not mutate a Complex64
instance and, instead, return some representation.
Returns a string
representation of a Complex64
instance.
var z = new Complex64( 3, -2 );
var str = z.toString();
// returns '3 - 2i'
Returns a JSON
representation of a Complex64
instance. JSON#stringify
implicitly calls this method when stringifying a Complex64
instance.
var z = new Complex64( 3, -2 );
var json = z.toJSON();
/*
{
"type": "Complex64",
"real": 3,
"imag": -2
}
*/
To a revive a Complex64
number from a JSON
string,
// Complex64 reviver:
var reviver = require( 'dstructs-complex64-reviver' );
var z = new Complex64( 3, -2 );
// Stringify a complex number (implicitly calls `.toJSON`):
var str = JSON.stringify( z );
// returns '{"type":"Complex64","real":3,"imag":-2}'
// Revive a Complex64 instance from a JSON string:
var z = JSON.parse( str, reviver );
// returns Complex64( 3 - 2i )
var Complex64 = require( 'dstructs-complex64' );
var z = new Complex64( 3, -2 );
console.log( 'type: %s', typeof z );
// returns 'object'
console.log( 'str: %s', z );
// returns '3 - 2i'
console.log( 'real: %d', z.real );
// returns 3
console.log( 'imag: %d', z.imag );
// returns -2
console.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
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.
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
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
Copyright © 2016. The Compute.io Authors.