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
- Host: GitHub
- URL: https://github.com/p2js/verbena-complex
- Owner: p2js
- Created: 2024-11-25T23:48:13.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-26T10:22:59.000Z (over 1 year ago)
- Last Synced: 2025-06-17T21:08:13.324Z (12 months ago)
- Language: TypeScript
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
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 }
```