rodriados/mathr 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

rodriados/mathr

最新稳定版本:v3.0

Composer 安装命令:

composer require rodriados/mathr

包简介

Math expressions: parser and evaluator.

README 文档

README

license MIT version 3.0 Build Status Coverage Status

Mathr is a fast mathematical expression parser, evaluator and calculator with some added juice.

Usage

The simplest usage possible for Mathr is by simply sending in a math expression.

<?php
$mathr = new Mathr;
$result = $mathr->evaluate("3 + 4 * 5");
echo $result; // 23

You also can create your own variables and functions!

<?php
$mathr->evaluate("v = 10");
$mathr->evaluate("fibonacci(0) = 0");
$mathr->evaluate("fibonacci(1) = 1");
$mathr->evaluate("fibonacci(x) = fibonacci(x - 1) + fibonacci(x - 2)");
$result = $mathr->evaluate("fibonacci(v)");
echo $result; // 55

If you want to, it's possible to bind functions to native PHP closures!

<?php
$mathr->set('triangle(b, h)', fn ($b, $h) => ($b * $h) / 2);
$result = $mathr->evaluate('triangle(5, 8)');
echo $result; // 20

There are a plenty of native functions and variables which you can use at will.

<?php
$mathr->evaluate("fibonacci(x) = ceil((φ ^ x - (1 - φ) ^ x) / sqrt(5))");
$result = $mathr->evaluate("fibonacci(10)");
echo $result; // 55

You can easily export and import your functions and variables.

<?php
$exported = $mathr->export(); // Exports all bound functions and variables.
$mathr->import($exported); // Imports functions and variables.

Install

The recommended way to install Mathr is via Composer.

{
    "require": {
        "rodriados/mathr": "v3.0"
    }
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-07-11