2017 © Pedro Peláez
 

library eval-math

EvalMath

image

conclusivesystems/eval-math

EvalMath

  • Wednesday, April 26, 2017
  • by rockyjvec
  • Repository
  • 2 Watchers
  • 1 Stars
  • 52 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 21 % Grown

The README.md

Composer/Packagist version of EvalMath originally by Miles Kaufman Copyright (C) 2005 Miles Kaufmann http://www.twmagic.com/, (*1)

This version contains improvements from moodle., (*2)

NAME

EvalMath - safely evaluate math expressions

DESCRIPTION

Use the EvalMath class when you want to evaluate mathematical expressions 
from untrusted sources.  You can define your own variables and functions,
which are stored in the object.  Try it, it's fun!

SYNOPSIS

`$m = new EvalMath;`

`// basic evaluation:`
`$result = $m->evaluate('2+2');`

`// supports: order of operation; parentheses; negation; built-in functions`
`$result = $m->evaluate('-8(5/2)^2*(1-sqrt(4))-8');`

`// create your own variables`
`$m->evaluate('a = e^(ln(pi))');`

`// or functions`
`$m->evaluate('f(x,y) = x^2 + y^2 - 2x*y + 1');`

`// and then use them`
`$result = $m->evaluate('3*f(42,a)');`

METHODS

`$m->evaluate($expr)`
    Evaluates the expression and returns the result.  If an error occurs,
    prints a warning and returns false.  If $expr is a function assignment,
    returns true on success.

`$m->e($expr)`
    A synonym for $m->evaluate().

`$m->vars()`
    Returns an associative array of all user-defined variables and values.

`$m->funcs()`
    Returns an array of all user-defined functions.

PARAMETERS

`$m->suppress_errors`
    Set to true to turn off warnings when evaluating expressions

`$m->last_error`
    If the last evaluation failed, contains a string describing the error.
    (Useful when suppress_errors is on).

The Versions

26/04 2017

dev-master

9999999-dev

EvalMath

  Sources   Download

The Requires

  • php >=5.3

 

evalmath

26/04 2017

1.0.1

1.0.1.0

EvalMath

  Sources   Download

The Requires

  • php >=5.3

 

evalmath

22/04 2017

1.0.0

1.0.0.0

EvalMath

  Sources   Download

The Requires

  • php >=5.3

 

evalmath