62 lines
1.2 KiB
C
62 lines
1.2 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <math.h>
|
|
#include <inttypes.h>
|
|
|
|
#define BUFFER_SIZE (1 << 12)
|
|
|
|
static void lrintf_test (void) ;
|
|
|
|
typedef union
|
|
{ double d [BUFFER_SIZE + 1] ;
|
|
float f [BUFFER_SIZE + 1] ;
|
|
int i [BUFFER_SIZE + 1] ;
|
|
short s [BUFFER_SIZE + 1] ;
|
|
} BUFFER ;
|
|
|
|
/* Data written to the file. */
|
|
static BUFFER data_out ;
|
|
|
|
/* Data read back from the file. */
|
|
static BUFFER data_in ;
|
|
|
|
int
|
|
main (void)
|
|
{
|
|
lrintf_test () ;
|
|
|
|
return 0 ;
|
|
} /* main */
|
|
|
|
/*============================================================================================
|
|
** Here are the test functions.
|
|
*/
|
|
|
|
static void
|
|
lrintf_test (void)
|
|
{ int k, items ;
|
|
float *float_data ;
|
|
int *int_data ;
|
|
|
|
/* print_test_name ("lrintf_test", "") ; */
|
|
|
|
items = 1024 ;
|
|
|
|
float_data = data_out.f ;
|
|
int_data = data_in.i ;
|
|
|
|
for (k = 0 ; k < items ; k++)
|
|
float_data [k] = (k * ((k % 2) ? 333333.0 : -333333.0)) ;
|
|
|
|
for (k = 0 ; k < items ; k++)
|
|
int_data [k] = lrintf (float_data [k]) ;
|
|
|
|
for (k = 0 ; k < items ; k++)
|
|
if (fabs (int_data [k] - float_data [k]) > 1.0)
|
|
{ printf ("\n\nLine %d: float : Incorrect sample (#%d : %f => %d).\n", __LINE__, k, float_data [k], int_data [k]) ;
|
|
exit (1) ;
|
|
} ;
|
|
|
|
printf ("ok\n") ;
|
|
} /* lrintf_test */
|