Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Nov 26, 2024
1 parent 386a469 commit be7e4c8
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 100 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<section class="release" id="unreleased">

## Unreleased (2024-11-24)
## Unreleased (2024-11-26)

<section class="packages">

Expand Down Expand Up @@ -2598,6 +2598,7 @@ A total of 5 people contributed to this release. Thank you to the following cont

<details>

- [`2a10dde`](https://github.com/stdlib-js/stdlib/commit/2a10dde4b821cf7d96fcd76339beac03e9548f47) - **bench:** update benchmarks and examples in `math/base/special/ldexp` [(#2781)](https://github.com/stdlib-js/stdlib/pull/2781) _(by Gunj Joshi, stdlib-bot)_
- [`b0e68c5`](https://github.com/stdlib-js/stdlib/commit/b0e68c5bc8ee985794eb2ea1791c9337cd15fbd0) - **chore:** update to modern benchmark Makefile _(by Philipp Burckhardt)_
- [`4817867`](https://github.com/stdlib-js/stdlib/commit/4817867dcbddffe1ead3f532e01fce352bd77808) - **chore:** move stdlib benchmarks into native sub-directories _(by Philipp Burckhardt)_
- [`04a838f`](https://github.com/stdlib-js/stdlib/commit/04a838fd4345e5a0b3e739e734b8fb1f21de56a3) - **chore:** use correct Makefile _(by Philipp Burckhardt)_
Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Contributors listed in alphabetical order.

Aayush Khanna <[email protected]>
Abhijit <[email protected]>
AbhijitRaut04 <[email protected]>
Adarsh Palaskar <[email protected]>
Aditya Sapra <[email protected]>
Expand Down Expand Up @@ -107,6 +108,7 @@ Utkarsh Raj <[email protected]>
UtkershBasnet <[email protected]>
Vaibhav Patel <[email protected]>
Varad Gupta <[email protected]>
Vinit Pandit <[email protected]>
Xiaochuan Ye <[email protected]>
Yernar Yergaziyev <[email protected]>
naveen <[email protected]>
Expand Down
37 changes: 6 additions & 31 deletions base/special/ldexp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,44 +182,19 @@ double stdlib_base_ldexp( const double frac, const int32_t exp );
```c
#include "stdlib/math/base/special/ldexp.h"
#include "stdlib/math/base/special/frexp.h"
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <inttypes.h>
#include <math.h>
static double rand_double() {
int r = rand();
return (double)r / ( (double)RAND_MAX + 1.0 );
}
int main( void ) {
double sign;
double frac;
int32_t exp;
double x;
double v;
double y;
int i;
for ( i = 0; i < 100; i++ ) {
if ( rand_double() < 0.5 ) {
sign = -1.0;
} else {
sign = 1.0;
}
// Generate a random number:
frac = rand_double() * 10.0;
exp = (int32_t)( rand_double()*616.0 ) - 308;
x = sign * frac * pow( 10.0, exp );
// Break the number into a normalized fraction and an integer power of two:
stdlib_base_frexp( x, &frac, &exp );
// Reconstitute the original number:
v = stdlib_base_ldexp( frac, exp );
const double frac[] = { 0.5, 5.0, 0.0, 3.5, 7.9 };
const int32_t exp[] = { 3, -2, 20, 39, 14 };
printf( "%e = %lf * 2^%" PRId32 " = %e\n", x, frac, exp, v );
for ( i = 0; i < 5; i++ ) {
y = stdlib_base_ldexp( frac[ i ], exp[ i ] );
printf( "ldexp(%lf, %d) = %lf\n", frac[ i ], exp[ i ], y );
}
}
```
Expand Down
11 changes: 6 additions & 5 deletions base/special/ldexp/benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var round = require( './../../../../base/special/round' );
var uniform = require( '@stdlib/random/array/uniform' );
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var isnan = require( './../../../../base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var ldexp = require( './../lib' );
Expand All @@ -36,11 +36,12 @@ bench( pkg, function benchmark( b ) {
var z;
var i;

x = uniform( 100, -10.0, 10.0 );
y = discreteUniform( 100, -1020.0, 1020.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*20.0 ) - 10.0;
y = round( randu()*2040.0 ) - 1020.0;
z = ldexp( x, y );
z = ldexp( x[ i % x.length ], y[ i % y.length ] );
if ( isnan( z ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
11 changes: 6 additions & 5 deletions base/special/ldexp/benchmark/benchmark.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var round = require( './../../../../base/special/round' );
var uniform = require( '@stdlib/random/array/uniform' );
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var isnan = require( './../../../../base/assert/is-nan' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;
Expand All @@ -45,11 +45,12 @@ bench( pkg+'::native', opts, function benchmark( b ) {
var z;
var i;

x = uniform( 100, -10.0, 10.0 );
y = discreteUniform( 100, -1020.0, 1020.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*20.0 ) - 10.0;
y = round( randu()*2040.0 ) - 1020.0;
z = ldexp( x, y );
z = ldexp( x[ i % x.length ], y[ i % y.length ] );
if ( isnan( z ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
13 changes: 8 additions & 5 deletions base/special/ldexp/benchmark/c/benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,20 @@ static double rand_double( void ) {
*/
static double benchmark( void ) {
double elapsed;
double x;
double y;
double x[ 100 ];
double y[ 100 ];
double z;
double t;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = ( rand_double() * 20.0 ) - 10.0;
y[ i ] = ( rand_double() * 2048.0 ) - 1024.0;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( rand_double()*20.0 ) - 10.0;
y = ( rand_double()*2048.0 ) - 1024.0;
z = ldexp( x, y );
z = ldexp( x[ i % 100 ], y[ i % 100 ] );
if ( z != z ) {
printf( "should not return NaN\n" );
break;
Expand Down
13 changes: 8 additions & 5 deletions base/special/ldexp/benchmark/c/cephes/benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,20 @@ static double rand_double( void ) {
*/
static double benchmark( void ) {
double elapsed;
double x;
double y;
double x[ 100 ];
double y[ 100 ];
double z;
double t;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = ( rand_double() * 20.0 ) - 10.0;
y[ i ] = ( rand_double() * 2048.0 ) - 1024.0;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( rand_double()*20.0 ) - 10.0;
y = ( rand_double()*2048.0 ) - 1024.0;
z = ldexp( x, y );
z = ldexp( x[ i % 100 ], y[ i % 100 ] );
if ( z != z ) {
printf( "should not return NaN\n" );
break;
Expand Down
13 changes: 8 additions & 5 deletions base/special/ldexp/benchmark/c/native/benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,20 @@ static double rand_double( void ) {
*/
static double benchmark( void ) {
double elapsed;
double x;
double y;
double x[ 100 ];
double y[ 100 ];
double z;
double t;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = ( rand_double() * 20.0 ) - 10.0;
y[ i ] = ( rand_double() * 2048.0 ) - 1024.0;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( rand_double()*20.0 ) - 10.0;
y = ( rand_double()*2048.0 ) - 1024.0;
z = stdlib_base_ldexp( x, y );
z = stdlib_base_ldexp( x[ i % 100 ], y[ i % 100 ] );
if ( z != z ) {
printf( "should not return NaN\n" );
break;
Expand Down
13 changes: 8 additions & 5 deletions base/special/ldexp/benchmark/cpp/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,20 @@ double rand_double() {
*/
double benchmark() {
double elapsed;
double x;
double y;
double x[ 100 ];
double y[ 100 ];
double z;
double t;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = ( rand_double() * 20.0 ) - 10.0;
y[ i ] = ( rand_double() * 2048.0 ) - 1024.0;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( rand_double()*20.0 ) - 10.0;
y = ( rand_double()*2048.0 ) - 1024.0;
z = ldexp( x, y );
z = ldexp( x[ i % 100 ], y[ i % 100 ] );
if ( z != z ) {
printf( "should not return NaN\n" );
break;
Expand Down
44 changes: 8 additions & 36 deletions base/special/ldexp/examples/c/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,47 +16,19 @@
* limitations under the License.
*/


#include "stdlib/math/base/special/ldexp.h"
#include "stdlib/math/base/special/frexp.h"
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <inttypes.h>
#include <math.h>

// TODO: replace use of `pow` with stdlib_base_pow()

static double rand_double() {
int r = rand();
return (double)r / ( (double)RAND_MAX + 1.0 );
}

int main( void ) {
double sign;
double frac;
int32_t exp;
double x;
double v;
int i;

for ( i = 0; i < 100; i++ ) {
if ( rand_double() < 0.5 ) {
sign = -1.0;
} else {
sign = 1.0;
}
// Generate a random number:
frac = rand_double() * 10.0;
exp = (int32_t)( rand_double()*616.0 ) - 308;
x = sign * frac * pow( 10.0, exp );

// Break the number into a normalized fraction and an integer power of two:
stdlib_base_frexp( x, &frac, &exp );
double y;
int i;

// Reconstitute the original number:
v = stdlib_base_ldexp( frac, exp );
const double frac[] = { 0.5, 5.0, 0.0, 3.5, 7.9 };
const int32_t exp[] = { 3, -2, 20, 39, 14 };

printf( "%e = %lf * 2^%" PRId32 " = %e\n", x, frac, exp, v );
}
for ( i = 0; i < 5; i++ ) {
y = stdlib_base_ldexp( frac[ i ], exp[ i ] );
printf( "ldexp(%lf, %d) = %lf\n", frac[ i ], exp[ i ], y );
}
}
3 changes: 1 addition & 2 deletions base/special/ldexp/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@
"@stdlib/constants/float64/min-base2-exponent-subnormal",
"@stdlib/constants/float64/max-base2-exponent",
"@stdlib/constants/float64/max-base2-exponent-subnormal",
"@stdlib/constants/float64/exponent-bias",
"@stdlib/math/base/special/frexp"
"@stdlib/constants/float64/exponent-bias"
]
},
{
Expand Down

0 comments on commit be7e4c8

Please sign in to comment.