9

Is there a good math parser in Javascript? I want to be able to parse something like:

LOG(3.14)+5^2+POW(2,LN(X*2,Y))

Thanks,

1
  • 1
    Is this for a job? If not I would use this as an opportunity to write my own. Commented Oct 14, 2010 at 19:20

4 Answers 4

7

Here is a brand new initiative:

http://mathjs.org

Comes with an extensive and easy to use parser which also supports assignment and usage of variables and functions like in your example expression.

Sign up to request clarification or add additional context in comments.

Comments

3

Use this one. It defined an "operator" object that lets you define your own operators.

http://jsfromhell.com/classes/math-processor

Warning: it uses with. If you don't know why that's dangerous, find out before using this code in anything critical. Alternately, you could just re-write it without with.

1 Comment

I wouldn't worry too much about with because of this: {p: MathProcessor.prototype}.
2

Try nerdamer

var result = nerdamer('log(3.14)+5^2+2^(log(X*2)/log(Y))').evaluate();
document.getElementById('text').innerHTML = result.text();
<script src="http://nerdamer.com/js/nerdamer.core.js"></script>
<div id="text"></div>

Comments

0

I know it's an old question, but I found it by chance and I have something to help. Not as complete as mathjs, but useful and fast.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.