Prepare lib to be a native class

This commit is contained in:
Laurent Destailleur 2018-03-25 19:21:00 +02:00
parent c50b772b11
commit 73273f68b3

View File

@ -1,5 +1,4 @@
<?php <?php
/* /*
================================================================================ ================================================================================
@ -92,7 +91,7 @@ class EvalMath {
var $last_error = null; var $last_error = null;
var $last_error_code = null; var $last_error_code = null;
var $v = array('e'=>2.71,'pi'=>3.14); // variables (and constants) var $v = array('e'=>2.71,'pi'=>3.14159); // variables (and constants)
var $f = array(); // user-defined functions var $f = array(); // user-defined functions
var $vb = array('e', 'pi'); // constants var $vb = array('e', 'pi'); // constants
var $fb = array( // built-in functions var $fb = array( // built-in functions
@ -101,7 +100,10 @@ class EvalMath {
'tan','tanh','arctan','atan','arctanh','atanh', 'tan','tanh','arctan','atan','arctanh','atanh',
'sqrt','abs','ln','log'); 'sqrt','abs','ln','log');
function EvalMath() { /**
* Constructor
*/
function __construct() {
// make the variables a little more accurate // make the variables a little more accurate
$this->v['pi'] = pi(); $this->v['pi'] = pi();
$this->v['e'] = exp(1); $this->v['e'] = exp(1);
@ -172,7 +174,7 @@ class EvalMath {
function nfx($expr) { function nfx($expr) {
$index = 0; $index = 0;
$stack = new EvalMathStack; $stack = new EvalMathStack();
$output = array(); // postfix form of expression, to be passed to pfx() $output = array(); // postfix form of expression, to be passed to pfx()
$expr = trim(strtolower($expr)); $expr = trim(strtolower($expr));
@ -299,7 +301,7 @@ class EvalMath {
if ($tokens == false) return false; if ($tokens == false) return false;
$stack = new EvalMathStack; $stack = new EvalMathStack();
foreach ($tokens as $token) { // nice and easy foreach ($tokens as $token) { // nice and easy
// if the token is a binary operator, pop two values off the stack, do the operation, and push the result back on // if the token is a binary operator, pop two values off the stack, do the operation, and push the result back on
@ -365,7 +367,9 @@ class EvalMath {
} }
} }
// for internal use /**
* Class for internal use
*/
class EvalMathStack { class EvalMathStack {
var $stack = array(); var $stack = array();