定制 hinyka/evalmath 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hinyka/evalmath

Composer 安装命令:

composer require hinyka/evalmath

包简介

Use the EvalMath when you want to evaluate mathematical expressions from untrusted sources.

README 文档

README

Safely evaluate math expressions.

Description

The EvalMath empowers safe evaluation of mathematical expressions originating from potentially untrusted sources.
It supports built-in and user-defined functions and variables, offering flexibility for complex mathematical operations.

Usage

# Create a base instance (default precision is set to 6 digits after the decimal point)
$em = new EvalMath;

# Create a base instance with the precision parameter set to 2 digits after the decimal point
$em = new EvalMath(2);

# Basic evaluation:
$result = $em->evaluate('2+2');

# Supports: order of operation; parentheses; negation; built-in functions
$result = $em->evaluate('-8(5/2)^2*(1-sqrt(4))-8');

# Create your own variables
$em->evaluate('a = e^(ln(pi))');

# or functions
$em->evaluate('f(x,y) = x^2 + y^2 - 2x*y + 1');

# and then use them
$result = $em->evaluate('3*f(42,a)');

Methods

Method Description
$em->evaluate($expression) Evaluates the expression and returns the result
$em->e($expression) A synonym for $m->evaluate($expression)
$em->getUserVariables() Returns an associative array of all user-defined variables and values
$em->getUserFunctions() Returns an array of all user-defined functions

Credits

This is a heavily refactored version of EvalMath, originally by Daniel Bojdo, which is based on Miles Kaufmann's EvalMath class.

License

This project is licensed under the BSD 3-Clause License. The full text of the license can be found in the LICENSE file.

统计信息

  • 总下载量: 11
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2023-08-24