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