Some advanced math functions for javascript