migrated maths to javascript, ruby sucks at it