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
18 changes: 7 additions & 11 deletions lib/node_modules/@stdlib/math/base/special/hypot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,16 @@ h = hypot( 5.0, NaN );
<!-- eslint no-undef: "error" -->

```javascript
var randu = require( '@stdlib/random/base/randu' );
var round = require( '@stdlib/math/base/special/round' );
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var hypot = require( '@stdlib/math/base/special/hypot' );

var x;
var y;
var h;
var i;
var len = 100;
var x = discreteUniform( len, -50, 50 );
var y = discreteUniform( len, -50, 50 );

for ( i = 0; i < 100; i++ ) {
x = round( randu()*100.0 ) - 50.0;
y = round( randu()*100.0 ) - 50.0;
h = hypot( x, y );
console.log( 'h(%d,%d) = %d', x, y, h );
var i;
for ( i = 0; i < len; i++ ) {
console.log( 'h(%d,%d) = %d', x[ i ], y[ i ], hypot( x[ i ], y[ i ] ) );
}
```

Expand Down
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 isnan = require( '@stdlib/math/base/assert/is-nan' );
var uniform = require( '@stdlib/random/array/uniform' );
var pkg = require( './../package.json' ).name;
var hypot = require( './../lib' );

Expand All @@ -37,16 +37,19 @@ var opts = {
// MAIN //

bench( pkg, function benchmark( b ) {
var len;
var x;
var y;
var z;
var i;

len = 100;
x = uniform( len, -50, 50 );
y = uniform( len, -50, 50 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*100.0 ) - 50.0;
y = ( randu()*100.0 ) - 50.0;
z = hypot( x, y );
z = hypot( x[ i % len ], y[ i % len ] );
if ( isnan( z ) ) {
b.fail( 'should not return NaN' );
}
Expand All @@ -60,16 +63,19 @@ bench( pkg, function benchmark( b ) {
});

bench( pkg+'::built-in', opts, function benchmark( b ) {
var len;
var x;
var y;
var z;
var i;

len = 100;
x = uniform( len, -50, 50 );
y = uniform( len, -50, 50 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*100.0 ) - 50.0;
y = ( randu()*100.0 ) - 50.0;
z = Math.hypot( x, y ); // eslint-disable-line stdlib/no-builtin-math
z = Math.hypot( x[ i % len ], y[ i % len ] ); // eslint-disable-line stdlib/no-builtin-math
if ( isnan( z ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
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 isnan = require( '@stdlib/math/base/assert/is-nan' );
var uniform = require( '@stdlib/random/array/uniform' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;

Expand All @@ -39,16 +39,19 @@ var opts = {
// MAIN //

bench( pkg+'::native', opts, function benchmark( b ) {
var len;
var x;
var y;
var z;
var i;

len = 100;
x = uniform( len, -50, 50 );
y = uniform( len, -50, 50 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*100.0 ) - 50.0;
y = ( randu()*100.0 ) - 50.0;
z = hypot( x, y );
z = hypot( x[ i % len ], y[ i % len ] );
if ( isnan( z ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
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() * 100.0 ) - 50.0;
y[ i ] = ( rand_double() * 100.0 ) - 50.0;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( 100.0*rand_double() ) - 50.0;
y = ( 100.0*rand_double() ) - 50.0;
z = stdlib_base_hypot( x, y );
z = stdlib_base_hypot( x[ i % 100 ], y[ i % 100 ] );
if ( z != z ) {
printf( "should not return NaN\n" );
break;
Expand Down
18 changes: 7 additions & 11 deletions lib/node_modules/@stdlib/math/base/special/hypot/examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,14 @@

'use strict';

var randu = require( '@stdlib/random/base/randu' );
var round = require( '@stdlib/math/base/special/round' );
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var hypot = require( './../lib' );

var x;
var y;
var h;
var i;
var len = 100;
var x = discreteUniform( len, -50, 50 );
var y = discreteUniform( len, -50, 50 );

for ( i = 0; i < 100; i++ ) {
x = round( randu()*100.0 ) - 50.0;
y = round( randu()*100.0 ) - 50.0;
h = hypot( x, y );
console.log( 'h(%d,%d) = %d', x, y, h );
var i;
for ( i = 0; i < len; i++ ) {
console.log( 'h(%d,%d) = %d', x[ i ], y[ i ], hypot( x[ i ], y[ i ] ) );
}
15 changes: 9 additions & 6 deletions lib/node_modules/@stdlib/math/base/special/hypot/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
{
"task": "build",
"src": [
"./src/hypot.c"
"./src/main.c"
],
"include": [
"./include"
Expand All @@ -41,13 +41,14 @@
"@stdlib/math/base/napi/binary",
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/assert/is-infinite",
"@stdlib/math/base/special/sqrt"
"@stdlib/math/base/special/sqrt",
"@stdlib/constants/float64/pinf"
]
},
{
"task": "benchmark",
"src": [
"./src/hypot.c"
"./src/main.c"
],
"include": [
"./include"
Expand All @@ -59,13 +60,14 @@
"dependencies": [
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/assert/is-infinite",
"@stdlib/math/base/special/sqrt"
"@stdlib/math/base/special/sqrt",
"@stdlib/constants/float64/pinf"
]
},
{
"task": "examples",
"src": [
"./src/hypot.c"
"./src/main.c"
],
"include": [
"./include"
Expand All @@ -77,7 +79,8 @@
"dependencies": [
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/assert/is-infinite",
"@stdlib/math/base/special/sqrt"
"@stdlib/math/base/special/sqrt",
"@stdlib/constants/float64/pinf"
]
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "stdlib/math/base/assert/is_nan.h"
#include "stdlib/math/base/assert/is_infinite.h"
#include "stdlib/math/base/special/sqrt.h"
#include <math.h>
#include "stdlib/constants/float64/pinf.h"

/**
* Computes the hypotenuse avoiding overflow and underflow.
Expand All @@ -41,7 +41,7 @@ double stdlib_base_hypot( const double x, const double y ) {
return 0.0 / 0.0; // NaN
}
if ( stdlib_base_is_infinite( x ) || stdlib_base_is_infinite( y ) ) {
return HUGE_VAL;
return STDLIB_CONSTANT_FLOAT64_PINF;
}
a = x;
b = y;
Expand All @@ -60,5 +60,5 @@ double stdlib_base_hypot( const double x, const double y ) {
return 0.0;
}
b /= a;
return a * stdlib_base_sqrt( 1.0 + (b*b) );
return a * stdlib_base_sqrt( 1.0 + ( b * b ) );
}
38 changes: 19 additions & 19 deletions lib/node_modules/@stdlib/math/base/special/hypot/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,28 +49,28 @@ tape( 'the function returns `+infinity` if either argument is `+-infinity`', fun
var h;

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

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

h = hypot( NINF, 3.14 );
t.strictEqual( h, PINF, 'returns +infinity' );
t.strictEqual( h, PINF, 'returns expected value' );

h = hypot( 3.14, NINF );
t.strictEqual( h, PINF, 'returns +infinity' );
t.strictEqual( h, PINF, 'returns expected value' );

h = hypot( PINF, PINF );
t.strictEqual( h, PINF, 'returns +infinity' );
t.strictEqual( h, PINF, 'returns expected value' );

h = hypot( NINF, PINF );
t.strictEqual( h, PINF, 'returns +infinity' );
t.strictEqual( h, PINF, 'returns expected value' );

h = hypot( PINF, NINF );
t.strictEqual( h, PINF, 'returns +infinity' );
t.strictEqual( h, PINF, 'returns expected value' );

h = hypot( NINF, NINF );
t.strictEqual( h, PINF, 'returns +infinity' );
t.strictEqual( h, PINF, 'returns expected value' );

t.end();
});
Expand All @@ -79,13 +79,13 @@ tape( 'the function returns `NaN` if either argument is `NaN`', function test( t
var h;

h = hypot( NaN, 3.14 );
t.strictEqual( isnan( h ), true, 'returns NaN' );
t.strictEqual( isnan( h ), true, 'returns expected value' );

h = hypot( 3.14, NaN );
t.strictEqual( isnan( h ), true, 'returns NaN' );
t.strictEqual( isnan( h ), true, 'returns expected value' );

h = hypot( NaN, NaN );
t.strictEqual( isnan( h ), true, 'returns NaN' );
t.strictEqual( isnan( h ), true, 'returns expected value' );

t.end();
});
Expand All @@ -94,16 +94,16 @@ tape( 'the function returns `+0` if both arguments are `+-0`', function test( t
var h;

h = hypot( +0.0, +0.0 );
t.strictEqual( isPositiveZero( h ), true, 'returns +0' );
t.strictEqual( isPositiveZero( h ), true, 'returns expected value' );

h = hypot( -0.0, +0.0 );
t.strictEqual( isPositiveZero( h ), true, 'returns +0' );
t.strictEqual( isPositiveZero( h ), true, 'returns expected value' );

h = hypot( +0.0, -0.0 );
t.strictEqual( isPositiveZero( h ), true, 'returns +0' );
t.strictEqual( isPositiveZero( h ), true, 'returns expected value' );

h = hypot( -0.0, -0.0 );
t.strictEqual( isPositiveZero( h ), true, 'returns +0' );
t.strictEqual( isPositiveZero( h ), true, 'returns expected value' );

t.end();
});
Expand Down Expand Up @@ -138,13 +138,13 @@ tape( 'the function computes the hypotenuse (canonical inputs)', function test(
var h;

h = hypot( 3.0, 4.0 );
t.strictEqual( h, 5.0, 'returns 5.0' );
t.strictEqual( h, 5.0, 'returns expected value' );

h = hypot( 6.0, 8.0 );
t.strictEqual( h, 10.0, 'returns 10.0' );
t.strictEqual( h, 10.0, 'returns expected value' );

h = hypot( 5.0, 12.0 );
t.strictEqual( h, 13.0, 'returns 13.0' );
t.strictEqual( h, 13.0, 'returns expected value' );

t.end();
});
Expand All @@ -153,7 +153,7 @@ tape( 'the function avoids overflow', function test( t ) {
var h;

h = sqrt( pow( 1.0e308, 2 ) + pow( 1.0e308, 2 ) );
t.strictEqual( h, PINF, 'returns +infinity' );
t.strictEqual( h, PINF, 'returns expected value' );

h = hypot( 1.0e308, 1.0e308 );
t.strictEqual( h, 1.4142135623730951e308, 'avoids overflow' );
Expand Down
Loading
Loading