Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. BigNumber.php

function BigNumber::add

Adds two BigNumber instances in the correct order to avoid a RoundingNecessaryException.

@todo This could be better resolved by creating an abstract protected method in BigNumber, and leaving to concrete classes the responsibility to perform the addition themselves or delegate it to the given number, depending on their ability to perform the operation. This will also require a version bump because we're potentially breaking custom BigNumber implementations (if any...)

@psalm-pure

1 call to BigNumber::add()
BigNumber::sum in vendor/brick/math/src/BigNumber.php
Returns the sum of the given values.

File

vendor/brick/math/src/BigNumber.php, line 304

Class

BigNumber
Common interface for arbitrary-precision rational numbers.

Namespace

Brick\Math

Code

private static function add(BigNumber $a, BigNumber $b) : BigNumber {
    if ($a instanceof BigRational) {
        return $a->plus($b);
    }
    if ($b instanceof BigRational) {
        return $b->plus($a);
    }
    if ($a instanceof BigDecimal) {
        return $a->plus($b);
    }
    if ($b instanceof BigDecimal) {
        return $b->plus($a);
    }
    
    /** @var BigInteger $a */
    return $a->plus($b);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal