Context API: Move math functions from the context class into their own module.

This is built on top of the currently unmerged pull #164.