RWalib C Array Library User Guide > Arithmetic Operations > alibNeg
  

alibNeg
Returns the negative of scalar or array argument, element-wise. The PV-WAVE API for this routine is the Subtraction Operator -.
Prototypes
void alibNegb( wvlong n, UCHAR *p, UCHAR *r )
void alibNegs( wvlong n, short *p, short *r )
void alibNegi( wvlong n, int *p, int *r )
void alibNegl( wvlong n, wvlong *p, wvlong *r )
void alibNegf( wvlong n, float *p, float *r )
void alibNegd( wvlong n, double *p, double *r )
void alibNegc( wvlong n, COMPLEX *p, COMPLEX *r )
void alibNegz( wvlong n, DCOMPLEX *p, DCOMPLEX *r )
Parameters
n — (Input) The number of elements in the source array.
*p — (Input) The n-element source array.
*r — (Input/Output) The n-element destination array. On return, r[i] = –p[i]. This operation can be done in-place (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 */
    short    s0[6]={2,3,4,5,6,7};
  /* make an output array */
    short    s[6];
  printf( "\n\n show 6-element vector s0" );
    alibinit( NULL, NULL, NULL, NULL );
    alibPrintArrays( 1, 1, 1, 6, s0, NULL );
  printf( "\n\n show the negative of s0, element-wise" );
    alibNegs( 6, s0, s );
    alibPrintArrays( 1, 1, 1, 6, s, NULL );
  printf( "\n\n now do the same operation, but in-place, \n" );
  printf( " and show the result as a (2,3) matrix" );
    alibNegs( 6, s0, s0 );
    alibPrintArrays( 1, 1, 2, 3, s0, NULL );
}
 
Output:
 
 show 6-element vector s0
 
       2       3       4       5       6       7
 
 show the negative of s0, element-wise
 
      -2      -3      -4      -5      -6      -7
 
 now do the same operation, but in-place, 
 and show the result as a (2,3) matrix
 
      -2      -3      -4
      -5      -6      -7

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