/*
* szl_power.h
*/
#ifndef SZL_POWER_H
#define SZL_POWER_H
double szl_power (double, unsigned int );
#endif
/*
* szl_power.c
*/
#include "szl_power.h"
double szl_power(double a, unsigned int n){
unsigned int i;
double b,c;
b=1.0;
c=a;
i=2;
while(i<(unsigned)32){
c *= c;
if(0x00000000 != (n & i)){ // == operator has higher priority than bitwise & operator
b *= c;
}
i = (i<<1);
}
if(0x00000001 == (0x00000001 & n)){
b*=a;
}
return b;
}
上述是冥n不超过25的情形。