Configuration ############# .. highlight:: php ``Arokettu\ArithmeticParser\Config`` class is used to configure the calculator and the parser. Config is mutable but it is cloned internally when passed to prevent external alterations. ``Config::default()`` ===================== The default preset used when no config is specified. Functions ========= .. versionadded:: 1.1 removeFunction() and clearFunctions() .. versionchanged:: 2.0 Functions can accept any number of arguments .. versionadded:: 2.0 ``pi()``, ``e()``, ``if()`` .. versionchanged:: 2.0 ``log()`` now also has ``base`` optional param The function must be a callable that accepts float arguments. Default functions: `abs `__, `exp `__, `log(num, base = e()) `__, `log10 `__, `sqrt `__, `acos `__, `asin `__, `atan `__, `cos `__, `sin `__, `tan `__, `acosh `__, `asinh `__, `atanh `__, `cosh `__, `sinh `__, `tanh `__, `ceil `__, `floor `__, `round `__, `deg2rad `__, `rad2deg `__, `pi `__, `e `__, if(if, then, else). .. note:: ``if()`` is a regular function and therefore is not lazy. For example, ``if (a = 0, 0, 1/a)`` will result in division by zero if ``a = 0``. You can: * Replace functions with your own list:: setFunctions(myfunc2: fn ($a) => a ** 2); * Add new functions:: addFunctions(myfunc3: fn ($a) => a ** 3); * Remove functions:: removeFunctions('acos', 'asin'); $config->removeFunction('acos'); // semantic alias for removeFunctions('acos') $config->clearFunctions(); // remove all functions Operators ========= .. versionadded:: 1.1 removeOperator() and clearOperators() .. versionadded:: 2.0 ``<``, ``>``, ``<=``, ``>=``, ``=``, ``==``, ``<>``, ``!=``, ``and``, ``AND``, ``or``, ``OR`` Operators can be unary and binary. Operator symbol can be any string without digits. Be wary when using latin character based operators, they are case-sensitive and may shadow variables and functions. Default operators: * ``+``, ``-`` in both unary and binary form. They are built-in and are not configurable. * ``*``, ``/``, ``<``, ``>``, ``<=``, ``>=``, ``=`` (also ``==``), ``<>`` (also ``!=``), ``and`` (also ``AND``), ``or`` (also ``OR``). You can: * Replace operators with your own list:: setOperators( new BinaryOperator('×', fn ($a, $b) => $a * $b, BinaryOperator::PRIORITY_MUL), new BinaryOperator('÷', fn ($a, $b) => $a / $b, BinaryOperator::PRIORITY_MUL), ); * Add new operators:: addOperators( new BinaryOperator('^', pow(...), BinaryOperator::PRIORITY_POW, BinaryAssoc::RIGHT), new UnaryOperator('!', factorial(...), UnaryPos::POSTFIX), ); * Remove operators:: removeOperators('*', '/'); // you cannot divide by zero if you cannot divide $config->removeOperator('/'); // semantic alias for removeOperators('/') // leave only + and - $config->clearOperators(); // + and - are handled specially and can't be removed