Go code for some helper functions in math