Exemplo n.º 1
0
 /**
  * Calculates the dot product between this vector and the given vector.
  *
  * @param Vector $vector The vector to calculate thet dot product with.
  * @return float
  */
 public function dotProduct(Vector $vector)
 {
     if ($this->getSize() !== $vector->getSize()) {
         throw new InvalidArgumentException('Invalid vector provided. The size should be the same.');
     }
     $result = new BigNumber();
     $vectorSize = $this->getSize();
     for ($i = 0; $i < $vectorSize; ++$i) {
         $value = new BigNumber($this[$i]);
         $value->multiply($vector[$i]);
         $result->add($value);
     }
     return $result;
 }
Exemplo n.º 2
0
 /**
  * Multiplies the two given numbers.
  *
  * @param BigNumber $lft The left number.
  * @param BigNumber $rgt The right number.
  * @param int $scale The scale of the calculated number.
  * @param bool $mutable Whether or not the result is mutable.
  * @return BigNumber
  */
 public static function multiply(BigNumber $lft, BigNumber $rgt, $scale = 10, $mutable = true)
 {
     $bigNumber = new BigNumber($lft, $scale, $mutable);
     return $bigNumber->multiply($rgt);
 }
Exemplo n.º 3
0
 public function testWithMutableTrue()
 {
     // Arrange
     $bigNumber = new BigNumber('5', 10, true);
     // Act
     $newBigNumber = $bigNumber->multiply(10);
     // Assert
     $this->assertInstanceOf('PHP\\Math\\BigNumber\\BigNumber', $bigNumber);
     $this->assertInstanceOf('PHP\\Math\\BigNumber\\BigNumber', $newBigNumber);
     $this->assertEquals('50', $bigNumber->getValue());
     $this->assertEquals('50', $newBigNumber->getValue());
 }