Heim > Artikel > Backend-Entwicklung > PHP int 超大溢出整数的 加减运算函数,如果有更好的方法欢迎探讨
【分享】PHP int 超大溢出整数的 加减运算函数,如果有更好的方法欢迎探讨
分享一个溢出整数加减的运算函数,刚刚写的,对于溢出的整数可以用这个来进行加减运算。
遗憾的几点是:
<br /> 一代码太多;<br /> 二只有加减运算,乘除取余都没有;<br />
<br /> mysql> SELECT 11234123413241341234123412341234+1;<br /> +------------------------------------+<br /> | 11234123413241341234123412341234+1 |<br /> +------------------------------------+<br /> | 11234123413241341234123412341235 |<br /> +------------------------------------+<br /> 1 row in set (0.00 sec)<br /> <br /> <br /> mysql> SELECT 11234123413241341234123412341234*12341234123;<br /> +----------------------------------------------+<br /> | 11234123413241341234123412341234*12341234123 |<br /> +----------------------------------------------+<br /> | 138642947209487270472850788378836360727782 |<br /> +----------------------------------------------+<br /> 1 row in set (0.00 sec)<br /> <br /> <br />
<br> /* big int operate [by fuzb 20130826] */<br> function bigintO($num1,$op,$num2)<br> {<br> $arr = array();<br> $endop = '';<br> $num1o = $num1;<br> $num2o = $num2;<br> if($num1 {<br> $c1 = -1;<br> $num1 = preg_replace('/^(-)/','',$num1);<br> <br> } else {<br> $c1 = 1;<br> }<br> <br> if($num2 {<br> $c2 = -1;<br> $num2 = preg_replace('/^(-)/','',$num2);<br> } else {<br> $c2 = 1;<br> }<br> <br> $len1 = strlen($num1);<br> $len2 = strlen($num2);<br> $len = max(strlen($num1),strlen($num2));<br> if($len1 if($len2 <br> <br> if($op == '+')<br> {<br> if($c1 == $c2)<br> { <div class="clear"> </div>