0.0.9 • Published 13 years ago

math-lexer v0.0.9

Weekly downloads
37
License
-
Repository
github
Last release
13 years ago

node-math-lexer

Build Status

This package parses basic mathematical formulae including variables into functions that will accept variable values and calculate results.

Installation

You can install this through npm:

`npm install math-lexer`

##Usage

var sysutil = require('util');
var mlexer = require('math-lexer');
var func = "3 * x^2 * y + 5 / (log(2 ^ (x / 2), 2) + 3 + abs(y^3))";
var realfunc = mlexer.parseString(func);

sysutil.puts(realfunc({x: 2, y: -1}));
//=> -11
sysutil.puts(realfunc({x: 2, y: 1}));
//=> 13

Language

  • Addition: a + b
  • Subtraction: a - b
  • Multiplication: a * b
  • Division: a / b
  • Exponentiation: a ^ b
  • Exponentiation: exp(a)
  • Natural Logarithm: ln(a)
  • Logarithm: log(a, b) b is the base
  • Absolute Value: abs(a)
  • Square Root: sqrt(a)
  • N-th Root: root(a, b) b is the root degree

Tests

Tests that exist are written for Nodeunit. To run them, install nodeunit and then run

`nodeunit test.js`

Alternatively, just npm install and npm test.

License

MIT (see LICENSE file)

0.0.9

13 years ago

0.0.8

13 years ago

0.0.7

13 years ago

0.0.6

13 years ago

0.0.5

13 years ago

0.0.4

13 years ago

0.0.3

13 years ago

0.0.2

13 years ago

0.0.1

13 years ago