8000 GitHub - p2js/verbena-complex: verbena + complex numbers
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

p2js/verbena-complex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 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
import { ComplexFunction } from 'verbena-complex';

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

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

About

verbena + complex numbers

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0