Skip to content

Commit ee2c461

Browse files
committed
Apply suggested changes
1 parent 966df6f commit ee2c461

File tree

7 files changed

+54
-43
lines changed

7 files changed

+54
-43
lines changed

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

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ limitations under the License.
2020

2121
# sqrtpif
2222

23-
> Compute the principal [square root][@stdlib/math/base/special/sqrtf] of the product of π and a positive single-precision floating-point number.
23+
> Compute the principal [square root][@stdlib/math/base/special/sqrt] of the product of π and a positive single-precision floating-point number.
2424
2525
<section class="usage">
2626

@@ -32,7 +32,7 @@ var sqrtpif = require( '@stdlib/math/base/special/sqrtpif' );
3232

3333
#### sqrtpif( x )
3434

35-
Computes the principal [square root][@stdlib/math/base/special/sqrtf] of the product of π and a positive single-precision floating-point number.
35+
Computes the principal [square root][@stdlib/math/base/special/sqrt] of the product of π and a positive single-precision floating-point number.
3636

3737
```javascript
3838
var v = sqrtpif( 4.0 );
@@ -48,7 +48,7 @@ v = sqrtpif( NaN );
4848
// returns NaN
4949
```
5050

51-
For negative numbers, the principal [square root][@stdlib/math/base/special/sqrtf] is **not** defined.
51+
For negative numbers, the principal [square root][@stdlib/math/base/special/sqrt] is **not** defined.
5252

5353
```javascript
5454
var v = sqrtpif( -4.0 );
@@ -66,15 +66,14 @@ var v = sqrtpif( -4.0 );
6666
<!-- eslint no-undef: "error" -->
6767

6868
```javascript
69-
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
69+
var randu = require( '@stdlib/random/array/discrete-uniform' );
7070
var sqrtpif = require( '@stdlib/math/base/special/sqrtpif' );
7171

72-
var x;
73-
var i;
72+
var x = randu( 100, 0, 100 );
7473

74+
var i;
7575
for ( i = 0; i < 100; i++ ) {
76-
x = discreteUniform( 0, 100 );
77-
console.log( 'sqrtpif(%d) = %d', x, sqrtpif( x ) );
76+
console.log( 'sqrtpif(%d) = %d', x[ i ], sqrtpif( x[ i ] ) );
7877
}
7978
```
8079

@@ -110,14 +109,14 @@ for ( i = 0; i < 100; i++ ) {
110109

111110
#### stdlib_base_sqrtpif( x )
112111

113-
Computes the principal [square root][@stdlib/math/base/special/sqrtf] of the product of π and a positive single-precision floating-point number.
112+
Computes the principal [square root][@stdlib/math/base/special/sqrt] of the product of π and a positive single-precision floating-point number.
114113

115114
```c
116-
float x = stdlib_base_sqrtpif( 4.0 );
117-
// returns ~3.5449
115+
float x = stdlib_base_sqrtpif( 4.0f );
116+
// returns ~3.5449f
118117

