Download the PHP package fintara/calculator-php without Composer
On this page you can find all versions of the php package fintara/calculator-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download fintara/calculator-php
More information about fintara/calculator-php
Files in fintara/calculator-php
Package calculator-php
Short Description Calculator for arithmetic expressions
License MIT
Informations about the package calculator-php
PHP Calculator for arithmetic expressions
PHP calculator which evaluates different arithmetic expressions:
The included functions by default are sqrt(x)
and log(base, arg)
, but
there is also an option to add custom functions with any number of arguments.
Basic usage
Advanced usage
Custom functions
You can add custom functions:
name
: name of the function, as it will be used in expressions. All lower case and _ (underscore) allowed.implementation
: how to evaluate the function.
Tokenizer
You can also use the tokenizer (or supply calculator with your own):
In case the expression contains functions (e.g. sqrt(x)
),
the tokenizer needs to know all functions' names as second parameter.
Note: The default tokenizer automatically adds *
(multiplication)
sign between a number and following function or a number and following
parenthesis (if the sign is not found).
Changelog
2.0.1
- Added LICENSE
2.0.0
- Breaking: operator
mod
is renamed to%
. - Breaking:
addFunction
does not need number of arguments anymore (removed 3rd argument). - Breaking: adding function with existing name throws.
You can use the helper
replaceFunction
. - Breaking:
getReversePolishNotation
is private. - Breaking:
setExpression
is removed. Use directlycalculate($expression)
. - Breaking:
ILexer
andDefaultLexer
are replaced withTokenizerInterface
andTokenizer
respectively.