Litipk\BigNumbers\Decimal::comp PHP Method

comp() public method

$this > $b : returns 1 , $this < $b : returns -1 , $this == $b : returns 0
public comp ( Decimal $b, integer $scale = null ) : integer
$b Decimal
$scale integer
return integer
    public function comp(Decimal $b, $scale = null)
    {
        self::paramsValidation($b, $scale);
        if ($this === $b) {
            return 0;
        } elseif ($b->isInfinite()) {
            return -$b->comp($this);
        }
        $cmp_scale = $scale !== null ? $scale : max($this->scale, $b->scale);
        return bccomp(self::innerRound($this->value, $cmp_scale), self::innerRound($b->value, $cmp_scale), $cmp_scale);
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Counts the number of significative digits of $val.
  * Assumes a consistent internal state (without zeros at the end or the start).
  *
  * @param  Decimal $val
  * @param  Decimal $abs $val->abs()
  * @return integer
  */
 private static function countSignificativeDigits(Decimal $val, Decimal $abs)
 {
     return strlen($val->value) - ($abs->comp(DecimalConstants::One()) === -1 ? 2 : max($val->scale, 1)) - ($val->isNegative() ? 1 : 0);
 }
All Usage Examples Of Litipk\BigNumbers\Decimal::comp