Skip to content

Commit 8900fbc

Browse files
refactor: update math/base/special/hypotf to follow latest project conventions
--- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: passed - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: failed ---
1 parent ba3d6e8 commit 8900fbc

File tree

9 files changed

+112
-78
lines changed

9 files changed

+112
-78
lines changed

lib/node_modules/@stdlib/math/base/special/hypotf/README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,22 @@ h = hypotf( 5.0, NaN );
8383
<!-- eslint no-undef: "error" -->
8484

8585
```javascript
86-
var randu = require( '@stdlib/random/base/randu' );
87-
var round = require( '@stdlib/math/base/special/round' );
86+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
8887
var hypotf = require( '@stdlib/math/base/special/hypotf' );
8988

89+
var len;
9090
var x;
9191
var y;
9292
var h;
9393
var i;
9494

95+
len = 100;
96+
x = discreteUniform( len, -50, 50 );
97+
y = discreteUniform( len, -50, 50 );
98+
9599
for ( i = 0; i < 100; i++ ) {
96-
x = round( randu()*100.0 ) - 50.0;
97-
y = round( randu()*100.0 ) - 50.0;
98-
h = hypotf( x, y );
99-
console.log( 'h(%d,%d) = %d', x, y, h );
100+
h = hypotf( x[ i ], y[ i ] );
101+
console.log( 'h(%d,%d) = %d', x[ i ], y[ i ], h );
100102
}
101103
```
102104

