<commit_before><?php

/**
 * This file is part of the MathExecutor package
 *
 * (c) <NAME>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code
 */

namespace Z;

use Z\Classes\Calculator;
use Z\Classes\Lexer;
use Z\Classes\Token;
use Z\Classes\TokenFactory;

/**
 * Class MathExecutor
 * @package Z
 */
class MathExecutor
{
    /**
     * Available variables
     *
     * @var array
     */
    private $variables = array();

    /**
     * @var TokenFactory
     */
    private $tokenFactory;

    /**
     * @var array
     */
    private $cache = array();

    /**
     * Base math operators
     */
    public function __construct()
    {
        $this->addDefaults();
    }

    public function __clone()
    {
        $this->addDefaults();
    }

    /**
     * Set default operands and functions
     */
    protected function addDefaults()
    {
        $this->tokenFactory = new TokenFactory();

        $this->tokenFactory->addOperator('Z\Classes\Token\TokenPlus');
        $this->tokenFactory->addOperator('Z\Classes\Token\TokenMinus');
        $this->tokenFactory->addOperator('Z\Classes\Token\TokenMultiply');
        $this->tokenFactory->addOperator('Z\Classes\Token\TokenDivision');
        $this->tokenFactory->addOperator('Z\Classes\Token\TokenDegree');

        $this->tokenFactory->addFunction('sin', 'sin');
        $this->tokenFactory->addFunction('cos', 'cos');
        //change tn to tan for consistency
        $this->tokenFactory->addFunction('tan', 'tan');
        $this->tokenFactory->addFunction('asin', 'asin');
        $this->tokenFactory->addFunction('acos', 'acos');
        $this->tokenFactory->addFunction('atan', 'atan');
        //added atan2 function
        $this->tokenFactory->addFunction('atant', 'atan2', 2);
        $this->tokenFactory->addFunction('min', 'min', 2);
        $this->tokenFactory->addFunction('max', 'max', 2);
        $this->tokenFactory->addFunction('avg', function($arg1, $arg2) { return ($arg1 + $arg2) / 2; }, 2);

        //for AB_P02
        $this->tokenFactory->addFunction('Fdeg', function($arg1, $arg2, $arg3) {return ($arg1 === abs($arg1)) ? $arg2 : $arg3;} , 3);

        $this->tokenFactory->addFunction('abs', 'abs');

        $this->setVars(array(
            'pi' => 3.14159265359,
            'e'  => 2.71828182846
        ));
    }

    /**
     * Add variable to executor
     *
     * @param  string        $variable
     * @param  integer|float $value
     * @throws \Exception
     * @return MathExecutor
     */
    public function setVar($variable, $value)
    {
        if (!is_numeric($value)) {
            throw new \Exception("Variable value must be a number");
        }<commit_msg>trying to fix pTwo add on function<commit_after><?php

/**
 * This file is part of the MathExecutor package
 *
 * (c) <NAME>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code
 */

namespace Z;

use Z\Classes\Calculator;
use Z\Classes\Lexer;
use Z\Classes\Token;
use Z\Classes\TokenFactory;

/**
 * Class MathExecutor
 * @package Z
 */
class MathExecutor
{
    /**
     * Available variables
     *
     * @var array
     */
    private $variables = array();

    /**
     * @var TokenFactory
     */
    private $tokenFactory;

    /**
     * @var array
     */
    private $cache = array();

    /**
     * Base math operators
     */
    public function __construct()
    {
        $this->addDefaults();
    }

    public function __clone()
    {
        $this->addDefaults();
    }

    /**
     * Set default operands and functions
     */
    protected function addDefaults()
    {
        $this->tokenFactory = new TokenFactory();

        $this->tokenFactory->addOperator('Z\Classes\Token\TokenPlus');
        $this->tokenFactory->addOperator('Z\Classes\Token\TokenMinus');
        $this->tokenFactory->addOperator('Z\Classes\Token\TokenMultiply');
        $this->tokenFactory->addOperator('Z\Classes\Token\TokenDivision');
        $this->tokenFactory->addOperator('Z\Classes\Token\TokenDegree');

        $this->tokenFactory->addFunction('sin', 'sin');
        $this->tokenFactory->addFunction('cos', 'cos');
        //change tn to tan for consistency
        $this->tokenFactory->addFunction('tan', 'tan');
        $this->tokenFactory->addFunction('asin', 'asin');
        $this->tokenFactory->addFunction('acos', 'acos');
        $this->tokenFactory->addFunction('atan', 'atan');
        //added atan2 function
        $this->tokenFactory->addFunction('atant', 'atan2', 2);
        $this->tokenFactory->addFunction('min', 'min', 2);
        $this->tokenFactory->addFunction('max', 'max', 2);
        $this->tokenFactory->addFunction('avg', function($arg1, $arg2) { return ($arg1 + $arg2) / 2; }, 2);

        //for AB_P02
        $this->tokenFactory->addFunction('pTwo', function($arg1, $arg2, $arg3) { return ($arg1 > 0) ? $arg2 : $arg3; } , 3);

        $this->tokenFactory->addFunction('abs', 'abs');

        $this->setVars(array(
            'pi' => 3.14159265359,
            'e'  => 2.71828182846
        ));
    }

    /**
     * Add variable to executor
     *
     * @param  string        $variable
     * @param  integer|float $value
     * @throws \Exception
     * @return MathExecutor
     */
    public function setVar($variable, $value)
    {
        if (!is_numeric($value)) {
            throw new \Exception("Variable value must be a number");
        }
{'fraction_non_alphanumeric': 0.1602540834845735, 'fraction_numerical': 0.016333938294010888, 'mean_word_length': 2.494610019023462, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 86, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1167600', 'n_tokens_mistral': 1708, 'n_tokens_neox': 1627, 'n_words': 354}