PHP calculate integer set of extra large numbers

php中世界最好的语言
Release: 2023-03-25 21:00:02
Original
2071 people have browsed it

This time I will bring you a integerset for calculating extra-large numbers in PHP. What are the notes for calculating extra-large integers in PHP? Here is a practical case. Let’s take a look. .

No more nonsense, the specific code is as follows:

function getIntAdd($a,$b){
$c = '';
$bCount = strlen($b);
$aCount = strlen($a);
$count = max($bCount,$aCount);
$aDiff = $count - $aCount;
$bDiff = $count - $bCount;
for($i = $count - 1;$i >= 0;$i--){
$aVal = $count - $i <= $aCount ? intval($a[$i - $aDiff]) : 0;
$bVal = $count - $i <= $bCount ? intval($b[$i - $bDiff]) : 0;
$v = $aVal + $bVal;
if(strlen($c) > 0 && strlen($c) >= $count - $i){
$c = ($v + intval($c[0])).substr($c,1,strlen($c) - 1);
}else{
$c = $v.$c.&#39;&#39;;
}
}
return $c;
}
$a = &#39;23490234328490289048902384908392849238&#39;;
$b = &#39;234320498324982390489328498230984982399290384902384&#39;;
$c = getIntAdd($a,$b);
print_r($c);
Copy after login

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

php Shared Memory Usage and Signal Control Use Case Analysis

In the WeChat applet product details page How to add popup box

The above is the detailed content of PHP calculate integer set of extra large numbers. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template