- abs: documentation ( source)
- printf: documentation ( source)
<?php
function f($dividend, $divider)
{
$reminder = (($dividend % $divider) + abs($divider)) % abs($divider);
$quotient = ($dividend - $reminder) / $divider;
printf("%2d/%2d = %2d (remainder %d)\n", $dividend, $divider, $quotient, $reminder);
}
f(7, 3);
f(7, -3);
f(-7, 3);
f(-7, -3);