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

Breadcrumb

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

function NativeCalculator::add

Overrides Calculator::add

4 calls to NativeCalculator::add()
NativeCalculator::doDiv in vendor/brick/math/src/Internal/Calculator/NativeCalculator.php
Performs the division of two non-signed large integers.
NativeCalculator::doMul in vendor/brick/math/src/Internal/Calculator/NativeCalculator.php
Performs the multiplication of two non-signed large integers.
NativeCalculator::sqrt in vendor/brick/math/src/Internal/Calculator/NativeCalculator.php
Adapted from https://cp-algorithms.com/num_methods/roots_newton.html
NativeCalculator::sub in vendor/brick/math/src/Internal/Calculator/NativeCalculator.php
Subtracts two numbers.

File

vendor/brick/math/src/Internal/Calculator/NativeCalculator.php, line 40

Class

NativeCalculator
Calculator implementation using only native PHP code.

Namespace

Brick\Math\Internal\Calculator

Code

public function add(string $a, string $b) : string {
    
    /**
     * @psalm-var numeric-string $a
     * @psalm-var numeric-string $b
     */
    $result = $a + $b;
    if (is_int($result)) {
        return (string) $result;
    }
    if ($a === '0') {
        return $b;
    }
    if ($b === '0') {
        return $a;
    }
    [
        $aNeg,
        $bNeg,
        $aDig,
        $bDig,
    ] = $this->init($a, $b);
    $result = $aNeg === $bNeg ? $this->doAdd($aDig, $bDig) : $this->doSub($aDig, $bDig);
    if ($aNeg) {
        $result = $this->neg($result);
    }
    return $result;
}

API Navigation

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