math_templates.h optimized