Actually (for both this case and the one above), we want to do a floating point division, not convert the result of the division to a double.  But since N is a double, we already do a floating point division, so there's no need to cast the result - it will already be a double.

It looks to me like the only part of the casting change that's needed is line 132 - I'll merge that and see.