Maths Code Refactoring

This pull request represents the completion of the first deliverable of my Google Summer of Code project.
I managed to refactor all the maths code in a c++ style while mantaining the same level of performance.
If you have any questions or doubts please ask.
Compiling with tdm-gcc causes an error here saying "pasting "->" and "X" does not give a valid preprocessing token". Removing the ## fixes it.