An open API service indexing awesome lists of open source software.

https://github.com/p2js/verbena-complex

verbena + complex numbers
https://github.com/p2js/verbena-complex

Last synced: 4 months ago
JSON representation

verbena + complex numbers

Awesome Lists containing this project

README

          

# verbena-complex

This package acts as a complex number extension to the [verbena](https://github.com/p2js/verbena) math function transcompiler to JS.

It uses verbena's standard lexer, parser and compiler, all completely unmodified. The magic happens with the library: All operations are redefined to convert all numbers to complex.js `Complex` numbers, and `i` is treated as a simple constant.

Some additional logic is implemented after lexing and parsing to allow for additional robustness and ergonomics:
- any identifier `i` will be converted to the constant `i` to allow implicit multiplications of variables by i, such as `ix`.
- due to the lack of logical operator overloading in verbena, as well as the lack of a natural order on the complex numbers, function clauses are unimplemented and will be removed before compilation.

## Usage

```
npm install verbena-complex
```

```js
import { ComplexFunction } from 'verbena-complex';

const f = ComplexFunction("f(x) = re(x * (3+2i))");

console.log(f(2)); // { re: 6, im: 0 }
```