Beispiel #1
0
 /**
  * This method returns the value as a IDouble. Note: Using this method may result in
  * lost of precision.
  *
  * @access public
  * @static
  * @param IRatio\Type $x                                    the object to be converted
  * @return IDouble\Type                                     the value as a IDouble
  */
 public static function toDouble(IRatio\Type $x) : IDouble\Type
 {
     return IRatio\Module::isInteger($x)->unbox() ? IInt32\Module::toDouble($x->numerator()) : IDouble\Module::divide(IInt32\Module::toDouble($x->numerator()), IInt32\Module::toDouble($x->denominator()));
 }
Beispiel #2
0
 /**
  * This method tests the "divide" method.
  *
  * @dataProvider data_divide
  */
 public function test_divide(array $provided, array $expected)
 {
     $p0 = IDouble\Module::divide(IDouble\Type::box($provided[0]), IDouble\Type::box($provided[1]));
     $e0 = $expected[0];
     $this->assertInstanceOf('\\Saber\\Data\\IDouble\\Type', $p0);
     $this->assertSame($e0, $p0->unbox());
 }
Beispiel #3
0
 /**
  * This method returns the average of all items in the list.
  *
  * @access public
  * @static
  * @param ISeq\Type $xs                                     the sequence to be processed
  * @return IDouble\Type                                     the result
  */
 public static function average(ISeq\Type $xs) : IDouble\Type
 {
     return $xs->__isEmpty() ? IDouble\Type::zero() : IDouble\Module::divide(static::sum($xs), $xs->length()->toDouble());
 }