Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,15 @@ static double tic( void ) {
}

/**
* Generates a random number on the interval [0,1).
* Generates a random number on the interval [min,max).
*
* @return random number
* @param min minimum value (inclusive)
* @param max maximum value (exclusive)
* @return random number
*/
static float rand_float( void ) {
int r = rand();
return (float)r / ( (float)RAND_MAX + 1.0f );
static float random_uniform( const float min, const float max ) {
float v = (float)rand() / ( (float)RAND_MAX + 1.0f );
return min + ( v*( max-min ) );
}

/**
Expand All @@ -100,14 +102,17 @@ float addf( const float x, const float y ) {
static double benchmark( void ) {
double elapsed;
double t;
float x;
float *x;
float y;
int i;

x = (float *) malloc( 100 * sizeof( float ) );
for ( i = 0; i < 100; i++ ) {
x[ i ] = random_uniform( -500.0f, 500.0f );
}
t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 1000.0f*rand_float() ) - 500.0f;
y = addf( x, 5.0f );
y = addf( x[ i%100 ], 5.0f );
if ( y != y ) {
printf( "should not return NaN\n" );
break;
Expand All @@ -117,6 +122,7 @@ static double benchmark( void ) {
if ( y != y ) {
printf( "should not return NaN\n" );
}
free( x );
return elapsed;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ static double tic( void ) {
}

/**
* Generates a random number on the interval [0,1).
* Generates a random number on the interval [min,max).
*
* @return random number
* @param min minimum value (inclusive)
* @param max maximum value (exclusive)
* @return random number
*/
static float rand_float( void ) {
int r = rand();
return (float)r / ( (float)RAND_MAX + 1.0f );
static float random_uniform( const float min, const float max ) {
float v = (float)rand() / ( (float)RAND_MAX + 1.0f );
return min + ( v*( max-min ) );
}

/**
Expand All @@ -92,14 +94,17 @@ static float rand_float( void ) {
static double benchmark( void ) {
double elapsed;
double t;
float x;
float *x;
float y;
int i;

x = (float *) malloc( 100 * sizeof( float ) );
for ( i = 0; i < 100; i++ ) {
x[ i ] = random_uniform( -500.0f, 500.0f );
}
t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 1000.0f*rand_float() ) - 500.0f;
y = stdlib_base_float32_add( x, 5.0f );
y = stdlib_base_float32_add( x[ i%100 ], 5.0f );
if ( y != y ) {
printf( "should not return NaN\n" );
break;
Expand All @@ -109,6 +114,7 @@ static double benchmark( void ) {
if ( y != y ) {
printf( "should not return NaN\n" );
}
free( x );
return elapsed;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,15 @@ static double tic( void ) {
}

/**
* Generates a random number on the interval [0,1).
* Generates a random number on the interval [min,max).
*
* @return random number
* @param min minimum value (inclusive)
* @param max maximum value (exclusive)
* @return random number
*/
static float rand_float( void ) {
int r = rand();
return (float)r / ( (float)RAND_MAX + 1.0f );
static float random_uniform( const float min, const float max ) {
float v = (float)rand() / ( (float)RAND_MAX + 1.0f );
return min + ( v*( max-min ) );
}

/**
Expand All @@ -100,14 +102,17 @@ float divide( const float x, const float y ) {
static double benchmark( void ) {
double elapsed;
double t;
float x;
float *x;
float y;
int i;

x = (float *) malloc( 100 * sizeof( float ) );
for ( i = 0; i < 100; i++ ) {
x[ i ] = random_uniform( -500.0f, 500.0f );
}
t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 1000.0f*rand_float() ) - 500.0f;
y = divide( x, 5.0f );
y = divide( x[ i%100 ], 5.0f );
if ( y != y ) {
printf( "should not return NaN\n" );
break;
Expand All @@ -117,6 +122,7 @@ static double benchmark( void ) {
if ( y != y ) {
printf( "should not return NaN\n" );
}
free( x );
return elapsed;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ static double tic( void ) {
}

/**
* Generates a random number on the interval [0,1).
* Generates a random number on the interval [min,max).
*
* @return random number
* @param min minimum value (inclusive)
* @param max maximum value (exclusive)
* @return random number
*/
static float rand_float( void ) {
int r = rand();
return (float)r / ( (float)RAND_MAX + 1.0f );
static float random_uniform( const float min, const float max ) {
float v = (float)rand() / ( (float)RAND_MAX + 1.0f );
return min + ( v*( max-min ) );
}

/**
Expand All @@ -92,14 +94,17 @@ static float rand_float( void ) {
static double benchmark( void ) {
double elapsed;
double t;
float x;
float *x;
float y;
int i;

x = (float *) malloc( 100 * sizeof( float ) );
for ( i = 0; i < 100; i++ ) {
x[ i ] = random_uniform( -500.0f, 500.0f );
}
t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 1000.0f*rand_float() ) - 500.0f;
y = stdlib_base_float32_div( x, 5.0f );
y = stdlib_base_float32_div( x[ i%100 ], 5.0f );
if ( y != y ) {
printf( "should not return NaN\n" );
break;
Expand All @@ -109,6 +114,7 @@ static double benchmark( void ) {
if ( y != y ) {
printf( "should not return NaN\n" );
}
free( x );
return elapsed;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,15 @@ static double tic( void ) {
}

/**
* Generates a random number on the interval [0,1).
* Generates a random number on the interval [min,max).
*
* @return random number
* @param min minimum value (inclusive)
* @param max maximum value (exclusive)
* @return random number
*/
static float rand_float( void ) {
int r = rand();
return (float)r / ( (float)RAND_MAX + 1.0f );
static float random_uniform( const float min, const float max ) {
float v = (float)rand() / ( (float)RAND_MAX + 1.0f );
return min + ( v*( max-min ) );
}

/**
Expand All @@ -94,13 +96,16 @@ static double benchmark( void ) {
double elapsed;
int32_t out;
double t;
float x;
float *x;
int i;

x = (float *) malloc( 100 * sizeof( float ) );
for ( i = 0; i < 100; i++ ) {
x[ i ] = random_uniform( -5.0e6f, 5.0e6f );
}
t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( rand_float()*1.0e7f ) - 5.0e6f;
out = stdlib_base_float32_exponent( x );
out = stdlib_base_float32_exponent( x[ i%100 ] );
if ( out == 128 ) {
printf( "unexpected result\n" );
break;
Expand All @@ -110,6 +115,7 @@ static double benchmark( void ) {
if ( out == 128 ) {
printf( "unexpected result\n" );
}
free( x );
return elapsed;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ static double tic( void ) {
}

/**
* Generates a random number on the interval [0,1).
* Generates a random number on the interval [min,max).
*
* @return random number
* @param min minimum value (inclusive)
* @param max maximum value (exclusive)
* @return random number
*/
static float rand_float( void ) {
int r = rand();
return (float)r / ( (float)RAND_MAX + 1.0f );
static float random_uniform( const float min, const float max ) {
float v = (float)rand() / ( (float)RAND_MAX + 1.0f );
return min + ( v*( max-min ) );
}

/**
Expand All @@ -92,14 +94,17 @@ static float rand_float( void ) {
static double benchmark( void ) {
double elapsed;
double t;
float x;
float *x;
float y;
int i;

x = (float *) malloc( 100 * sizeof( float ) );
for ( i = 0; i < 100; i++ ) {
x[ i ] = random_uniform( -500.0f, 500.0f );
}
t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 1000.0f*rand_float() ) - 500.0f;
y = stdlib_base_float32_identity( x );
y = stdlib_base_float32_identity( x[ i%100 ] );
if ( y != y ) {
printf( "should not return NaN\n" );
break;
Expand All @@ -109,6 +114,7 @@ static double benchmark( void ) {
if ( y != y ) {
printf( "should not return NaN\n" );
}
free( x );
return elapsed;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,15 @@ static double tic( void ) {
}

/**
* Generates a random number on the interval [0,1).
* Generates a random number on the interval [min,max).
*
* @return random number
* @param min minimum value (inclusive)
* @param max maximum value (exclusive)
* @return random number
*/
static float rand_float( void ) {
int r = rand();
return (float)r / ( (float)RAND_MAX + 1.0f );
static float random_uniform( const float min, const float max ) {
float v = (float)rand() / ( (float)RAND_MAX + 1.0f );
return min + ( v*( max-min ) );
}

/**
Expand All @@ -99,15 +101,18 @@ float mulf( const float x, const float y ) {
*/
static double benchmark( void ) {
double elapsed;
float x;
float *x;
float y;
double t;
int i;

x = (float *) malloc( 100 * sizeof( float ) );
for ( i = 0; i < 100; i++ ) {
x[ i ] = random_uniform( -500.0f, 500.0f );
}
t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 1000.0f*rand_float() ) - 500.0f;
y = mulf( x, 5.0f );
y = mulf( x[ i%100 ], 5.0f );
if ( y != y ) {
printf( "should not return NaN\n" );
break;
Expand All @@ -117,6 +122,7 @@ static double benchmark( void ) {
if ( y != y ) {
printf( "should not return NaN\n" );
}
free( x );
return elapsed;
}

Expand Down
Loading