A common complaint about the standard C library is its lack of a function for calculating (small) integer powers. GSL provides a simple functions to fill this gap. For reasons of efficiency, these functions do not check for overflow or underflow conditions.

__Function:__double**gsl_pow_int***(double*`x`, int`n`)-
This routine computes the power @math{x^n} for integer
`n`. The power is computed using the minimum number of multiplications. For example, @math{x^8} is computed as @math{((x^2)^2)^2}, requiring only 3 multiplications. A version of this function which also computes the numerical error in the result is available as`gsl_sf_pow_int_e`

.

__Function:__double**gsl_pow_2***(const double*`x`)__Function:__double**gsl_pow_3***(const double*`x`)__Function:__double**gsl_pow_4***(const double*`x`)__Function:__double**gsl_pow_5***(const double*`x`)__Function:__double**gsl_pow_6***(const double*`x`)__Function:__double**gsl_pow_7***(const double*`x`)__Function:__double**gsl_pow_8***(const double*`x`)__Function:__double**gsl_pow_9***(const double*`x`)- These functions can be used to compute small integer powers @math{x^2}, @math{x^3}, etc. efficiently. The functions will be inlined when possible so that use of these functions should be as efficient as explicitly writing the corresponding product expression.

#include <gsl/gsl_math.h> double y = gsl_pow_4 (3.141) /* compute 3.141**4 */

Go to the first, previous, next, last section, table of contents.