I hadn't even noticed this little change.... gahhh! Dumb me.

$p=iif($p,$p-1,($^)/2)