Optimized math functions