|
|
1.1 ! root 1: /* ! 2: computes a^b. ! 3: uses log and exp ! 4: */ ! 5: ! 6: #include <errno.h> ! 7: int errno; ! 8: double log(), exp(); ! 9: ! 10: double ! 11: pow(arg1,arg2) ! 12: double arg1, arg2; ! 13: { ! 14: double temp; ! 15: long l = arg2; ! 16: ! 17: if(l != arg2 || l>64 || l<-64) { ! 18: if(arg1 <= 0.) { ! 19: if(arg1 == 0.) { ! 20: if(arg2 <= 0.) ! 21: goto domain; ! 22: return(0.); ! 23: } ! 24: if(l != arg2) ! 25: goto domain; ! 26: temp = exp(arg2 * log(-arg1)); ! 27: return l&1? -temp: temp; ! 28: } ! 29: return(exp(arg2 * log(arg1))); ! 30: } ! 31: temp = (l&1) ? arg1 : 1.0; ! 32: for(l=l<0?-l:l; l >>= 1;) { ! 33: arg1 *= arg1; ! 34: if(l & 1) ! 35: temp *= arg1; ! 36: } ! 37: return arg2 < 0? 1/temp: temp; ! 38: ! 39: domain: ! 40: errno = EDOM; ! 41: return(0.); ! 42: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.