| GNU Scientific Library Reference Manual - Revised Second Edition (v1.8) by M. Galassi, J. Davies, J. Theiler, B. Gough, G. Jungman, M. Booth, F. Rossi Paperback (6"x9"), 636 pages, 60 figures ISBN 0954161734 RRP £24.99 ($39.99) |
4.4 Small integer powers
A common complaint about the standard C library is its lack of a function for calculating (small) integer powers. GSL provides some 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 x^n for integer n. The
power is computed efficiently--for example, x^8 is computed as
((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)
- Function: double gsl_pow_3 (const double x)
- These functions can be used to compute small integer powers x^2, 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 */
| ISBN 0954161734 | GNU Scientific Library Reference Manual - Revised Second Edition (v1.8) | See the print edition |