119-
x = stdlib_base_sqrtpif( 10.0 );
120-
// returns ~5.60499
118+
x = stdlib_base_sqrtpif( 10.0f );
119+
// returns ~5.60499f
121120
```
122121

123122
The function accepts the following arguments:
@@ -152,14 +151,13 @@ float stdlib_base_sqrtpif( const float x );
152151
#include <stdio.h>
153152
154153
int main( void ) {
155-
float x;
154+
const float x[] = { 4.0f, 10.0f, 3.14f, -3.14f, 0.0f, 0.0f / 0.0f };
155+
156156
float v;
157157
int i;
158-
159-
for ( i = 0; i < 100; i++ ) {
160-
x = ( (float)rand() / (float)RAND_MAX ) * 100.0;
161-
v = stdlib_base_sqrtpif( x );
162-
printf( "sqrtpif(%f) = %f\n", x, v );
158+
for ( i = 0; i < 6; i++ ) {
159+
v = stdlib_base_sqrtpif( x[ i ] );
160+
printf( 'sqrtpif(%f) = %f', x[ i ], sqrtpif( x[ i ] ) );
163161
}
164162
}
165163
```
@@ -184,10 +182,10 @@ int main( void ) {
184182

185183
<section class="links">
186184

187-
[@stdlib/math/base/special/sqrtf]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/sqrtf
188-
189185
<!-- <related-links> -->
190186

187+
[@stdlib/math/base/special/sqrt]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/sqrt
188+
191189
<!-- </related-links> -->
192190

193191
</section>

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

Lines changed: 4 additions & 3 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 randu = require( '@stdlib/random/array/discrete-uniform' );
2525
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2626
var pkg = require( './../package.json' ).name;
2727
var sqrtpif = require( './../lib' );
@@ -34,10 +34,11 @@ bench( pkg, function benchmark( b ) {
3434
var y;
3535
var i;
3636

37+
x = randu( 100, 0, 100000.0 );
38+
3739
b.tic();
3840
for ( i = 0; i < b.iterations; i++ ) {
39-
x = ( randu()*100000.0 ) - 0.0;
40-
y = sqrtpif( x );
41+
y = sqrtpif( x[ i % x.length ] );
4142
if ( isnanf( y ) ) {
4243
b.fail( 'should not return NaN' );
4344
}

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

Lines changed: 4 additions & 3 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 randu = require( '@stdlib/random/array/discrete-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;
@@ -43,10 +43,11 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4343
var y;
4444
var i;
4545

46+
x = randu( 100, 0, 100000.0 );
47+
4648
b.tic();
4749
for ( i = 0; i < b.iterations; i++ ) {
48-
x = ( randu()*100000.0 ) - 0.0;
49-
y = sqrtpif( x );
50+
y = sqrtpif( x[ i % x.length ] );
5051
if ( isnanf( y ) ) {
5152
b.fail( 'should not return NaN' );
5253
}

lib/node_modules/@stdlib/math/base/special/sqrtpif/benchmark/c/benchmark.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,35 @@ static double tic( void ) {
7474
return (double)now.tv_sec + (double)now.tv_usec/1.0e6;
7575
}
7676

77+
/**
78+
* Generates a random number on the interval [0,1).
79+
*
80+
* @return random number
81+
*/
82+
static float rand_float( void ) {
83+
int r = rand();
84+
return (float)r / ( (float)RAND_MAX + 1.0f );
85+
}
86+
7787
/**
7888
* Runs a benchmark.
7989
*
8090
* @return elapsed time in seconds
8191
*/
8292
static double benchmark( void ) {
8393
double elapsed;
94+
float x[ 100 ];
8495
double t;
85-
float x;
8696
float y;
8797
int i;
8898

99+
for ( i = 0; i < 100; i++ ) {
100+
x[ i ] = ( 100000.0f * rand_float() );
101+
}
102+
89103
t = tic();
90104
for ( i = 0; i < ITERATIONS; i++ ) {
91-
x = ( (float)rand() * 100000.0 ) - 0.0;
92-
y = stdlib_base_sqrtpif( x );
105+
y = stdlib_base_sqrtpif( x[ i % 100 ] );
93106
if ( y != y ) {
94107
printf( "should not return NaN\n" );
95108
break;

lib/node_modules/@stdlib/math/base/special/sqrtpif/examples/c/example.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@
2121
#include <stdio.h>
2222

2323
int main( void ) {
24-
float x;
24+
const float x[] = { 4.0f, 10.0f, 3.14f, -3.14f, 0.0f, 0.0f / 0.0f };
25+
2526
float v;
2627
int i;
27-
28-
for ( i = 0; i < 100; i++ ) {
29-
x = ( (float)rand() / (float)RAND_MAX ) * 100.0;
30-
v = stdlib_base_sqrtpif( x );
31-
printf( "sqrtpif(%f) = %f\n", x, v );
28+
for ( i = 0; i < 6; i++ ) {
29+
v = stdlib_base_sqrtpif( x[ i ] );
30+
printf( 'sqrtpif(%f) = %f', x[ i ], sqrtpif( x[ i ] ) );
3231
}
3332
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@
1818

1919
'use strict';
2020

21-
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
21+
var randu = require( '@stdlib/random/array/discrete-uniform' );
2222
var sqrtpif = require( './../lib' );
2323

24-
var x;
25-
var i;
24+
var x = randu( 100, 0, 100 );
2625

26+
var i;
2727
for ( i = 0; i < 100; i++ ) {
28-
x = discreteUniform( 0, 100 );
29-
console.log( 'sqrtpif(%d) = %d', x, sqrtpif( x ) );
28+
console.log( 'sqrtpif(%d) = %d', x[ i ], sqrtpif( x[ i ] ) );
3029
}

lib/node_modules/@stdlib/math/base/special/sqrtpif/src/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
* @return output value
2828
*
2929
* @example
30-
* float out = stdlib_base_sqrtpif( 4.0 );
31-
* // returns 3.5449
30+
* float out = stdlib_base_sqrtpif( 4.0f );
31+
* // returns ~3.5449f
3232
*/
3333
float stdlib_base_sqrtpif( const float x ) {
3434
return stdlib_base_sqrtf( x * STDLIB_CONSTANT_FLOAT32_PI );

0 commit comments

Comments
 (0)