Beispiel #1
0
 /**
  * This method tests the "nvl" method.
  */
 public function test_nvl()
 {
     $x = IDouble\Type::one();
     $y = IDouble\Type::zero();
     $z = IDouble\Module::nvl($x, $y);
     $this->assertInstanceOf('\\Saber\\Data\\IDouble\\Type', $z);
     $this->assertSame(1.0, $z->unbox());
     $z = IDouble\Module::nvl(null, $x);
     $this->assertInstanceOf('\\Saber\\Data\\IDouble\\Type', $z);
     $this->assertSame(1.0, $z->unbox());
     $z = IDouble\Module::nvl(null, null);
     $this->assertInstanceOf('\\Saber\\Data\\IDouble\\Type', $z);
     $this->assertSame(0.0, $z->unbox());
 }
Beispiel #2
0
 /**
  * This method tests the "singletons" methods.
  */
 public function test_singletons()
 {
     $p0 = IDouble\Type::negative();
     $e0 = IDouble\Type::negative();
     $this->assertInstanceOf('\\Saber\\Data\\IDouble\\Type', $p0);
     $this->assertSame($e0->__hashCode(), $p0->__hashCode());
     $p1 = $p0->unbox();
     $e1 = -1.0;
     $this->assertInternalType('float', $p1);
     $this->assertSame($e1, $p1);
     $p2 = IDouble\Type::zero();
     $e2 = IDouble\Type::zero();
     $this->assertInstanceOf('\\Saber\\Data\\IDouble\\Type', $p2);
     $this->assertSame($e2->__hashCode(), $p2->__hashCode());
     $p3 = $p2->unbox();
     $e3 = 0.0;
     $this->assertInternalType('float', $p3);
     $this->assertSame($e3, $p3);
     $p4 = IDouble\Type::one();
     $e4 = IDouble\Type::one();
     $this->assertInstanceOf('\\Saber\\Data\\IDouble\\Type', $p4);
     $this->assertSame($e4->__hashCode(), $p4->__hashCode());
     $p5 = $p4->unbox();
     $e5 = 1.0;
     $this->assertInternalType('float', $p5);
     $this->assertSame($e5, $p5);
 }
Beispiel #3
0
 /**
  * This method returns a list of all numbers for the specified sequence.
  *
  * @access public
  * @static
  * @param IDouble\Type $x                                   where to start
  * @param Core\Type $y                                      either an integer representing
  *                                                          the end of the sequence or a
  *                                                          tuple describing the sequence
  * @return IArrayList\Type                                  an empty array list
  */
 public static function sequence(IDouble\Type $x, Core\Type $y) : IArrayList\Type
 {
     $buffer = array();
     if ($y instanceof ITuple\Type) {
         $s = IDouble\Module::subtract($y->first(), $x);
         $n = $y->second();
     } else {
         // ($y instanceof IDouble\Type)
         $s = IDouble\Type::one();
         $n = $y;
     }
     if (IDouble\Module::isNegative($s)->unbox()) {
         for ($i = $x; IDouble\Module::ge($i, $n)->unbox(); $i = IDouble\Module::add($i, $s)) {
             $buffer[] = $i;
         }
     } else {
         for ($i = $x; IDouble\Module::le($i, $n)->unbox(); $i = IDouble\Module::add($i, $s)) {
             $buffer[] = $i;
         }
     }
     return IArrayList\Type::box($buffer);
 }
Beispiel #4
0
 /**
  * This method returns the product 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 product(ISeq\Type $xs) : IDouble\Type
 {
     return $xs->foldLeft(function (IDouble\Type $c, INumber\Type $x) {
         return IDouble\Module::multiply($c, $x->toDouble());
     }, IDouble\Type::one());
 }