php 7中使用int 32的下溢返回0

时间:2018-01-14 08:05:52

标签: php-7 underflow

我使用以下代码打印带下溢的两个整数的总和:

        $z10 = (int)($z & 0xFFFFFFFF);
        $z11 = (int)($z5 & 0xFFFFFFFF);
        $z12 = (int)(((int)$z10 + (int)$z11) & 0xFFFFFFFF);
        $z10_type =  gettype ( $z10);
        $z11_type =  gettype ( $z11);
        $z12_type =  gettype ( $z12);
        print "z10   " .dechex($z10) . "           " . $z10_type . "\n";
        print "z11   " .dechex($z11) . "           " . $z11_type .  "\n";
        print "z12   " .dechex($z12) . "           " . $z12_type .  "\n";
        $z = ((int)($z10 + $z11)) & 0xFFFFFFFF;
        print "z   " .$z . "\n";

php7和HW支持int32的结果是:

z10   eb9c083c           integer
z11   8d833a2f           integer
z12   0           integer
z   0

php 5.5和HW支持int32的结果是:

z10   eb9c083c           integer
z11   8d833a2f           integer
z12   791f426b           integer
z   2032091755

我在php 7中获得0的原因是什么?

0 个答案:

没有答案