@@ -272,7 +272,7 @@ public function add(Decimal $b, $scale = null)
272
272
if ($ this ->isInfinite ()) {
273
273
if (!$ b ->isInfinite ()) {
274
274
return $ this ;
275
- } elseif ($ this ->isPositive () && $ b -> isPositive () || $ this -> isNegative () && $ b -> isNegative ( )) {
275
+ } elseif ($ this ->hasSameSign ( $ b )) {
276
276
return $ this ;
277
277
} else { // elseif ($this->isPositive() && $b->isNegative || $this->isNegative() && $b->isPositive()) {
278
278
throw new \DomainException ("Infinite numbers with opposite signs can't be added " );
@@ -325,12 +325,14 @@ public function mul(Decimal $b, $scale = null)
325
325
{
326
326
self ::paramsValidation ($ b , $ scale );
327
327
328
- if ($ this ->isZero () && $ b ->isInfinite () || $ this ->isInfinite () && $ b ->isZero ()) {
328
+ if ($ this ->isInfinite () || $ b ->isZero ()) {
329
+ return $ b ->mul ($ this );
330
+ } elseif ($ this ->isZero () && $ b ->isInfinite ()) {
329
331
throw new \DomainException ("Zero multiplied by infinite is not allowed. " );
330
- } elseif ($ this ->isZero () && !$ b ->isInfinite () || ! $ this -> isInfinite () && $ b -> isZero () ) {
332
+ } elseif ($ this ->isZero () && !$ b ->isInfinite ()) {
331
333
return Decimal::fromInteger (0 , $ scale );
332
- } elseif ($ this -> isInfinite () || $ b ->isInfinite ()) {
333
- if ($ this ->isPositive () && $ b -> isPositive () || $ this -> isNegative () && $ b -> isNegative ( )) {
334
+ } elseif ($ b ->isInfinite ()) {
335
+ if ($ this ->hasSameSign ( $ b )) {
334
336
return self ::getPositiveInfinite ();
335
337
} else { // elseif ($this->isPositive() && $b->isNegative() || $this->isNegative() && $b->isPositive()) {
336
338
return self ::getNegativeInfinite ();
@@ -655,6 +657,10 @@ public function abs()
655
657
return $ this ->additiveInverse ();
656
658
}
657
659
660
+ public function hasSameSign (Decimal $ b ) {
661
+ return $ this ->isPositive () && $ b ->isPositive () || $ this ->isNegative () && $ b ->isNegative ();
662
+ }
663
+
658
664
/**
659
665
* "Rounds" the decimal string to have at most $scale digits after the point
660
666
*
0 commit comments