verbena-complex
v0.2.0
Published
verbena + complex numbers
Maintainers
Readme
verbena-complex
This package acts as a complex number extension to the 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
iwill be converted to the constantito allow implicit multiplications of variables by i, such asix. - 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 adding them to a function definition will cause an error.
Usage
npm install verbena-compleximport { ComplexFunction } from 'verbena-complex';
const f = ComplexFunction("f(x) = re(x * (3+2i))");
console.log(f(2)); // { re: 6, im: 0 }