Assuming ^ means exponentiation and that q is a run-time variable, use std::pow(double, int) .
EDIT: for completeness, due to comments on this question: I asked the question Why is std :: pow (double, int) removed from C ++ 11? about the missing function and actually pow(double, int) not deleted in C ++ 0x, only the language was changed. However, it seems that libraries cannot actually optimize it due to problems in terms of accuracy.
Even considering that I will still use pow until the measurement shows me that it needs to be optimized.
Mark B Apr 11 '11 at 18:01 2011-04-11 18:01
source share