xref: /csrg-svn/old/libm/liboldnm/pow.c (revision 20008)
120003Sdist /*
2*20008Sdist  * Copyright (c) 1980 Regents of the University of California.
3*20008Sdist  * All rights reserved.  The Berkeley software License Agreement
4*20008Sdist  * specifies the terms and conditions for redistribution.
5*20008Sdist  */
6*20008Sdist 
7*20008Sdist #ifndef lint
8*20008Sdist static char sccsid[] = "@(#)pow.c	5.1 (Berkeley) 05/08/85";
9*20008Sdist #endif not lint
10*20008Sdist 
11*20008Sdist /*
1220003Sdist 	computes a^b.
1320003Sdist 	uses log and exp
1420003Sdist */
1520003Sdist 
1620003Sdist #include	<errno.h>
1720003Sdist int errno;
1820003Sdist double log(), exp();
1920003Sdist 
2020003Sdist double
pow(arg1,arg2)2120003Sdist pow(arg1,arg2)
2220003Sdist double arg1, arg2;
2320003Sdist {
2420003Sdist 	double temp;
2520003Sdist 	long l;
2620003Sdist 
2720003Sdist 	asm("	bispsw	$0xe0");
2820003Sdist 	if(arg1 <= 0.) {
2920003Sdist 		if(arg1 == 0.) {
3020003Sdist 			if(arg2 <= 0.)
3120003Sdist 				goto domain;
3220003Sdist 			return(0.);
3320003Sdist 		}
3420003Sdist 		l = arg2;
3520003Sdist 		if(l != arg2)
3620003Sdist 			goto domain;
3720003Sdist 		temp = exp(arg2 * log(-arg1));
3820003Sdist 		if(l & 1)
3920003Sdist 			temp = -temp;
4020003Sdist 		return(temp);
4120003Sdist 	}
4220003Sdist 	return(exp(arg2 * log(arg1)));
4320003Sdist 
4420003Sdist domain:
4520003Sdist 	errno = EDOM;
4620003Sdist 	return(0.);
4720003Sdist }
48