public function big_integer_add($num1,$num2){ $str1 = strval($num1); $str2 = strval($num2); $length1 = strlen($str1); $length2 = strlen($str2); $length = $length1>$length2?$length1:$length2; $result = ''; $flag = 0; while($length--){ $m = 0; $n = 0; if($length1>0) $m = $str1[--$length1]; if($length2>0) $n = $str2[--$length2]; $tmp = $m+$n+$flag; $flag = $tmp/10; $result = ($tmp%10).$result; } return doubleval($result);//或者直接返回字符串 }
$a = 9874651230987465123098746512309874651230987465123098746512309874651230987465123098746512309874651230; $b = 9874651230987465123098746512309874651230987465123098746512309874651230987465123098746512309874651230; dump($this->big_integer_add($a,$b)); echo "<br>"; dump($a+$b) ;
点击查看更多内容
1人点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