If you are talking about the else 0:

I've added that because if all labels are positive or negative we would divide by 0, I could change it to 0.5 if that's more appropriate.

The formula is quite neat, and hard to find. I can't find the link searching through my history right now, but I'll comment on that soon. I've verified the computation using an R package to calculate ROC on the exact same data set.