How is -13 d = -13 in PHP?

后端 未结 4 911
南笙
南笙 2020-12-06 17:45

Derived from this question : (Java) How does java do modulus calculations with negative numbers?

Anywhere to force PHP to return positive 51?

update

4条回答
  •  青春惊慌失措
    2020-12-06 17:58

    Anyway, the post you referenced already gave the correct answer:

    $r = $x % $n;
    if ($r < 0)
    {
        $r += abs($n);
    }
    

    Where $x = -13 and $n = 64.

提交回复
热议问题