Example #1
0
 /**
  * Returns the (min, max) of the two scales or zero
  *
  * @param N $l
  * @param N $r
  *
  * @return array [min, max]
  */
 public static function getScales(N $l, N $r)
 {
     $scales = [];
     if ($l instanceof FloatNumber) {
         $scales[] = $l->getScale();
     }
     if ($r instanceof FloatNumber) {
         $scales[] = $r->getScale();
     }
     if (count($scales) == 1) {
         $scales[] = $scales[0];
     }
     return [min($scales), max($scales)];
 }
Example #2
0
 public function __construct($value)
 {
     parent::__construct($value);
 }
Example #3
0
 /**
  * @test
  * @dataProvider numbers
  */
 public function to_string_numbers(N $i, $expected)
 {
     $this->assertSame($expected, $i->__toString());
 }
Example #4
0
 /**
  * Check if this number is less than the given value
  *
  * @param N $other
  *
  * @return mixed
  */
 protected function _lt(N $other)
 {
     return $this->getValue() < intval($other->getValue());
 }
Example #5
0
 /**
  * Sub two Numbers
  * $l - $r
  *
  * @param VONumber $l
  * @param VONumber $r
  *
  * @return VONumber
  */
 public function sub(VONumber $l, VONumber $r)
 {
     if ($l instanceof IntegerNumber && $r instanceof IntegerNumber) {
         return new IntegerNumber(bcsub($l->__toString(), $r->__toString()));
     } else {
         $scale = FloatNumber::getScales($l, $r);
         $res = new FloatNumber(bcsub($l->__toString(), $r->__toString(), $scale[1]), $scale[0]);
         return $res;
     }
 }