2017 © Pedro Peláez
 

library simple-math

Simple math evaluator

image

phpmyadmin/simple-math

Simple math evaluator

  • Wednesday, November 8, 2017
  • by phpmyadmin
  • Repository
  • 5 Watchers
  • 0 Stars
  • 35 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

SimpleMath

Simple math expression evaluator., (*1)

Please note that in most cases it's better to use Symfony ExpressionLanguage Component instead. It performs better and provides more features., (*2)

This repository will probably not receive any updates in future., (*3)

Build Status codecov.io Scrutinizer Code Quality Packagist, (*4)

Features

  • Supports basic arithmetic operations +, -, *, /, %
  • Supports parenthesis
  • Supports right associative ternary operator
  • Supports comparison operators ==, !=, >, <, >=, <=
  • Supports basic logical operations &&, ||
  • Supports variables (either PHP style $a or simple n)

The library was developed in order to be able to evaluate Gettext plural equations, but can be used for any mathematical calculations., (*5)

Installation

Please use Composer to install:, (*6)

composer require phpmyadmin/simple-math

Documentation

The API documentation is available at https://develdocs.phpmyadmin.net/simple-math/., (*7)

Object API usage

// Create math object
$math = new SimpleMath\Math();

// Evaluate expression
$value = $math->evaluate('1 + 2');

// Evaluate expression with PHP style variable
$math->registerVariable('$a', 4);
$value = $math->evaluate('$a + 1');

// Evaluate expression with variable
$math->registerVariable('n', 4);
$value = $math->evaluate('n + 1');

// Calculate same expression with different values
$math = new SimpleMath\Math();

$math->parse('n + 1');

$math->registerVariable('n', 10);
$value = $math->run();

$math->registerVariable('n', 100);
$value = $math->run();

History

This library is based on Expressions.php gist. It adds some functions, performance improvements and ability to install using Composer., (*8)

The Versions

08/11 2017

dev-master

9999999-dev https://github.com/phpmyadmin/simple-math

Simple math evaluator

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.4.0

 

The Development Requires

php math eval calculation

12/10 2016

0.2

0.2.0.0 https://github.com/phpmyadmin/simple-math

Simple math evaluator

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.4.0

 

The Development Requires

php math eval calculation

12/10 2016

0.1

0.1.0.0 https://github.com/phpmyadmin/simple-math

Simple math evaluator

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.4.0

 

The Development Requires

php math eval calculation