Cycles Procedural Square using Polar Coordinates
I'm not sure what you've actually got wrong with your setup but I've tried to replicate it by entering your math into a Node Expressions expression (see https://baldingwizard.wixsite.com/blog/node-expressions) - which builds the nodes directly from the text.

This produces the following result :



The generated 'inner' nodes for the 'f' function are :



And here's the Blend file (Blender 2.8) for reference 



EDIT: Actually, I think I've spotted the error. Your nodes actually perform the calculation : 

f = cos(floor(a * 0.636+0.5)*(1.57-a)) * dist


ie, Instead of multiplying by 1.57 and then subtracting 'a', you're nodes subtract a from 1.57 and then multiply - note the brackets I added around '1.57-a'). Here's the amended (wrong) calculation, replicating your result :