Apply operation between value and operand by using operator

@param double $value    Value to convert
@param string $operator Operator to apply
@param double $operand  Operand to use

@return double
553208
protected function applyOperation($value, $operator, $operand)
    {
        $processedValue = $value;

        switch ($operator) {
            case "div":
                if ($operand !== 0) {
                    $processedValue = $processedValue / $operand;
                }
                break;
            case "mul":
                $processedValue = $processedValue * $operand;
                break;
            case "add":
                $processedValue = $processedValue + $operand;
                break;
            case "sub":
                $processedValue = $processedValue - $operand;
                break;
            default:
                throw new UnknownOperatorException();
        }

        return $processedValue;
    }
302547
private function compareLong($value1, $value2, $operator)
    {
        switch ($operator) {
            case FieldExpression::EQUALS:
                return $value1 === $value2;

            case FieldExpression::NOT_EQUALS:
                return $value1 !== $value2;

            case FieldExpression::GT:
                return $value1 > $value2;

            case FieldExpression::LT:
                return $value1 < $value2;
        }

        $errMsg = 'unknown field operator';
        throw new InvalidArgumentException($errMsg);
    }
464089
public function where($column, $operator, $value = null)
    {
        $instance = $this->whereStrategyInstance();

        $instance->whereStrategy()->where(...func_get_args());

        return $instance;
    }
1320058
protected function invalidOperatorAndValue($operator, $value)
    {
        $isOperator = in_array($operator, $this->operators);

        return is_null($value) && $isOperator && ! in_array($operator, ['=', '<>', '!=']);
    }
764153
public function process()
    {
        $operands = $this->getOperands();

        if ($operands->containsNull() === true) {
            return null;
        }

        if ($operands->anythingButRecord() === false) {
            $msg = "The Max operator only accept values with a cardinality of single, multiple or ordered.";
            throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
        }

        if ($operands->exclusivelyNumeric() === false) {
            // As per QTI 2.1 spec, If any of the sub-expressions is not a numerical value, then the result is NULL.
            return null;
        }

        // As per QTI 2.1 spec,
        // The result is a single float, or, if all sub-expressions are of
        // integer type, a single integer.
        $integerCount = 0;
        $valueCount = 0;
        $max = -PHP_INT_MAX;
        foreach ($operands as $operand) {
            if (!$operand instanceof Container) {
                $baseType = ($operand instanceof QtiFloat) ? BaseType::FLOAT : BaseType::INTEGER;
                $value = new MultipleContainer($baseType, array($operand));
            } else {
                $value = $operand;
            }

            foreach ($value as $v) {

                if (is_null($v)) {
                    return null;
                }

                $valueCount++;
                $integerCount += ($v instanceof QtiInteger) ? 1 : 0;

                if ($v->getValue() > $max) {
                    $max = $v->getValue();
                }
            }
        }

        return ($integerCount === $valueCount) ? new QtiInteger(intval($max)) : new QtiFloat(floatval($max));
    }
585773
public static function doUnaryOperation($operator, &$value)
    {
        if (self::$unaryOperations === null) {
            self::$unaryOperations = [
                    self::BITWISE_NOT   => function (&$i) { return ~$i; },
                    self::NOT           => function (&$i) { return !$i; },
                    self::INCREMENT     => function (&$i) { return $i++; },
                    self::DECREMENT     => function (&$i) { return $i--; },
                    self::PRE_INCREMENT => function (&$i) { return ++$i; },
                    self::PRE_DECREMENT => function (&$i) { return --$i; },
                    self::NEGATION      => function (&$i) { return -$i; },
                    self::PLUS          => function (&$i) { return +$i; },
            ];
        }

        if (!isset(self::$unaryOperations[$operator])) {
            throw new PinqException('Unary operator \'%s\' is not supported', $operator);
        }

        $operation = self::$unaryOperations[$operator];

        return $operation($value);
    }
265365
public function process()
    {
        $operands = $this->getOperands();

        if ($operands->containsNull() === true) {
            return null;
        }

        if ($operands->exclusivelySingle() === false) {
            $msg = "The Round operator only accepts operands with a single cardinality.";
            throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
        }

        if ($operands->exclusivelyNumeric() === false) {
            $msg = "The Round operator only accepts operands with baseType integer or float.";
            throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
        }

        $operand = $operands[0];
        $mode = ($operand->getValue() >= 0) ? PHP_ROUND_HALF_UP : PHP_ROUND_HALF_DOWN;

        return new QtiInteger(intval(round($operand->getValue(), 0, $mode)));
    }
261196
public static function expr($field, $operator = null, $value = null) {
        return new Expr($field, $operator, $value);
    }
964783
public function process()
    {
        $operands = $this->getOperands();

        if ($operands->containsNull() === true) {
            return null;
        }

        if ($operands->exclusivelySingle() === false) {
            $msg = "The Truncate operator only accepts operands with a single cardinality.";
            throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
        }

        if ($operands->exclusivelyNumeric() === false) {
            $msg = "The Truncate operator only accepts operands with an integer or float baseType.";
            throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
        }

        $operand = $operands[0];

        if (is_nan($operand->getValue())) {
            return null;
        } elseif (is_infinite($operand->getValue())) {
            return new QtiFloat(INF);
        } else {
            return new QtiInteger(intval($operand->getValue()));
        }
    }
1131065
public function where($operand, $operatorOrValue=null, $value=null)
    {
        return $this->addWhere($operand, $operatorOrValue, $value, 'and', func_num_args());
    }
