Ejemplo n.º 1
0
 /**
  * Create fibonacci sequence
  *
  * The sequence is infinite but the factory method optionally takes a third argument to limit the sequence. A fourth
  * parameter can be passed to specify an offset for the sequence.
  *
  * @param integer $start
  * @param integer $increment
  * @param integer $limit
  * @param integer $offset
  * @return Traversable
  */
 public static function sequence($start = 0, $increment = 1, $limit = 0, $offset = 0)
 {
     $sequence = new FibonacciSequence($start, $increment);
     InvalidArgumentException::assertParameterType(3, 'integer', $limit, 'unsigned');
     InvalidArgumentException::assertParameterType(4, 'integer', $offset, 'unsigned');
     if ($limit > 0) {
         $sequence = new LimitIterator($sequence, $offset, $limit);
     }
     return $sequence;
 }
Ejemplo n.º 2
0
 /**
  * Calculate nth percentile of a list of numbers
  *
  * @param number[] $numbers
  * @param float $percentile
  * @param string $mode
  * @param boolean $sort
  * @return float
  */
 public static function percentile(array $numbers, $percentile, $mode = self::NEAREST_RANK, $sort = true)
 {
     InvalidArgumentException::assertParameterType('2', 'double', $percentile, '0..1');
     if ($sort) {
         sort($numbers);
     }
     switch ($mode) {
         case static::LINEAR_INTERPOLATION:
             $result = static::linearInterpolation($numbers, $percentile);
             break;
         case static::NEAREST_RANK:
         default:
             $result = static::nearestRank($numbers, $percentile);
             break;
     }
     return $result;
 }
Ejemplo n.º 3
0
 /**
  * @param integer $start
  * @param integer $increment
  */
 public function __construct($start, $increment)
 {
     $this->start = InvalidArgumentException::assertParameterType(1, 'integer', $start);
     $this->increment = InvalidArgumentException::assertParameterType(2, 'integer', $increment);
 }