computes the ratio of a value to the sum of a set of values. If expr evaluates to null,
then the ratio-to-report value also evaluates to null.

@return ratio_to_report(expr)
767313
public static <T> WindowOver<T> ratioToReport(Expression<T> expr) {
        return new WindowOver<T>(expr.getType(), SQLOps.RATIOTOREPORT, expr);
    }
70451
public double normalize() {
        double propSum = this.getSum();
        if (propSum == s.zero()) {
            this.fill(s.divide(s.one(), s.fromReal(this.size())));
        } else if (propSum == s.posInf()) {
            int count = count(s.posInf());
            if (count == 0) {
                throw new RuntimeException("Unable to normalize since sum is infinite but contains no infinities: " + this.toString());
            }
            double constant = s.divide(s.one(), s.fromReal(count));
            for (int d=0; d<this.size(); d++) {
                if (this.getValue(d) == s.posInf()) {
                    this.setValue(d, constant);
                } else {
                    this.setValue(d, s.zero());
                }
            }
        } else {
            this.divide(propSum);
            assert !this.containsNaN();
        }
        return propSum;
    }
1350571
public function aggregate($expr)
    {
        foreach ($expr as $k => $v) {
            if (is_array($v)) {
                if (isset($v['$count_if'])) {
                    unset($v['$count_if'][0]);
                    $v = ['$sum' => ['$cond' => [$v['$count_if'], 1, 0]]];
                } elseif (isset($v['$sum_if'])) {
                    $field = isset($v['$sum_if'][0]) ? $v['$sum_if'][0] : 1;
                    unset($v['$sum_if'][0]);
                    $v = ['$sum' => ['$cond' => [$v['$sum_if'], is_numeric($field) ? (float)$field : '$' . $field, 0]]];
                } elseif (isset($v['$avg_if'])) {
                    $field = isset($v['$avg_if'][0]) ? $v['$avg_if'][0] : 1;
                    unset($v['$avg_if'][0]);
                    $v = ['$avg' => ['$cond' => [$v['$avg_if'], is_numeric($field) ? (float)$field : '$' . $field, 0]]];
                }
                $this->_aggregate[$k] = $v;
                continue;
            }

            if (preg_match('#^(\w+)\((.*)\)$#', $v, $match) !== 1) {
                throw new MisuseException(['`:aggregate` aggregate is invalid.', 'aggregate' => $v]);
            }

            $accumulator = strtolower($match[1]);
            $normalizes = ['group_concat' => 'push',
                'std' => 'stdDevPop',
                'stddev' => 'stdDevPop',
                'stddev_pop' => 'stdDevPop',
                'stddev_samp' => 'stdDevSamp',
                'addtoset' => 'addToSet',
                'stddevpop' => 'stdDevPop',
                'stddevsamp' => 'stdDevSamp'];
            if (isset($normalizes[$accumulator])) {
                $accumulator = $normalizes[$accumulator];
            }
            $operand = $match[2];
            if ($accumulator === 'count') {
                $this->_aggregate[$k] = ['$sum' => 1];
            } elseif ($accumulator === 'count_if') {
                if ($cond = $this->_compileCondExpression($operand)) {
                    $this->_aggregate[$k] = ['$sum' => $cond];
                } else {
                    throw new MisuseException(['unknown COUNT_IF expression: `:expression`', 'expression' => $operand]);
                }
            } elseif ($accumulator === 'sum_if') {
                if ($cond = $this->_compileCondExpression($operand)) {
                    $this->_aggregate[$k] = ['$sum' => $cond];
                } else {
                    throw new MisuseException(['unknown SUM_IF expression: `:expression`', 'expression' => $operand]);
                }
            } elseif ($accumulator === 'avg_if') {
                if ($cond = $this->_compileCondExpression($operand)) {
                    $this->_aggregate[$k] = ['$avg' => $cond];
                } else {
                    throw new MisuseException(['unknown AVG_IF expression: `:expression`', 'expression' => $operand]);
                }
            } elseif (in_array($accumulator, ['avg', 'first', 'last', 'max', 'min', 'push', 'addToSet', 'stdDevPop', 'stdDevSamp', 'sum'], true)) {
                if (preg_match('#^[\w\.]+$#', $operand) === 1) {
                    $this->_aggregate[$k] = ['$' . $accumulator => '$' . $operand];
                } elseif (preg_match('#^([\w\.]+)\s*([\+\-\*/%])\s*([\w\.]+)$#', $operand, $match2) === 1) {
                    $operator_map = ['+' => '$add', '-' => '$subtract', '*' => '$multiply', '/' => '$divide', '%' => '$mod'];
                    $sub_operand = $operator_map[$match2[2]];
                    $sub_operand1 = is_numeric($match2[1]) ? (float)$match2[1] : ('$' . $match2[1]);
                    $sub_operand2 = is_numeric($match2[3]) ? (float)$match2[3] : ('$' . $match2[3]);
                    $this->_aggregate[$k] = ['$' . $accumulator => [$sub_operand => [$sub_operand1, $sub_operand2]]];
                } elseif ($cond = $this->_compileCondExpression($operand)) {
                    $this->_aggregate[$k] = ['$' . $accumulator => $this->_compileCondExpression($operand)];
                } else {
                    throw new MisuseException(['unknown `:operand` operand of `:aggregate` aggregate', 'operand' => $operand, 'aggregate' => $v]);
                }
            } else {
                throw new MisuseException([
                    'unknown `:accumulator` accumulator of `:aggregate` aggregate',
                    'accumulator' => $accumulator,
                    'aggregate' => $v
                ]);
            }
        }

        return $this->execute();
    }
223364
private function realquickRatio()
    {
        $aLength = count($this->a);
        $bLength = count($this->b);

        return $this->calculateRatio(min($aLength, $bLength), $aLength + $bLength);
    }
1114078
public function total()
    {
        $total = array_reduce($this->examples, function($x, $e) {
            $x += $e instanceof Example ? 1 : $e->total();
            return $x;
        }, 0);

        return $total;
    }
707508
public static double ratioSmallestOverLargest( double []sv ) {
        if( sv.length == 0 )
            return Double.NaN;

        double min = sv[0];
        double max = min;

        for (int i = 1; i < sv.length; i++) {
            double v = sv[i];
            if( v > max )
                max = v;
            else if( v < min )
                min = v;
        }

        return  min/max;
    }
1343563
private function calculate()
    {
        if (count($this->points) < 2) {
            throw new \RuntimeException('There must be two or more points (co-ordinates) before a calculation can be performed.');
        }
        $total = 0;
        foreach ($this->points as $point) {
            if (isset($previous)) {
                $total += $this->distanceBetweenPoints($previous, $point);
            }
            $previous = $point;
        }
        return $total;
    }
454624
public static double average(List<? extends Number> values) {
        if (values == null || values.isEmpty()) return 0D;

        double sum = 0D;
        for (Number v : values) sum += v.doubleValue();

        return sum / values.size();
    }
892240
public static function NPV()
    {
        // Return value
        $returnValue = 0;

        // Loop through arguments
        $aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());

        // Calculate
        $rate = array_shift($aArgs);
        for ($i = 1; $i <= count($aArgs); ++$i) {
            // Is it a numeric value?
            if (is_numeric($aArgs[$i - 1])) {
                $returnValue += $aArgs[$i - 1] / pow(1 + $rate, $i);
            }
        }

        // Return
        return $returnValue;
    }
657167
@Override
    public double doubleValueExact() {
        double d = this.number.doubleValue();
        if (d == Double.NEGATIVE_INFINITY || d == Double.POSITIVE_INFINITY) {
            throw new ArithmeticException("Unable to convert to double: "
                    + this.number);
        }
        return d;
    }
426768
public function expr() : Expr
    {
        $expr = new Expr($this->dm);
        $expr->setClassMetadata($this->class);

        return $expr;
    }
541443
@Override
    public double getMean() {
        if (values.length == 0) {
            return 0;
        }

        double sum = 0;
        for (int i = 0; i < values.length; i++) {
            sum += values[i] * normWeights[i];
        }
        return sum;
    }
640927
@Override
	public Expression getValueExpression() {
		return ifThenElse(equalTo(count, literal(0L)), nullOf(getResultType()), div(sum, count));
	}
897877
public static function SUBTOTAL() {
		$aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());

		// Calculate
		$subtotal = array_shift($aArgs);

		if ((is_numeric($subtotal)) && (!is_string($subtotal))) {
			switch($subtotal) {
				case 1	:
					return PHPExcel_Calculation_Statistical::AVERAGE($aArgs);
					break;
				case 2	:
					return PHPExcel_Calculation_Statistical::COUNT($aArgs);
					break;
				case 3	:
					return PHPExcel_Calculation_Statistical::COUNTA($aArgs);
					break;
				case 4	:
					return PHPExcel_Calculation_Statistical::MAX($aArgs);
					break;
				case 5	:
					return PHPExcel_Calculation_Statistical::MIN($aArgs);
					break;
				case 6	:
					return self::PRODUCT($aArgs);
					break;
				case 7	:
					return PHPExcel_Calculation_Statistical::STDEV($aArgs);
					break;
				case 8	:
					return PHPExcel_Calculation_Statistical::STDEVP($aArgs);
					break;
				case 9	:
					return self::SUM($aArgs);
					break;
				case 10	:
					return PHPExcel_Calculation_Statistical::VARFunc($aArgs);
					break;
				case 11	:
					return PHPExcel_Calculation_Statistical::VARP($aArgs);
					break;
			}
		}
		return PHPExcel_Calculation_Functions::VALUE();
	}
750962
public function allocateByRatios(array $ratios)
    {
        /** @var Money[] $result */
        $result = array();
        $total = array_sum($ratios);
        $remainder = $this->amount;

        for ($i = 0; $i < count($ratios); $i++) {
            $amount = $this->castToFloat($this->amount * $ratios[$i] / $total);
            $result[] = $this->newMoney($amount);
            $remainder -= $amount;
        }

        for ($i = 0; $i < $remainder; $i++) {
            $result[$i] = $this->newMoney($result[$i]->getAmount() + 1);
        }

        return $result;
    }
642541
public double normalize() {
        double propSum = this.getSum();
        if (propSum == s.zero()) {
            this.fill(s.divide(s.one(), s.fromReal(values.length)));
        } else if (propSum == s.posInf()) {
            int count = DoubleArrays.count(values, s.posInf());
            if (count == 0) {
                throw new RuntimeException("Unable to normalize since sum is infinite but contains no infinities: " + Arrays.toString(values));
            }
            double constant = s.divide(s.one(), s.fromReal(count));
            for (int d=0; d<values.length; d++) {
                if (values[d] == s.posInf()) {
                    values[d] = constant;
                } else {
                    values[d] = s.zero();
                }
            }
        } else {
            this.divide(propSum);
            assert !this.containsNaN();
        }
        return propSum;
    }
539595
public static function IMSUM() {
		// Return value
		$returnValue = self::_parseComplex('0');
		$activeSuffix = '';

		// Loop through the arguments
		$aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
		foreach ($aArgs as $arg) {
			$parsedComplex = self::_parseComplex($arg);

			if ($activeSuffix == '') {
				$activeSuffix = $parsedComplex['suffix'];
			} elseif (($parsedComplex['suffix'] != '') && ($activeSuffix != $parsedComplex['suffix'])) {
				return PHPExcel_Calculation_Functions::VALUE();
			}

			$returnValue['real'] += $parsedComplex['real'];
			$returnValue['imaginary'] += $parsedComplex['imaginary'];
		}

		if ($returnValue['imaginary'] == 0.0) { $activeSuffix = ''; }
		return self::COMPLEX($returnValue['real'],$returnValue['imaginary'],$activeSuffix);
	}