Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add C implementation for math/base/special/fast/pow-int #1919

Merged
merged 12 commits into from
Mar 17, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat: add C implementation for math/base/special/fast/pow-int
gunjjoshi committed Mar 16, 2024
commit 67fe957b917a1d30e05a99a8eaddde0a3ab9d4f3
Original file line number Diff line number Diff line change
@@ -182,7 +182,7 @@ The function accepts the following arguments:
- **y**: `[in] double` exponent.

```c
double stdlib_base_fast_pow( const double x, int32_t y );
double stdlib_base_fast_pow( const double x, const int32_t y );
```
</section>
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@
* Prints the TAP version.
*/
void print_version() {
printf( "TAP version 13\n" );
printf( "TAP version 13\n" );
}

/**
@@ -44,12 +44,12 @@ void print_version() {
* @param passing total number of passing tests
*/
void print_summary( int total, int passing ) {
printf( "#\n" );
printf( "1..%d\n", total ); // TAP plan
printf( "# total %d\n", total );
printf( "# pass %d\n", passing );
printf( "#\n" );
printf( "# ok\n" );
printf( "#\n" );
printf( "1..%d\n", total ); // TAP plan
printf( "# total %d\n", total );
printf( "# pass %d\n", passing );
printf( "#\n" );
printf( "# ok\n" );
}

/**
@@ -58,12 +58,12 @@ void print_summary( int total, int passing ) {
* @param elapsed elapsed time in seconds
*/
void print_results( double elapsed ) {
double rate = (double)ITERATIONS / elapsed;
printf( " ---\n" );
printf( " iterations: %d\n", ITERATIONS );
printf( " elapsed: %0.9f\n", elapsed );
printf( " rate: %0.9f\n", rate );
printf( " ...\n" );
double rate = (double)ITERATIONS / elapsed;
printf( " ---\n" );
printf( " iterations: %d\n", ITERATIONS );
printf( " elapsed: %0.9f\n", elapsed );
printf( " rate: %0.9f\n", rate );
printf( " ...\n" );
}

/**
@@ -72,9 +72,9 @@ void print_results( double elapsed ) {
* @return clock time
*/
double tic() {
struct timeval now;
gettimeofday( &now, NULL );
return (double)now.tv_sec + (double)now.tv_usec/1.0e6;
struct timeval now;
gettimeofday( &now, NULL );
return (double)now.tv_sec + (double)now.tv_usec / 1.0e6;
}

/**
@@ -83,8 +83,8 @@ double tic() {
* @return random number
*/
double rand_double() {
int r = rand();
return (double)r / ( (double)RAND_MAX + 1.0 );
int r = rand();
return (double)r / ( (double)RAND_MAX + 1.0 );
}

/**
@@ -93,46 +93,46 @@ double rand_double() {
* @return elapsed time in seconds
*/
double benchmark() {
double elapsed;
int32_t x;
double t;
double y;
double z;
int i;
double elapsed;
int32_t x;
double t;
double y;
double z;
int i;

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 100.0 * rand_double() ) - 50.00;
y = floor( 100.0 * rand_double() ) - 50.00;
t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 100.0 * rand_double() ) - 50.00;
y = floor( 100.0 * rand_double() ) - 50.00;
z = stdlib_base_fast_pow( x, y );
if ( z != z) {
printf( "should not return NaN\n" );
break;
}
}
elapsed = tic() - t;
if ( z != z ) {
printf( "should not return NaN\n" );
}
return elapsed;
if ( z != z) {
printf( "should not return NaN\n" );
break;
}
}
elapsed = tic() - t;
if ( z != z ) {
printf( "should not return NaN\n" );
}
return elapsed;
}

/**
* Main execution sequence.
*/
int main( void ) {
double elapsed;
int i;
double elapsed;
int i;

// Use the current time to seed the random number generator:
srand( time( NULL ) );
// Use the current time to seed the random number generator:
srand( time( NULL ) );

print_version();
for ( i = 0; i < REPEATS; i++ ) {
printf( "# c::native::%s\n", NAME );
elapsed = benchmark();
print_results( elapsed );
printf( "ok %d benchmark finished\n", i+1 );
}
print_summary( REPEATS, REPEATS );
print_version();
for ( i = 0; i < REPEATS; i++ ) {
printf( "# c::native::%s\n", NAME );
elapsed = benchmark();
print_results( elapsed );
printf( "ok %d benchmark finished\n", i+1 );
}
print_summary( REPEATS, REPEATS );
}
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@
"dependencies": [
"@stdlib/math/base/napi/binary",
"@stdlib/math/base/assert/is-nan",
"@stdlib/constants/float64/pinf"
"@stdlib/constants/float64/pinf"
]
},
{
@@ -57,7 +57,7 @@
"libpath": [],
"dependencies": [
"@stdlib/math/base/assert/is-nan",
"@stdlib/constants/float64/pinf"
"@stdlib/constants/float64/pinf"
]
},
{
@@ -74,7 +74,7 @@
"libpath": [],
"dependencies": [
"@stdlib/math/base/assert/is-nan",
"@stdlib/constants/float64/pinf"
"@stdlib/constants/float64/pinf"
]
}
]