Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
pow_ii.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 /* $Header: /m_home/m_utkej/Argonne/cvs2svn/cvs/Open64/osprey1.0/libF77/pow_ii.c,v 1.1.1.1 2002-05-22 20:09:13 dsystem Exp $ */
00038 
00039 #include "cmplrs/host.h"
00040 
00041 int32 __powii(int32 ap, int32 n)
00042 {
00043 int32 pow;
00044 /* 10/9/89 fix bug 5116 */
00045 
00046 if(n != 0) {
00047         if (n<0) {
00048                 /* if ap <> 1 or -1, then any other integer raised to
00049                  * a negative power would return a fraction, which is 
00050                  * rounded to 0.  if ap = 1 or -1 then depending on the
00051                  * power, if the power is odd, then result = -1, else = 1
00052                  */
00053                 if ((ap!=1)&&(ap!=-1)) return(0); 
00054                 n = -n;
00055                 }
00056         pow=1;
00057         for( ; ; )
00058                 {
00059                 if(n & 01)
00060                         pow *= ap;
00061                 if(n >>= 1)
00062                         ap *= ap;
00063                 else
00064                         return(pow);
00065                 }
00066      }
00067 else return(1);
00068 }
00069 
00070 int64 __powll(int64 ap, int64 n)
00071 {
00072 int64 pow;
00073 /* 10/9/89 fix bug 5116 */
00074 
00075 if(n != 0) { 
00076         if (n<0) {
00077                 /* if ap <> 1 or -1, then any other integer raised to
00078                  * a negative power would return a fraction, which is 
00079                  * rounded to 0.  if ap = 1 or -1 then depending on the
00080                  * power, if the power is odd, then result = -1, else = 1
00081                  */
00082                 if ((ap!=1)&&(ap!=-1)) return(0); 
00083                 n = -n;
00084                 }
00085         pow=1;
00086         for( ; ; )
00087                 {
00088                 if(n & 01)
00089                         pow = pow * ap;
00090                 if(n >>= 1)
00091                         ap = ap * ap;
00092                 else
00093                         return(pow);
00094                 }
00095      }
00096 else return(1);
00097 }
00098 
00099 int64 __powli(int64 ap, int32 n)
00100 {
00101 int64 pow;
00102 /* 10/9/89 fix bug 5116 */
00103 
00104 if(n != 0) {
00105         if (n<0) {
00106                 /* if ap <> 1 or -1, then any other integer raised to
00107                  * a negative power would return a fraction, which is 
00108                  * rounded to 0.  if ap = 1 or -1 then depending on the
00109                  * power, if the power is odd, then result = -1, else = 1
00110                  */
00111                 if ((ap!=1)&&(ap!=-1)) return(0); 
00112                 n = -n;
00113                 }
00114         pow=1;
00115         for( ; ; )
00116                 {
00117                 if(n & 01)
00118                         pow = pow * ap;
00119                 if(n >>= 1)
00120                         ap = ap * ap;
00121                 else
00122                         return(pow);
00123                 }
00124      }
00125 else return(1);
00126 }
00127 
00128 int32 __powil(int32 ap, int64 n)
00129 {
00130 int32 pow;
00131 /* 10/9/89 fix bug 5116 */
00132 
00133 if(n != 0) {
00134         if (n<0) {
00135                 /* if ap <> 1 or -1, then any other integer raised to
00136                  * a negative power would return a fraction, which is 
00137                  * rounded to 0.  if ap = 1 or -1 then depending on the
00138                  * power, if the power is odd, then result = -1, else = 1
00139                  */
00140                 if ((ap!=1)&&(ap!=-1)) return(0); 
00141                 n = -n;
00142                 }
00143         pow=1;
00144         for( ; ; )
00145                 {
00146                 if(n & 01)
00147                         pow = pow * ap;
00148                 if(n >>= 1)
00149                         ap = ap * ap;
00150                 else
00151                         return(pow);
00152                 }
00153      }
00154 else return(1);
00155 }
00156 
00157 /* By-reference versions for backward compatibility. */
00158 
00159 int32 pow_ii(int32 *ap, int32 *bp)
00160 {
00161 int32 pow;
00162 pow=__powii(*ap,*bp);
00163 return pow;
00164 }
00165 
00166 int64 pow_il(int32 *ap, int64 *bp)
00167 {
00168 int64 pow;
00169 pow=__powil(*ap,*bp);
00170 return pow;
00171 }
00172 
00173 int64 pow_li(int64 *ap, int32 *bp)
00174 {
00175 int64 pow;
00176 pow=__powli(*ap,*bp);
00177 return pow;
00178 }
00179 
00180 int64 pow_ll(int64 *ap, int64 *bp)
00181 {
00182 int64 pow;
00183 pow=__powll(*ap,*bp);
00184 return pow;
00185 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines