Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
pow_zi.c
Go to the documentation of this file.
00001 /*
00002 
00003   Copyright (C) 2000, 2001 Silicon Graphics, Inc.  All Rights Reserved.
00004 
00005   This program is free software; you can redistribute it and/or modify it
00006   under the terms of version 2.1 of the GNU Lesser General Public License 
00007   as published by the Free Software Foundation.
00008 
00009   This program is distributed in the hope that it would be useful, but
00010   WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00012 
00013   Further, this software is distributed without any warranty that it is
00014   free of the rightful claim of any third person regarding infringement 
00015   or the like.  Any license provided herein, whether implied or 
00016   otherwise, applies only to this software file.  Patent licenses, if
00017   any, provided herein do not apply to combinations of this program with 
00018   other software, or any other product whatsoever.  
00019 
00020   You should have received a copy of the GNU Lesser General Public 
00021   License along with this program; if not, write the Free Software 
00022   Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, 
00023   USA.
00024 
00025   Contact information:  Silicon Graphics, Inc., 1600 Amphitheatre Pky,
00026   Mountain View, CA 94043, or:
00027 
00028   http://www.sgi.com
00029 
00030   For further information regarding this notice, see:
00031 
00032   http://oss.sgi.com/projects/GenInfo/NoticeExplan
00033 
00034 */
00035 
00036 
00037 #include "cmplrs/host.h"
00038 #include "cmplx.h"
00039 #include "z_div.h"
00040 
00041 dcomplex __powzi(double adreal, double adimag, int32 n)
00042 /* __powzi = a**n  */
00043 {
00044   double t;
00045   dcomplex x, p;
00046 
00047   p.dreal = 1;
00048   p.dimag = 0;
00049 
00050   if(n == 0)
00051     return p;
00052 
00053   if(n < 0) {
00054     n = -n;
00055     x = __zdiv(p.dreal, p.dimag, adreal, adimag);
00056   } else {
00057     x.dreal = adreal;
00058     x.dimag = adimag;
00059   }
00060 
00061   for( ; ; ) {
00062     if(n & 01) {
00063       t = p.dreal * x.dreal - p.dimag * x.dimag;
00064       p.dimag = p.dreal * x.dimag + p.dimag * x.dreal;
00065       p.dreal = t;
00066     }
00067     if(n >>= 1) {
00068       t = x.dreal * x.dreal - x.dimag * x.dimag;
00069       x.dimag = 2 * x.dreal * x.dimag;
00070       x.dreal = t;
00071     } else {
00072       break;
00073     }
00074   }
00075 
00076   return p;
00077 }
00078 
00079 void pow_zi_(dcomplex *p, dcomplex *a, int32 *b)   /* p = a**b  */
00080 {
00081   *p = __powzi(a->dreal, a->dimag,*b);
00082 }
00083 
00084 void pow_zi__(dcomplex *p, dcomplex *a, int32 *b)   /* p = a**b  */
00085 {
00086   *p = __powzi(a->dreal, a->dimag,*b);
00087 }
00088 
00089 dcomplex __powzl(double adreal, double adimag, int64 n)
00090 /* __powzl = a**n  */
00091 {
00092   double t;
00093   dcomplex x, p;
00094 
00095   p.dreal = 1;
00096   p.dimag = 0;
00097 
00098   if(n == 0)
00099     return p;
00100 
00101   if(n < 0) {
00102     n = -n;
00103     x = __zdiv(p.dreal, p.dimag, adreal, adimag);
00104   } else {
00105     x.dreal = adreal;
00106     x.dimag = adimag;
00107   }
00108 
00109   for( ; ; ) {
00110     if(n & 01) {
00111       t = p.dreal * x.dreal - p.dimag * x.dimag;
00112       p.dimag = p.dreal * x.dimag + p.dimag * x.dreal;
00113       p.dreal = t;
00114     }
00115     if(n >>= 1) {
00116       t = x.dreal * x.dreal - x.dimag * x.dimag;
00117       x.dimag = 2 * x.dreal * x.dimag;
00118       x.dreal = t;
00119     } else {
00120       break;
00121     }
00122   }
00123 
00124   return p;
00125 }
00126 
00127 void pow_zl_(dcomplex *p, dcomplex *a, int64 *b)   /* p = a**b  */
00128 {
00129   *p = __powzl(a->dreal, a->dimag,*b);
00130 }
00131 
00132 void pow_zl__(dcomplex *p, dcomplex *a, int64 *b)   /* p = a**b  */
00133 {
00134   *p = __powzl(a->dreal, a->dimag,*b);
00135 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines