Coder Social home page Coder Social logo

langleyfoxall / math_eval Goto Github PK

View Code? Open in Web Editor NEW
41.0 3.0 7.0 15 KB

✖️➕➖➗ `math_eval` safely evaluates mathematical expressions

License: GNU Lesser General Public License v3.0

PHP 100.00%
mathematics eval php-library math-eval math helper-functions

math_eval's Introduction

✖️➕➖➗ Math Eval Helper Function

Build Status Coverage Status StyleCI Packagist

This PHP package provides a math_eval helper function, that allows safe evaluation of mathematical expressions, without the use of the potentially dangerous eval function.

Installation

The math_eval package can be easily installed using Composer. Just run the following command from the root of your project.

composer require "langleyfoxall/math_eval"

If you have never used the Composer dependency manager before, head to the Composer website for more information on how to get started.

Usage

To evaluate a basic mathematical expression, just pass its string representation to the math_eval function.

Here are some basic usage examples:

$two = math_eval('1 + 1');
$three = math_eval('5 - 2');
$ten = math_eval('2 * 5');
$four = math_eval('8 / 2');

It is also possible to pass expression variables. See the examples below.

$ten = math_eval('a + b', ['a' => 7, 'b' => 3]);
$fifteen = math_eval('x * y', ['x' => 3, 'y' => 5]);

Credit

This package makes use of the mossadal/math-parser package.

math_eval's People

Contributors

divineomega avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

math_eval's Issues

Example code misses 'require'

The example code misses the mandatory require:
require 'vendor/autoload.php';
The code does not run as written in the example.

Problem with simple calcul

Hi,

I have a problem with a simple calcul :

math_eval("0.37+0.31-0.68"), the result is "0" but the math_eval function return "-1.1102230246252E-16"

Have you an idea of the problem ?

Thanks

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.