Skip to content

Commit

Permalink
chore: update descriptions, test descriptions and refactor benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
gunjjoshi committed Aug 23, 2024
1 parent 66a6ca9 commit a0c0b4e
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 40 deletions.
6 changes: 3 additions & 3 deletions lib/node_modules/@stdlib/math/base/special/maxf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ limitations under the License.

# maxf

> Return the maximum value (single-precision).
> Return the maximum single-precision floating-point number.
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

Expand All @@ -42,7 +42,7 @@ var maxf = require( '@stdlib/math/base/special/maxf' );

#### maxf( x, y )

Returns the maximum value (single-precision).
Returns the maximum single-precision floating-point number.

```javascript
var v = maxf( 4.2, 3.14 );
Expand Down Expand Up @@ -131,7 +131,7 @@ for ( i = 0; i < 100; i++ ) {

#### stdlib_base_maxf( x, y )

Returns the maximum value (single-precision).
Returns the maximum single-precision floating-point number.

```c
float out = stdlib_base_maxf( 4.2f, 3.14f );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var randu = require( '@stdlib/random/array/uniform' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var pkg = require( './../package.json' ).name;
var maxf = require( './../lib' );
Expand All @@ -35,11 +35,12 @@ bench( pkg, function benchmark( b ) {
var z;
var i;

x = randu( 100, -100.0, 100.0 );
y = randu( 100, -100.0, 100.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu() * 1000.0 ) - 500.0;
y = ( randu() * 1000.0 ) - 500.0;
z = maxf( x, y );
z = maxf( x[ i % x.length ], y[ i % y.length ] );
if ( isnanf( z ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

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

x = randu( 100, -100.0, 100.0 );
y = randu( 100, -100.0, 100.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu() * 200.0 ) - 100.0;
y = ( randu() * 200.0 ) - 100.0;
z = maxf( x, y );
z = maxf( x[ i % x.length ], y[ i % y.length ] );
if ( isnanf( z ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,19 @@ static float rand_float( void ) {
static double benchmark( void ) {
double elapsed;
double t;
float x;
float y;
float x[ 100 ];
float y[ 100 ];
float z;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = ( 200.0f * rand_float() ) - 100.0f;
y[ i ] = ( 200.0f * rand_float() ) - 100.0f;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 200.0f * rand_float() ) - 100.0f;
y = ( 200.0f * rand_float() ) - 100.0f;
z = stdlib_base_maxf( x, y );
z = stdlib_base_maxf( x[ i % 100 ], y[ i % 100 ] );
if ( z != z ) {
printf( "should not return NaN\n" );
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

{{alias}}( x, y )
Returns the maximum value (single-precision).
Returns the maximum single-precision floating-point number.

If any argument is `NaN`, the function returns `NaN`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// TypeScript Version: 4.1

/**
* Returns the maximum value (single-precision).
* Returns the maximum single-precision floating-point number.
*
* @param x - first number
* @param y - second number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extern "C" {
#endif

/**
* Returns the maximum value (single-precision).
* Returns the maximum single-precision floating-point number.
*/
float stdlib_base_maxf( const float x, const float y );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
'use strict';

/**
* Return the maximum value (single-precision).
* Return the maximum single-precision floating-point number.
*
* @module @stdlib/math/base/special/maxf
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var PINF = require( '@stdlib/constants/float32/pinf' );
// MAIN //

/**
* Returns the maximum value (single-precision).
* Returns the maximum single-precision floating-point number.
*
* @param {number} x - first number
* @param {number} y - second number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var addon = require( './../src/addon.node' );
// MAIN //

/**
* Returns the maximum value (single-precision).
* Returns the maximum single-precision floating-point number.
*
* @private
* @param {number} x - first number
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@stdlib/math/base/special/maxf",
"version": "0.0.0",
"description": "Return the maximum value (single-precision).",
"description": "Return the maximum single-precision floating-point number.",
"license": "Apache-2.0",
"author": {
"name": "The Stdlib Authors",
Expand Down
2 changes: 1 addition & 1 deletion lib/node_modules/@stdlib/math/base/special/maxf/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "stdlib/constants/float32/pinf.h"

/**
* Returns the maximum value (single-precision).
* Returns the maximum single-precision floating-point number.
*
* @param x first number
* @param y second number
Expand Down
16 changes: 8 additions & 8 deletions lib/node_modules/@stdlib/math/base/special/maxf/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ tape( 'the function returns `+Infinity` if provided `+Infinity`', function test(
var v;

v = maxf( PINF, 3.14 );
t.strictEqual( v, PINF, 'returns +infinity' );
t.strictEqual( v, PINF, 'returns expected value' );

v = maxf( 3.14, PINF );
t.strictEqual( v, PINF, 'returns +infinity' );
t.strictEqual( v, PINF, 'returns expected value' );

t.end();
});
Expand All @@ -65,16 +65,16 @@ tape( 'the function returns a correctly signed zero', function test( t ) {
var v;

v = maxf( +0.0, -0.0 );
t.strictEqual( isPositiveZerof( v ), true, 'returns +0' );
t.strictEqual( isPositiveZerof( v ), true, 'returns expected value' );

v = maxf( -0.0, +0.0 );
t.strictEqual( isPositiveZerof( v ), true, 'returns +0' );
t.strictEqual( isPositiveZerof( v ), true, 'returns expected value' );

v = maxf( -0.0, -0.0 );
t.strictEqual( isNegativeZerof( v ), true, 'returns -0' );
t.strictEqual( isNegativeZerof( v ), true, 'returns expected value' );

v = maxf( +0.0, +0.0 );
t.strictEqual( isPositiveZerof( v ), true, 'returns +0' );
t.strictEqual( isPositiveZerof( v ), true, 'returns expected value' );

t.end();
});
Expand All @@ -83,10 +83,10 @@ tape( 'the function returns the maximum value', function test( t ) {
var v;

v = maxf( float64ToFloat32( 4.2 ), float64ToFloat32( 3.14 ) );
t.strictEqual( v, float64ToFloat32( 4.2 ), 'returns max value' );
t.strictEqual( v, float64ToFloat32( 4.2 ), 'returns expected value' );

v = maxf( float64ToFloat32( -4.2 ), float64ToFloat32( 3.14 ) );
t.strictEqual( v, float64ToFloat32( 3.14 ), 'returns max value' );
t.strictEqual( v, float64ToFloat32( 3.14 ), 'returns expected value' );

t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ tape( 'the function returns `+Infinity` if provided `+Infinity`', opts, function
var v;

v = maxf( PINF, 3.14 );
t.strictEqual( v, PINF, 'returns +infinity' );
t.strictEqual( v, PINF, 'returns expected value' );

v = maxf( 3.14, PINF );
t.strictEqual( v, PINF, 'returns +infinity' );
t.strictEqual( v, PINF, 'returns expected value' );

t.end();
});
Expand All @@ -74,16 +74,16 @@ tape( 'the function returns a correctly signed zero', opts, function test( t ) {
var v;

v = maxf( +0.0, -0.0 );
t.strictEqual( isPositiveZerof( v ), true, 'returns +0' );
t.strictEqual( isPositiveZerof( v ), true, 'returns expected value' );

v = maxf( -0.0, +0.0 );
t.strictEqual( isPositiveZerof( v ), true, 'returns +0' );
t.strictEqual( isPositiveZerof( v ), true, 'returns expected value' );

v = maxf( -0.0, -0.0 );
t.strictEqual( isNegativeZerof( v ), true, 'returns -0' );
t.strictEqual( isNegativeZerof( v ), true, 'returns expected value' );

v = maxf( +0.0, +0.0 );
t.strictEqual( isPositiveZerof( v ), true, 'returns +0' );
t.strictEqual( isPositiveZerof( v ), true, 'returns expected value' );

t.end();
});
Expand All @@ -92,10 +92,10 @@ tape( 'the function returns the maximum value', opts, function test( t ) {
var v;

v = maxf( float64ToFloat32( 4.2 ), float64ToFloat32( 3.14 ) );
t.strictEqual( v, float64ToFloat32( 4.2 ), 'returns max value' );
t.strictEqual( v, float64ToFloat32( 4.2 ), 'returns expected value' );

v = maxf( float64ToFloat32( -4.2 ), float64ToFloat32( 3.14 ) );
t.strictEqual( v, float64ToFloat32( 3.14 ), 'returns max value' );
t.strictEqual( v, float64ToFloat32( 3.14 ), 'returns expected value' );

t.end();
});

0 comments on commit a0c0b4e

Please sign in to comment.