Bother - that code is such a pain to work through.
Agreed. I worked through it back in the summer and it took me at least three passes to get everything right. I'm also quite confident there is only the single bug (well, not accounting for a rounding bug that also creeps in on rare occasions).
Here is the difference between whipping an axeman and an archer on turn 0:
Axeman:
35 hammers remaining / 20 hammers per pop = 2 pop sacrificed
35 hammers left in project -> 60 hammers contributed from whipping.
Archer:
25 hammers remaining / 20 hammers per pop = 2 pop sacrificed
25 hammer left in project -> 30 hammers contributed from whipping
So, if you had a theoetical project that cost you 55 hammers on the first turn the outcomes would look like this:
55 / 20 = 3 pop sacrificed
55 hammers left -> 60 hammers contributed
That last time it actually worked out exactly as it was supposed to, but those times are fairly rare.
If you haven't seen it before, you can take a look at my whipping spreadsheet that can be used to calculate returns from whipping projects at various hammer levels.
http://forums.civfanatics.com/attachment.php?attachmentid=137640&d=1157570705