RWalib C Array Library User Guide > Exponentiation and Logarithms > alibPowI
  

alibPowI
Integer powers for scalar or array arguments, element-wise. The PV-WAVE API for this routine is the Exponentiation Operator ^.
Prototypes
void alibPowIf( wvlong m, wvlong n, float *p, wvlong *q, float *r )
void alibPowId( wvlong m, wvlong n, double *p, wvlong *q, double *r )
void alibPowIc( wvlong m, wvlong n, COMPLEX *p, wvlong *q, COMPLEX *r )
void alibPowIz( wvlong m, wvlong n, DCOMPLEX *p, wvlong *q, DCOMPLEX *r )
Parameters
m — (Input) The number of elements in the first array operand. A value of 0 indicates that the first operand is a scalar.
n — (Input) The number of elements in the second array operand. A value of 0 indicates that the second operand is a scalar. If both operands are arrays then n must equal m.
*p — (Input) The pointer to the first operand.
*q — (Input) The pointer to the second operand.
*r — (Input/Output) The destination array. On return, array r contains argument p to the integer power of argument q, element-wise. The operation can be done in-place, i.e., r can equal p.
Example
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "alib.h"
void main() {
  /* make up some input data for the examples */
    wvlong   p0=3, p1=-3, p2[4]={3,-3,4,-4};
    float    f0=2, f1[4]={2,3,4,5};
  /* make an output array */
    float    f[4];
  printf( "\n\n show scalar f0 and 4-element vector p2" );
    alibinit( NULL, NULL, NULL, NULL );
    alibPrintArrayf( 1, 1, 1, 1, &f0, NULL );
    alibPrintArrayl( 1, 1, 1, 4, p2, "%16lld" );
  printf( "\n\n show f0 to the power p2, element-wise" );
    alibPowIf( 0, 4, &f0, p2, f );
    alibPrintArrayf( 1, 1, 1, 4, f, NULL );
  printf( "\n\n show 4-element vector f1 and scalar p0" );
    alibPrintArrayf( 1, 1, 1, 4, f1, NULL );
    alibPrintArrayl( 1, 1, 1, 1, &p0, "%16lld" );
  printf( "\n\n show f1 to the power p0, element-wise" );
    alibPowIf( 4, 0, f1, &p0, f );
    alibPrintArrayf( 1, 1, 1, 4, f, NULL );
  printf( "\n\n show 4-element vector f1 and scalar p1" );
    alibPrintArrayf( 1, 1, 1, 4, f1, NULL );
    alibPrintArrayl( 1, 1, 1, 1, &p1, "%16lld" );
  printf( "\n\n show f1 to the power p1, element-wise" );
    alibPowIf( 4, 0, f1, &p1, f );
    alibPrintArrayf( 1, 1, 1, 4, f, NULL );
  printf( "\n\n show 4-element vectors f1 and p2" );
    alibPrintArrayf( 1, 1, 1, 4, f1, NULL );
    alibPrintArrayl( 1, 1, 1, 4, p2, "%16lld" );
  printf( "\n\n show f1 to the power p2, element-wise" );
    alibPowIf( 4, 4, f1, p2, f );
    alibPrintArrayf( 1, 1, 1, 4, f, NULL );
  printf( "\n\n repeat the operation in-place;  print result as a matrix" );
    alibPowIf( 4, 4, f1, p2, f1 );
    alibPrintArrayf( 1, 1, 2, 2, f1, NULL );
}
 
Output:
 
 show scalar f0 and 4-element vector p2
 
   2.000e+00
 
               3              -3               4              -4
 
 show f0 to the power p2, element-wise
 
   8.000e+00   1.250e-01   1.600e+01   6.250e-02
 
 show 4-element vector f1 and scalar p0
 
   2.000e+00   3.000e+00   4.000e+00   5.000e+00
 
               3
 
 show f1 to the power p0, element-wise
 
   8.000e+00   2.700e+01   6.400e+01   1.250e+02
 
 show 4-element vector f1 and scalar p1
 
   2.000e+00   3.000e+00   4.000e+00   5.000e+00
 
              -3
 
 show f1 to the power p1, element-wise
 
   1.250e-01   3.704e-02   1.562e-02   8.000e-03
 
 show 4-element vectors f1 and p2
 
   2.000e+00   3.000e+00   4.000e+00   5.000e+00
 
               3              -3               4              -4
 
 show f1 to the power p2, element-wise
 
   8.000e+00   3.704e-02   2.560e+02   1.600e-03
 
 repeat the operation in-place;  print result as a matrix
 
   8.000e+00   3.704e-02
   2.560e+02   1.600e-03

Version 2017.0
Copyright © 2017, Rogue Wave Software, Inc. All Rights Reserved.