Code Monkey home page Code Monkey logo

eval-math's Introduction

Composer/Packagist version of EvalMath by Miles Kaufman Copyright (C) 2005 Miles Kaufmann http://www.twmagic.com/ 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).

eval-math's People

Contributors

dbojdo avatar dbojdo8x8 avatar tecem avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.