RWalib C Array Library User Guide > Arithmetic Operations > alibAbs
  

alibAbs
Returns the absolute value of each element in an array. The PV-WAVE API for this routine is the ABS Function.
Prototypes
void alibAbss( wvlong n, short *p, short *r )
void alibAbsi( wvlong n, int *p, int *r )
void alibAbsl( wvlong n, wvlong *p, wvlong *r )
void alibAbsf( wvlong n, float *p, float *r )
void alibAbsd( wvlong n, double *p, double *r )
void alibAbsc( wvlong n, COMPLEX *p, double *r )
void alibAbsz( wvlong n, DCOMPLEX *p, double *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, array r contains the absolute value of each element in array p. For real data-types, 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 */
        short    s0[6] = {0,-1,2,-3,4,-5};
    /* make an output array */
        short  s[6];
    printf( "\n\n print the input array s0" );
        alibinit( NULL, NULL, NULL, NULL );
        alibPrintArrays( 1, 1, 1, 6, s0, NULL );
    printf( "\n\n print the absolute value of each element in s0" );
        alibAbss( 6, s0, s );
        alibPrintArrays( 1, 1, 1, 6, s, NULL );
    printf( "\n\n now do the same operation in-place, \n" );
    printf( " and show the result as a (2,3) matrix" );
        alibAbss( 6, s0, s0 );
        alibPrintArrays( 1, 1, 2, 3, s0, NULL );
}
 
Output:
 
 print the input array s0
 
       0      -1       2      -3       4      -5
 
 print the absolute value of each element in s0
 
       0       1       2       3       4       5
 
 now do the same operation in-place, 
 and show the result as a (2,3) matrix
 
       0       1       2
       3       4       5

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