Javascript math parser library

余生颓废 提交于 2019-11-27 18:09:27

问题


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:


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.




回答2:


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.




回答3:


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>



回答4:


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.



来源:https://stackoverflow.com/questions/3936730/javascript-math-parser-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!