Skip to content

MehrAlsNix/ext-tinyexpr

Repository files navigation

PHP TinyExpression

Math evaluation for strings.

Build Status Build status

TinyExpr Binding

TinyExpr Bindings for PHP

TinyExpr is a very small parser and evaluation library for evaluating math expressions from C

Installation

Linux

git clone --branch "master" --depth 1 https://github.com/MehrAlsNix/ext-tinyexpr.git /tmp/tinyexpression
cd /tmp/tinyexpression
phpize
./configure
make
make install
echo "extension=tinyexpression.so" > /usr/local/etc/php/conf.d/tinyexpression.ini

Windows

tbd.


Functions

tinyexpr_interp


(TinyExpression 0.1.0)

tinyexpr_interp - Evaluate math expressions from a string.

Description
tinyexpr_interp ( string $expr ) : float
Parameters

expr string

Return Values

Returns the evaluated math expression as a float.

Examples
docker-compose build
docker-compose up -d
docker-compose exec php bash
php -r "var_dump(tinyexpr_interp('2*9+8-(5/9)'));"
 
float(25.444444444444)
php -r "var_dump(tinyexpr_interp('sin(0.6)'));"
 
float(0.56464247339504)

Not parsable expressions will return NAN:

php -r "var_dump(tinyexpr_interp('(1+2'), is_nan(tinyexpr_interp('(1+2')));"
 
float(NAN)
bool(true)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy