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

Breadcrumb

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

function Calculator::cmp

Compares two numbers.

@psalm-return -1|0|1

Return value

int -1 if the first number is less than, 0 if equal to, 1 if greater than the second number.

3 calls to Calculator::cmp()
Calculator::divRound in vendor/brick/math/src/Internal/Calculator.php
Performs a rounded division.
Calculator::modInverse in vendor/brick/math/src/Internal/Calculator.php
Returns the modular multiplicative inverse of $x modulo $m.
NativeCalculator::sqrt in vendor/brick/math/src/Internal/Calculator/NativeCalculator.php
Adapted from https://cp-algorithms.com/num_methods/roots_newton.html

File

vendor/brick/math/src/Internal/Calculator.php, line 135

Class

Calculator
Performs basic operations on arbitrary size integers.

Namespace

Brick\Math\Internal

Code

public final function cmp(string $a, string $b) : int {
    [
        $aNeg,
        $bNeg,
        $aDig,
        $bDig,
    ] = $this->init($a, $b);
    if ($aNeg && !$bNeg) {
        return -1;
    }
    if ($bNeg && !$aNeg) {
        return 1;
    }
    $aLen = \strlen($aDig);
    $bLen = \strlen($bDig);
    if ($aLen < $bLen) {
        $result = -1;
    }
    elseif ($aLen > $bLen) {
        $result = 1;
    }
    else {
        $result = $aDig <=> $bDig;
    }
    return $aNeg ? -$result : $result;
}

API Navigation

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