RWalib C Array Library User Guide > Rounding Operations > alibRound
  

alibRound
Rounds each element of an array to the nearest integer. Half-way cases are rounded away from zero. The PV-WAVE API for this routine is the NINT Function (specifically the Floating keyword).
Prototypes
void alibRoundf( wvlong n, float *p, float *r )
void alibRoundd( wvlong n, double *p, double *r )
Parameters
n — (Input) The number of elements in the array.
*p — (Input) The n-element source array.
*r — (Input/Output) The destination array. On return, each element has been rounded to the nearest integer. Half-way cases are rounded away from zero. This 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 data for the examples */
   float  f0[5]={-1.75,-0.5,0.25,0.5,2}, *f;
   /* make output array */
   f = (float*)malloc(5*sizeof(float));
   printf( "\n\n show array f0" );
      alibinit( NULL, NULL, NULL, NULL );
      alibPrintArrayf( 1, 1, 1, 5, f0, NULL );
   printf( "\n\n round each element in f0 to the nearest integer" );
      alibRoundf( 5, f0, f );
      alibPrintArrayf( 1, 1, 1, 5, f, NULL );
}
 
Output:
 
 show array f0
 
  -1.750e+00  -5.000e-01   2.500e-01   5.000e-01   2.000e+00
 
 round each element in f0 to the nearest integer
 
  -2.000e+00  -1.000e+00   0.000e+00   1.000e+00   2.000e+00

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