749964
public function where($field, $operator, $value = null)
    {
        if (is_null($value)) {
            $value    = $operator;
            $operator = '=';
        }

        return $this->filter(function ($data) use ($field, $operator, $value) {
            if (strpos($field, '.')) {
                list($field, $relation) = explode('.', $field);

                $result = isset($data[$field][$relation]) ? $data[$field][$relation] : null;
            } else {
                $result = isset($data[$field]) ? $data[$field] : null;
            }

            switch ($operator) {
                case '===':
                    return $result === $value;
                case '!==':
                    return $result !== $value;
                case '!=':
                case '<>':
                    return $result != $value;
                case '>':
                    return $result > $value;
                case '>=':
                    return $result >= $value;
                case '<':
                    return $result < $value;
                case '<=':
                    return $result <= $value;
                case 'like':
                    return is_string($result) && false !== strpos($result, $value);
                case 'not like':
                    return is_string($result) && false === strpos($result, $value);
                case 'in':
                    return is_scalar($result) && in_array($result, $value, true);
                case 'not in':
                    return is_scalar($result) && !in_array($result, $value, true);
                case 'between':
                    list($min, $max) = is_string($value) ? explode(',', $value) : $value;
                    return is_scalar($result) && $result >= $min && $result <= $max;
                case 'not between':
                    list($min, $max) = is_string($value) ? explode(',', $value) : $value;
                    return is_scalar($result) && $result > $max || $result < $min;
                case '==':
                case '=':
                default:
                    return $result == $value;
            }
        });
    }
1201682
private double doubleValue( double left, double right ) {
        switch( operator ) {
            case '+':
                return left + right;
            case '-':
                return left - right;
            case '*':
                return left * right;
            case '/':
                return left / right;
            default:
                throw createException( "Not supported Oprator '" + operator + "' for Expression '" + toString() + '\'' );
        }
    }
520064
private function validateLogicalOperator($value) 
    {
        $operator = strtoupper(trim($value));
        $isValid = in_array($operator, $this->logicalOperators);
        
        if($isValid === true) {
            return $operator;
        } 
        
        throw new \Exception("Logical operator $value is not supported.");
    }
480257
public function update($operator, Expression $operand)
    {
        if ($this->operator === $operator && $this->operand === $operand) {
            return $this;
        }

        return new self($operator, $operand);
    }
494323
protected static function parseOperatorAndValue($value, $is_negation)
    {
        if ($result = static::parseComparisonOperator($value, $is_negation)) {
            return $result;
        }

        if ($result = static::parseLikeOperator($value, $is_negation)) {
            return $result;
        }

        if ($result = static::parseNullOperator($value, $is_negation)) {
            return $result;
        }

        if ($result = static::parseEqualsInOperator($value, $is_negation)) {
            return $result;
        }

        throw new InvalidArgumentException(sprintf('Unable to parse operator or value from "%s"', $value));
    }
645929
protected final CALC operator(Class<? extends Operator> operator, Object value) {
        Num tmp = null;
        if (value instanceof Num)
            tmp = (Num)value;
        else
            tmp = new Num(value);
        
        infix.add(CacheExtension.getOperator(operator));
        infix.add(tmp);
        return getThis();
    }
5784
public static function Comparison ($value, $operator, $operand, $options) {
		$converter = static::GetConverter($options['type'] ?? null);
		if (is_callable($converter)) {
			$value		= $converter($value);
			$operand	= $converter($operand);
		}

 		if (is_object($value) && is_callable($value)) {
 			$value = $value($operator, $operand, $options);
 		}

 		if (is_object($operand) && is_callable($operand)) {
 			$operand = $operand($operator, $operand, $options);
 		}

		if (($empty_skip_type = $options['have_to_skip'] ?? false) !== false) {
			if (static::TwoValueEmptyChecker($value, $operand, $empty_skip_type, $options['empty_filter'] ?? null)) {
				return true;
			}
		}

		switch ($operator) {
			case static::OP_LT:
				return $value < $operand;
			case static::OP_LT_EQ:
				return $value <= $operand;
			case static::OP_GT:
				return $value > $operand;
			case static::OP_GT_EQ:
				return $value >= $operand;
			case static::OP_EQ:
				return $value == $operand;
			case static::OP_NOT_EQ:
				return $value != $operand;
			case static::OP_S_EQ:
				return $value === $operand;
			case static::OP_S_NOT_EQ:
				return $value !== $operand;
			case static::OP_IN:
				return in_array($value, Arrays::AdjustArray($operand), true);
			case static::OP_ANY:
				$ret = array_intersect(Arrays::AdjustArray($value), Arrays::AdjustArray($operand));
				return !empty($ret);
			case static::OP_NOT_IN:
				return !in_array($value, Arrays::AdjustArray($operand), true);
			case static::OP_KEY_EXISTS:
			case static::OP_KEY:
				return isset($operand[$value]) || array_key_exists($value, $operand);
			case static::OP_ANY_KEY_EXISTS:
				foreach ((array) $operand as $needle) {
					if (isset($value[$needle]) || array_key_exists($needle, $value)) {
						return true;
					}
				}
				return false;
			case static::OP_NOT_ANY_KEY_EXISTS:
				$count = 0;
				foreach ((array) $operand as $needle) {
					if (isset($value[$needle]) || array_key_exists($needle, $value)) {
						if (++$count > 1) {
							return false;
						}
					}
				}
				return true;
			default:
				return false;
		}
	}