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

This is built on top of PR #164.