xref: /csrg-svn/usr.bin/f77/libF77/pow_zz.c (revision 47940)
1*47940Sbostic /*-
2*47940Sbostic  * Copyright (c) 1980 The Regents of the University of California.
3*47940Sbostic  * All rights reserved.
422941Skre  *
5*47940Sbostic  * %sccs.include.proprietary.c%
610517Sdlw  */
710517Sdlw 
8*47940Sbostic #ifndef lint
9*47940Sbostic static char sccsid[] = "@(#)pow_zz.c	5.3 (Berkeley) 04/12/91";
10*47940Sbostic #endif /* not lint */
11*47940Sbostic 
1210517Sdlw #include "complex"
1329968Smckusick #ifdef tahoe
1429968Smckusick #define cabs zabs
1529968Smckusick #endif tahoe
1610517Sdlw 
pow_zz(r,a,b)1710517Sdlw pow_zz(r,a,b)
1810517Sdlw dcomplex *r, *a, *b;
1910517Sdlw {
2010517Sdlw double logr, logi, x, y;
2110517Sdlw double log(), exp(), cos(), sin(), atan2(), cabs();
2210517Sdlw 
2310517Sdlw logr = log( cabs(a->dreal, a->dimag) );
2410517Sdlw logi = atan2(a->dimag, a->dreal);
2510517Sdlw 
2610517Sdlw x = exp( logr * b->dreal - logi * b->dimag );
2710517Sdlw y = logr * b->dimag + logi * b->dreal;
2810517Sdlw 
2910517Sdlw r->dreal = x * cos(y);
3010517Sdlw r->dimag = x * sin(y);
3110517Sdlw }
32