quantk / arithmetic-parser

Arithmetic parser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Arithmetic Parser

Build Status codecov Scrutinizer Code Quality

Simple interpreter of arithmetic expressions

Usage

Simple arithmetic operations with operation priority

<?php
//1.0
$result = \App\Interpreter::evaluate('(1.0 + 2.0 * 3.0 / ( 6.0*6.0 + 5.0*44.0)) - 0.0234375');
?>

Simple functions such as sqrt (also supported cos,sin,tan)

<?php
//2.0
$result = \App\Interpreter::evaluate('sqrt(4)');
//3.0
$result = \App\Interpreter::evaluate('sqrt(2+2*2+3)');
?>

Power operator

<?php
//32
$result = \App\Interpreter::evaluate('2**5');
//32
$result = \App\Interpreter::evaluate('2^5');
//36
$result = \App\Interpreter::evaluate('(2+2*2)^2');
?>

About

Arithmetic parser


Languages

Language:PHP 100.0%