Derived from this question : (Java) How does java do modulus calculations with negative numbers?
Anywhere to force PHP to return positive 51?
update
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.