lib/node_modules/@stdlib/math/base/special/hypotf/benchmark/benchmark.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
2525
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2626
var pkg = require( './../package.json' ).name;
2727
var hypotf = require( './../lib' );
@@ -37,16 +37,24 @@ var opts = {
3737
// MAIN //
3838

3939
bench( pkg, function benchmark( b ) {
40+
var opts;
41+
var len;
4042
var x;
4143
var y;
4244
var z;
4345
var i;
4446

47+
opts = {
48+
'dtype': 'float32'
49+
};
50+
51+
len = 100;
52+
x = uniform( len, -50, 50, opts );
53+
y = uniform( len, -50, 50, opts );
54+
4555
b.tic();
4656
for ( i = 0; i < b.iterations; i++ ) {
47-
x = ( randu()*100.0 ) - 50.0;
48-
y = ( randu()*100.0 ) - 50.0;
49-
z = hypotf( x, y );
57+
z = hypotf( x[ i % len ], y[ i % len ] );
5058
if ( isnanf( z ) ) {
5159
b.fail( 'should not return NaN' );
5260
}
@@ -60,16 +68,24 @@ bench( pkg, function benchmark( b ) {
6068
});
6169

6270
bench( pkg+'::built-in', opts, function benchmark( b ) {
71+
var opts;
72+
var len;
6373
var x;
6474
var y;
6575
var z;
6676
var i;
6777

78+
opts = {
79+
'dtype': 'float32'
80+
};
81+
82+
len = 100;
83+
x = uniform( len, -50, 50, opts );
84+
y = uniform( len, -50, 50, opts );
85+
6886
b.tic();
6987
for ( i = 0; i < b.iterations; i++ ) {
70-
x = ( randu()*100.0 ) - 50.0;
71-
y = ( randu()*100.0 ) - 50.0;
72-
z = Math.hypot( x, y ); // eslint-disable-line stdlib/no-builtin-math
88+
z = Math.hypot( x[ i % len ], y[ i % len ] ); // eslint-disable-line stdlib/no-builtin-math
7389
if ( isnanf( z ) ) {
7490
b.fail( 'should not return NaN' );
7591
}

lib/node_modules/@stdlib/math/base/special/hypotf/benchmark/benchmark.native.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var randu = require( '@stdlib/random/base/randu' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
2626
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2727
var tryRequire = require( '@stdlib/utils/try-require' );
2828
var pkg = require( './../package.json' ).name;
@@ -39,16 +39,24 @@ var opts = {
3939
// MAIN //
4040

4141
bench( pkg+'::native', opts, function benchmark( b ) {
42+
var opts;
43+
var len;
4244
var x;
4345
var y;
4446
var z;
4547
var i;
4648

49+
opts = {
50+
'dtype': 'float32'
51+
};
52+
53+
len = 100;
54+
x = uniform( len, -50, 50, opts );
55+
y = uniform( len, -50, 50, opts );
56+
4757
b.tic();
4858
for ( i = 0; i < b.iterations; i++ ) {
49-
x = ( randu()*100.0 ) - 50.0;
50-
y = ( randu()*100.0 ) - 50.0;
51-
z = hypotf( x, y );
59+
z = hypotf( x[ i % len ], y[ i % len ] );
5260
if ( isnanf( z ) ) {
5361
b.fail( 'should not return NaN' );
5462
}

lib/node_modules/@stdlib/math/base/special/hypotf/benchmark/c/native/benchmark.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,19 @@ static float rand_float( void ) {
9292
static double benchmark( void ) {
9393
double elapsed;
9494
double t;
95-
float x;
96-
float y;
95+
float x[ 100 ];
96+
float y[ 100 ];
9797
float z;
9898
int i;
9999

100+
for ( i = 0; i < 100; i++ ) {
101+
x[ i ] = ( 100.0f * rand_float() ) - 50.0f;
102+
y[ i ] = ( 100.0f * rand_float() ) - 50.0f;
103+
}
104+
100105
t = tic();
101106
for ( i = 0; i < ITERATIONS; i++ ) {
102-
x = ( 100.0f*rand_float() ) - 50.0f;
103-
y = ( 100.0f*rand_float() ) - 50.0f;
104-
z = stdlib_base_hypotf( x, y );
107+
z = stdlib_base_hypotf( x[ i % 100 ], y[ i % 100 ] );
105108
if ( z != z ) {
106109
printf( "should not return NaN\n" );
107110
break;

lib/node_modules/@stdlib/math/base/special/hypotf/examples/index.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,20 @@
1818

1919
'use strict';
2020

21-
var randu = require( '@stdlib/random/base/randu' );
22-
var round = require( '@stdlib/math/base/special/round' );
21+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
2322
var hypotf = require( './../lib' );
2423

24+
var len;
2525
var x;
2626
var y;
2727
var h;
2828
var i;
2929

30+
len = 100;
31+
x = discreteUniform( len, -50, 50 );
32+
y = discreteUniform( len, -50, 50 );
33+
3034
for ( i = 0; i < 100; i++ ) {
31-
x = round( randu()*100.0 ) - 50.0;
32-
y = round( randu()*100.0 ) - 50.0;
33-
h = hypotf( x, y );
34-
console.log( 'h(%d,%d) = %d', x, y, h );
35+
h = hypotf( x[ i ], y[ i ] );
36+
console.log( 'h(%d,%d) = %d', x[ i ], y[ i ], h );
3537
}

lib/node_modules/@stdlib/math/base/special/hypotf/manifest.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
{
2929
"task": "build",
3030
"src": [
31-
"./src/hypotf.c"
31+
"./src/main.c"
3232
],
3333
"include": [
3434
"./include"
@@ -41,13 +41,14 @@
4141
"@stdlib/math/base/napi/binary",
4242
"@stdlib/math/base/assert/is-nanf",
4343
"@stdlib/math/base/assert/is-infinitef",
44-
"@stdlib/math/base/special/sqrtf"
44+
"@stdlib/math/base/special/sqrtf",
45+
"@stdlib/constants/float32/pinf"
4546
]
4647
},
4748
{
4849
"task": "benchmark",
4950
"src": [
50-
"./src/hypotf.c"
51+
"./src/main.c"
5152
],
5253
"include": [
5354
"./include"
@@ -59,13 +60,14 @@
5960
"dependencies": [
6061
"@stdlib/math/base/assert/is-nanf",
6162
"@stdlib/math/base/assert/is-infinitef",
62-
"@stdlib/math/base/special/sqrtf"
63+
"@stdlib/math/base/special/sqrtf",
64+
"@stdlib/constants/float32/pinf"
6365
]
6466
},
6567
{
6668
"task": "examples",
6769
"src": [
68-
"./src/hypotf.c"
70+
"./src/main.c"
6971
],
7072
"include": [
7173
"./include"
@@ -77,7 +79,8 @@
7779
"dependencies": [
7880
"@stdlib/math/base/assert/is-nanf",
7981
"@stdlib/math/base/assert/is-infinitef",
80-
"@stdlib/math/base/special/sqrtf"
82+
"@stdlib/math/base/special/sqrtf",
83+
"@stdlib/constants/float32/pinf"
8184
]
8285
}
8386
]

lib/node_modules/@stdlib/math/base/special/hypotf/src/hypotf.c renamed to lib/node_modules/@stdlib/math/base/special/hypotf/src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "stdlib/math/base/assert/is_nanf.h"
2121
#include "stdlib/math/base/assert/is_infinitef.h"
2222
#include "stdlib/math/base/special/sqrtf.h"
23-
#include <math.h>
23+
#include "stdlib/constants/float32/pinf.h"
2424

2525
/**
2626
* Computes the hypotenuse avoiding overflow and underflow (single-precision).

lib/node_modules/@stdlib/math/base/special/hypotf/test/test.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var PINF = require( '@stdlib/constants/float32/pinf' );
2626
var NINF = require( '@stdlib/constants/float32/ninf' );
2727
var EPS = require( '@stdlib/constants/float32/eps' );
2828
var absf = require( '@stdlib/math/base/special/absf' );
29-
var sqrt = require( '@stdlib/math/base/special/sqrt' );
29+
var sqrtf = require( '@stdlib/math/base/special/sqrtf' );
3030
var pow = require( '@stdlib/math/base/special/pow' );
3131
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
3232
var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' );
@@ -50,28 +50,28 @@ tape( 'the function returns `+infinity` if either argument is `+-infinity`', fun
5050
var h;
5151

5252
h = hypotf( PINF, 3.14 );
53-
t.strictEqual( h, PINF, 'returns +infinity' );
53+
t.strictEqual( h, PINF, 'returns expected value' );
5454

5555
h = hypotf( 3.14, PINF );
56-
t.strictEqual( h, PINF, 'returns +infinity' );
56+
t.strictEqual( h, PINF, 'returns expected value' );
5757

5858
h = hypotf( NINF, 3.14 );
59-
t.strictEqual( h, PINF, 'returns +infinity' );
59+
t.strictEqual( h, PINF, 'returns expected value' );
6060

6161
h = hypotf( 3.14, NINF );
62-
t.strictEqual( h, PINF, 'returns +infinity' );
62+
t.strictEqual( h, PINF, 'returns expected value' );
6363

6464
h = hypotf( PINF, PINF );
65-
t.strictEqual( h, PINF, 'returns +infinity' );
65+
t.strictEqual( h, PINF, 'returns expected value' );
6666

6767
h = hypotf( NINF, PINF );
68-
t.strictEqual( h, PINF, 'returns +infinity' );
68+
t.strictEqual( h, PINF, 'returns expected value' );
6969

7070
h = hypotf( PINF, NINF );
71-
t.strictEqual( h, PINF, 'returns +infinity' );
71+
t.strictEqual( h, PINF, 'returns expected value' );
7272

7373
h = hypotf( NINF, NINF );
74-
t.strictEqual( h, PINF, 'returns +infinity' );
74+
t.strictEqual( h, PINF, 'returns expected value' );
7575

7676
t.end();
7777
});
@@ -80,13 +80,13 @@ tape( 'the function returns `NaN` if either argument is `NaN`', function test( t
8080
var h;
8181

8282
h = hypotf( NaN, 3.14 );
83-
t.strictEqual( isnanf( h ), true, 'returns NaN' );
83+
t.strictEqual( isnanf( h ), true, 'returns expected value' );
8484

8585
h = hypotf( 3.14, NaN );
86-
t.strictEqual( isnanf( h ), true, 'returns NaN' );
86+
t.strictEqual( isnanf( h ), true, 'returns expected value' );
8787

8888
h = hypotf( NaN, NaN );
89-
t.strictEqual( isnanf( h ), true, 'returns NaN' );
89+
t.strictEqual( isnanf( h ), true, 'returns expected value' );
9090

9191
t.end();
9292
});
@@ -95,16 +95,16 @@ tape( 'the function returns `+0` if both arguments are `+-0`', function test( t
9595
var h;
9696

9797
h = hypotf( +0.0, +0.0 );
98-
t.strictEqual( isPositiveZerof( h ), true, 'returns +0' );
98+
t.strictEqual( isPositiveZerof( h ), true, 'returns expected value' );
9999

100100
h = hypotf( -0.0, +0.0 );
101-
t.strictEqual( isPositiveZerof( h ), true, 'returns +0' );
101+
t.strictEqual( isPositiveZerof( h ), true, 'returns expected value' );
102102

103103
h = hypotf( +0.0, -0.0 );
104-
t.strictEqual( isPositiveZerof( h ), true, 'returns +0' );
104+
t.strictEqual( isPositiveZerof( h ), true, 'returns expected value' );
105105

106106
h = hypotf( -0.0, -0.0 );
107-
t.strictEqual( isPositiveZerof( h ), true, 'returns +0' );
107+
t.strictEqual( isPositiveZerof( h ), true, 'returns expected value' );
108108

109109
t.end();
110110
});
@@ -139,21 +139,21 @@ tape( 'the function computes the hypotenuse (canonical inputs)', function test(
139139
var h;
140140

141141
h = hypotf( 3.0, 4.0 );
142-
t.strictEqual( h, 5.0, 'returns 5.0' );
142+
t.strictEqual( h, 5.0, 'returns expected value' );
143143

144144
h = hypotf( 6.0, 8.0 );
145-
t.strictEqual( h, 10.0, 'returns 10.0' );
145+
t.strictEqual( h, 10.0, 'returns expected value' );
146146

147147
h = hypotf( 5.0, 12.0 );
148-
t.strictEqual( h, 13.0, 'returns 13.0' );
148+
t.strictEqual( h, 13.0, 'returns expected value' );
149149

150150
t.end();
151151
});
152152

153153
tape( 'the function avoids overflow', function test( t ) {
154154
var h;
155155

156-
h = float64ToFloat32( sqrt( float64ToFloat32( float64ToFloat32( pow( 1.0e38, 2 ) ) + float64ToFloat32( pow( 1.0e38, 2 ) ) ) ) ); // eslint-disable-line max-len
156+
h = sqrtf( float64ToFloat32( float64ToFloat32( pow( 1.0e38, 2 ) ) + float64ToFloat32( pow( 1.0e38, 2 ) ) ) ); // eslint-disable-line max-len
157157
t.strictEqual( h, PINF, 'returns +infinity' );
158158

159159
h = hypotf( 1.0e38, 1.0e38 );
@@ -165,7 +165,7 @@ tape( 'the function avoids overflow', function test( t ) {
165165
tape( 'the function avoids underflow', function test( t ) {
166166
var h;
167167

168-
h = float64ToFloat32( sqrt( float64ToFloat32( float64ToFloat32( pow( 1.0e-45, 2 ) ) + float64ToFloat32( pow( 1.0e-45, 2 ) ) ) ) ); // eslint-disable-line max-len
168+
h = sqrtf( float64ToFloat32( float64ToFloat32( pow( 1.0e-45, 2 ) ) + float64ToFloat32( pow( 1.0e-45, 2 ) ) ) ); // eslint-disable-line max-len
169169
t.strictEqual( h, 0.0, 'returns 0' );
170170

171171
h = hypotf( 1.0e-45, 1.0e-45 );

0 commit comments

Comments
 (0)