Giter Club home page Giter Club logo

complex-js's Introduction

complex-js logo

Overview

Getting Started

To install via npm:

npm i complex-js moo nearley # peer dependencies for expression parser

Node.js:

const Complex = require('complex-js');

ES2015 Module:

import Complex from 'complex-js';

Browser:

<script src="https://cdn.jsdelivr.net/combine/npm/[email protected],npm/[email protected],npm/complex-js"></script>
<script>
const { Complex } = window;
</script>

RequireJS:

requirejs(['complex-js'], function (Complex) {

});

Documentation

API reference available at https://patrickroberts.github.io/complex-js/.

Code Coverage

Report available at https://patrickroberts.github.io/complex-js/lcov-report/.

License

Copyright (c) 2020 Patrick Roberts

MIT

complex-js's People

Contributors

dependabot[bot] avatar patrickroberts avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

complex-js's Issues

Bad multiply-division parsing

Hi, nice library. lightweight and so useful.

But trying to make a app, I note that some expressions are not parsed correctly:

Complex.compile('1/a*b*c',['a','b','c'])

returns a optimized function in the browser:

ƒ: anonymous(Complex,a,b,c) {
return this[0].divide(a.multiply(b)).multiply(c)
}

and

Complex.compile('(1/a)*b*c',['a','b','c'])

returns

ƒ: anonymous(Complex,a,b,c) {
return this[0].divide(a).multiply(b).multiply(c)
}

that are different expressions.

* and / operators should be the same precedence and the correct result is the last (a chain of operators without grouping).

Thanks

complex-js version: 5.0.0

Add Unit Testing

Addition of Mocha + Chai + Istanbul BDD-style unit testing and code coverage is currently in progress.

Contact

Hi Patrick,

I used your brilliant library to prepare a nice educational tool.
It is available here
http://plansoft.org/edu

I have an idea to add my code to your repository, what do you think?
Otherwise I will create my own repository.

Good job on complex.js !

Kind regards
https://github.com/MaciejSzymczak
[email protected]

(Don't worry you are not mentioned in my code yet, I will fix it soon, this is just a working code.)

pow(0+0i, 1+0i) === NaN

> C = require('complex-js')
> C(0,0).pow(C(1,0))
n { abs: 0, arg: NaN }
> C(0,0).pow(C(1,0)).real
NaN
> C(0,0).pow(C(1,0)).imag
NaN

The case of pow(0+0i, ...) needs to be handled specially, since you can't compute the angle. I think the logic should be:

   if (y.real === 0 && y.imag === 0) {
    return C(1, 0)
   }
   else if (x.real === 0 && x.imag === 0) {
    return C(0, 0)
  }
  else {
    ... existing logic ...
   }

passing numbers to operators

What are you thoughts on extending functionality so as to pass numbers to complex operators like:

> Complex(1,1).mult(10)
Complex( 10, 10 )

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.