Calculates the sum of values from given expression
@param callable|string|null $sum
@return numeric
497394
public function sum($sum=null)
    {
        $sum = LambdaUtils::toSelectCallable($sum);
        $temp = $this->select($sum)->toArray();
        return array_sum($temp);
    }
877477
public function avg($avg=null)
    {
        $avg = LambdaUtils::toSelectCallable($avg);
        return ($this->sum($avg)/$this->length());
    }
143660
@NullSafe
  public static int sum(final int... numbers) {
    int sum = 0;

    if (numbers != null) {
      for (int number : numbers) {
        sum += number;
      }
    }

    return sum;
  }
499235
public static function toCents($amount)
    {
        /*
         * There's probably a better way, but this is what i could come up with
         * to avoid rounding errors
         * todo: search for a better way
         */

        if (!is_float($amount)) {
            $type = gettype($amount);

            throw new \UnexpectedValueException("Needs a float! not $type");
        }

        //handle locales
        $locale = localeconv();

        $amount = str_replace($locale['mon_thousands_sep'], '', $amount);
        $amount = str_replace($locale['mon_decimal_point'], '.', $amount);
        $amount = str_replace($locale['decimal_point'], '.', $amount);

        $parts = explode('.', "$amount");

        // handle the case where $amount has a .0 fraction part
        if (count($parts) == 1) {
            $parts[] = '00';
        }

        list($whole, $fraction) = $parts;

        /*
         * since the documentation only mentions decimals with a precision of two
         * and doesn't specify any rounding method i'm truncating the number
         *
         * the str_pad is to handle the case where $amount is, for example, 6.9
         */
        $fraction = str_pad(substr($fraction, 0, 2), 2, '0');

        $whole = (int) $whole * 100;
        $fraction = (int) $fraction;

        return $whole + $fraction;
    }
845659
public function sum(callable $callback = null)
    {

        if ($callback === null)
        {
            $callback = function ($time) {

                return $time->getSeconds();
            };

            return $this->createTime(0, 0, parent::sum($callback));
        }

        return parent::sum($callback);
    }
969976
public static function sum($items, $callback = null)
    {
        $callback = static::valueRetriever($callback);
        $sum = null;

        foreach ($items as $item) {
            if (($amount = $callback($item)) !== null) {
                $sum = $sum ? $sum->add($amount) : $amount;
            }
        }

        return $sum ?: static::zero();
    }
1075019
public function sum(string $column): int
    {
        $sum = $this->queryRelate->getQuery()->sum($column);

        $this->resetQueryRelate();

        return $sum;
    }
467187
public static function forSum(callable $num): self {
        return new self(
                function() { return 0; },
                function(&$result, $element) use($num) { $result+= $num($element); }
        );
    }
463775
private function unionAggregate(array $sets, array $weights = null, string $aggregate = 'SUM'): int
    {
        return $this->handle->zUnion($this->name, $sets, $weights, $aggregate);
    }
441849
public static function MROUND($number, $multiple)
    {
        $number   = PHPExcel_Calculation_Functions::flattenSingleValue($number);
        $multiple = PHPExcel_Calculation_Functions::flattenSingleValue($multiple);

        if ((is_numeric($number)) && (is_numeric($multiple))) {
            if ($multiple == 0) {
                return 0;
            }
            if ((self::SIGN($number)) == (self::SIGN($multiple))) {
                $multiplier = 1 / $multiple;
                return round($number * $multiplier) / $multiplier;
            }
            return PHPExcel_Calculation_Functions::NaN();
        }
        return PHPExcel_Calculation_Functions::VALUE();
    }
109581
public function byAmount( $nAmount ) {
		$oTheOne = null;
		foreach ( $this as $oBankTxn ) {
			if ( (string)$oBankTxn->amount == (string)$nAmount ) {
				$oTheOne = $oBankTxn;
				break;
			}
		}
		return $oTheOne;
	}
902122
public function sum($callback = null)
    {
        if (\is_null($callback)) {
            return array_sum($this->items);
        }

        $callback = $this->valueRetriever($callback);

        return $this->reduce(function ($result, $item) use ($callback) {
            return $result + $callback($item);
        }, 0);
    }
954919
public function sum($callback = null): float
    {
        return $this->reduce(function ($carry, $value, $key) use ($callback) {
            $value = $callback === null ? $value : $this->accessKey($value, $callback, $key);
            return $carry + $value;
        }, 0);
    }
476520
public function sum($column, $criteria = null)
    {
        // convert to criteria.
        $criteria = call_user_func_array(array($this, 'argsToCriteria'), [$criteria]);

        $criteria->columns(sprintf('sum(%s) as s', $column));
        
        // logical delete ?
        $schema = $this->getSchema();
        if ($schema->hasColumn('active')) {
            $criteria->where('active = ?', 1);
        }

        // to SQL.
        $sql = $criteria->toSQL();

        // query
        $sum = $this->getOne($sql, $criteria->getParams());
        return $sum ?: 0;
    }
566493
public function val($index = 0) {

		if(false === ('-' . intval($index) == '-' . $index)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($index)), E_USER_ERROR);
		}

		$val = $this -> strip();

		if(true === isset($val[$index])) {
			return $val[$index];
		}

		return null;
	}
492746
protected function crossSum($int)
    {
        $sum     = 0;
        $str_int = (string) $int;
        for ($i = 0; $i < strlen($str_int); $i++) {
            //$sum = bcadd($str_int{$i}, $sum);
            $sum += $str_int{$i};

        }
        return $sum;
    }
1129676
public function getSumFromFlexibee($conditions = [])
    {
        $flexiData = $this->getFlexiData('$sum', $conditions);
        return empty($flexiData) ? null : $flexiData['sum'];
    }