diff options
author | Bruce Wells <brucekwells@gmail.com> | 2022-06-02 01:11:51 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-02 01:11:51 +0300 |
commit | a944fe4e5631a6b3085ee2962e3159261f90bfcd (patch) | |
tree | 8dbbb41307b76f23db01f420418c7b8fbc44a996 /README.md | |
parent | cbada2b920782bdfd2f18ef88c09e24ae4840f4a (diff) |
Bcmath (#115)v2.3.0
* Add useBCMath
* Support for % operator (mod)
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -3,7 +3,7 @@ # A simple and extensible math expressions calculator ## Features: -* Built in support for +, -, *, / and power (^) operators +* Built in support for +, -, *, %, / and power (^) operators * Paratheses () and arrays [] are fully supported * Logical operators (==, !=, <, <, >=, <=, &&, ||) * Built in support for most PHP math functions @@ -101,7 +101,7 @@ $executor->calculate('avarage(1, 3, 4, 8)'); // 4 ``` ## Operators: -Default operators: `+ - * / ^` +Default operators: `+ - * / % ^` Add custom operator to executor: @@ -111,7 +111,7 @@ use NXP\Classes\Operator; $executor->addOperator(new Operator( '%', // Operator sign false, // Is right associated operator - 170, // Operator priority + 180, // Operator priority function (&$stack) { $op2 = array_pop($stack); @@ -189,6 +189,10 @@ $calculator->setVarNotFoundHandler( ); ``` +## Floating Point BCMath Support +By default, `MathExecutor` uses PHP floating point math, but if you need a fixed precision, call **useBCMath()**. Precision defaults to 2 decimal points, or pass the required number. +`WARNING`: Functions may return a PHP floating point number. By doing the basic math functions on the results, you will get back a fixed number of decimal points. Use a plus sign in from of any stand alone function to return the proper number of decimal places. + ## Division By Zero Support: Division by zero throws a `\NXP\Exception\DivisionByZeroException` by default ```php |