Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
pow_ci.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 #include <math.h>
00037 #include "cmplrs/host.h"
00038 #include "moremath.h"
00039 #include "cmplx.h"
00040 #include "c_div.h"
00041 
00042 complex __powci(float areal, float aimag, int32 n)   /* __powci = a**n  */
00043 {
00044   float_t t;
00045   complex x, p;
00046 
00047   p.real = 1;
00048   p.imag = 0;
00049 
00050   if(n == 0)
00051     return p;
00052 
00053   if(n < 0) {
00054     n = -n;
00055     x = __cdiv(p.real, p.imag, areal, aimag);
00056   } else {
00057     x.real = areal;
00058     x.imag = aimag;
00059   }
00060 
00061   for( ; ; ) {
00062     if(n & 01) {
00063       t = p.real * x.real - p.imag * x.imag;
00064       p.imag = p.real * x.imag + p.imag * x.real;
00065       p.real = t;
00066     }
00067     if(n >>= 1) {
00068       t = x.real * x.real - x.imag * x.imag;
00069       x.imag = 2 * x.real * x.imag;
00070       x.real = t;
00071     } else {
00072       break;
00073     }
00074   }
00075 
00076   return p;
00077 }
00078 
00079 void pow_ci(complex *p, complex *a, int32 *b)   /* p = a**b  */
00080 {
00081   *p = __powci(a->real, a->imag, *b);
00082 }
00083 
00084 void
00085 pow_ci_(complex *p, complex *a, int32 *b)
00086 {
00087         *p = __powci(a->real, a->imag, *b);
00088 }
00089 
00090 void
00091 pow_ci__(complex *p, complex *a, int32 *b)
00092 {
00093         *p = __powci(a->real, a->imag, *b);
00094 }
00095 
00096 complex __powcl(float areal, float aimag, int64 n)   /* __powcl = a**n  */
00097 {
00098   float_t t;
00099   complex x, p;
00100 
00101   p.real = 1;
00102   p.imag = 0;
00103 
00104   if(n == 0)
00105     return p;
00106 
00107   if(n < 0) {
00108     n = -n;
00109     x = __cdiv(p.real, p.imag, areal, aimag);
00110   } else {
00111     x.real = areal;
00112     x.imag = aimag;
00113   }
00114 
00115   for( ; ; ) {
00116     if(n & 01) {
00117       t = p.real * x.real - p.imag * x.imag;
00118       p.imag = p.real * x.imag + p.imag * x.real;
00119       p.real = t;
00120     }
00121     if(n >>= 1) {
00122       t = x.real * x.real - x.imag * x.imag;
00123       x.imag = 2 * x.real * x.imag;
00124       x.real = t;
00125     } else {
00126       break;
00127     }
00128   }
00129 
00130   return p;
00131 }
00132 
00133 void pow_cl(complex *p, complex *a, int64 *b)   /* p = a**b  */
00134 {
00135   *p = __powcl(a->real, a->imag, *b);
00136 }
00137 
00138 void
00139 pow_cl_(complex *p, complex *a, int64 *b)
00140 {
00141         *p = __powcl(a->real, a->imag, *b);
00142 }
00143 
00144 void
00145 pow_cl__(complex *p, complex *a, int64 *b)
00146 {
00147         *p = __powcl(a->real, a->imag, *b);
00148 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines