Complex numbers (64-bit).
$ npm install dstructs-complex64varComplex64=require('dstructs-complex64');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 )A Complex64 instance has the following properties...
A read-only property returning the real component.
varreal=z.real;// returns <number>A read-only property returning the imaginary component.
varimag=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.
varz=newComplex64(3,-2);varstr=z.toString();// returns '3 - 2i'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 )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.jsThis repository uses tape for unit tests. To run the tests, execute the following command in the top-level application directory:
$ make testAll 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-covIstanbul creates a ./reports/coverage directory. To access an HTML version of the report,
$ make view-covThis 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-browsersTo view the tests in a local web browser,
$ make view-browser-testsCopyright © 2016. The Compute.io Authors.