在java中解析数学表达式的好库是什么? [英] What's a good library for parsing mathematical expressions in java?

查看:25
本文介绍了在java中解析数学表达式的好库是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名 Android 开发人员,作为我的下一个应用程序的一部分,我需要评估大量用户创建的数学表达式和方程.我正在寻找一个很好的 java 库,它是轻量级的,可以使用用户定义的变量和常量、三角函数和指数函数等来评估数学表达式.

I'm an Android Developer and as part of my next app I will need to evaluate a large variety of user created mathematical expressions and equations. I am looking for a good java library that is lightweight and can evaluate mathematical expressions using user defined variables and constants, trig and exponential functions, etc.

我环顾四周,Jep 似乎很受欢迎,但我想了解更多建议,尤其是来自以前使用过这些库的人的建议.

I've looked around and Jep seems to be popular, but I would like to hear more suggestions, especially from people who have used these libraries before.

推荐答案

我写了一个简单但功能强大的 MathExpression Evaluator 不久前,它是免费和开源的.它的主要优点是快速和小巧——两者对于手持设备来说都是一件好事.如果它满足您的需求,欢迎您使用.

I wrote a simple but capable Math Expression Evaluator a while back, which is free and open-source. It's main advantage is being fast and tiny - both are a good thing with hand-held devices. If it meets your need you are welcome to use it.

  • 具有推断优先级的基本数学运算符 (^ * × ·/÷ % + -).
  • 带括号的显式优先级.
  • 括号内的子表达式的隐式乘法.
  • 修正指数的右结合性(幂运算符).
  • 直接支持以 0x 为前缀的十六进制数字.
  • 常量和变量.
  • 可扩展的运算符.
  • 可扩展的功能.
  • 20 KiB 占用空间.
MathEval math=new MathEval();

math.setVariable("Top",    5);
math.setVariable("Left",  20);
math.setVariable("Bottom",15);
math.setVariable("Right", 60);

System.out.println("Middle: "+math.evaluate("floor((Right+1-Left)/2)"));

这篇关于在java中解析数学表达式的好库是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