Skip to content

Commit 66e8128

Browse files
committed
feat: add implementation
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: passed - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent e5ddcf5 commit 66e8128

File tree

21 files changed

+318
-676
lines changed

21 files changed

+318
-676
lines changed

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

Lines changed: 30 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -18,56 +18,47 @@ limitations under the License.
1818
1919
-->
2020

21-
# rempio2
21+
# rempio2f
2222

23-
> Compute `x - nπ/2 = r`.
23+
> Compute `x - nπ/2 = r` (single-precision).
2424
2525
<section class="usage">
2626

2727
## Usage
2828

2929
```javascript
30-
var rempio2 = require( '@stdlib/math/base/special/rempio2' );
30+
var rempio2f = require( '@stdlib/math/base/special/rempio2f' );
3131
```
3232

33-
#### rempio2( x, y )
33+
#### rempio2f( x, y )
3434

3535
Computes `x - nπ/2 = r`.
3636

3737
```javascript
38-
var y = [ 0.0, 0.0 ];
39-
var n = rempio2( 128.0, y );
38+
var y = [ 0.0 ];
39+
var n = rempio2f( 128.0, y );
4040
// returns 81
4141

4242
var y1 = y[ 0 ];
4343
// returns ~0.765
44-
45-
var y2 = y[ 1 ];
46-
// returns ~3.618e-17
4744
```
4845

49-
When `x` is `NaN` or infinite, the function returns `0` and sets the elements of `y` to `NaN`.
46+
When `x` is `NaN` or infinite, the function returns `0` and sets `y[0]` to `NaN`.
5047

5148
```javascript
52-
var y = [ 0.0, 0.0 ];
53-
var n = rempio2( NaN, y );
49+
var y = [ 0.0 ];
50+
var n = rempio2f( NaN, y );
5451
// returns 0
5552

5653
var y1 = y[ 0 ];
5754
// returns NaN
5855

59-
var y2 = y[ 1 ];
60-
// returns NaN
61-
62-
y = [ 0.0, 0.0 ];
63-
n = rempio2( Infinity, y );
56+
y = [ 0.0 ];
57+
n = rempio2f( Infinity, y );
6458
// returns 0
6559

6660
y1 = y[ 0 ];
6761
// returns NaN
68-
69-
y2 = y[ 1 ];
70-
// returns NaN
7162
```
7263

7364
</section>
@@ -80,8 +71,8 @@ y2 = y[ 1 ];
8071

8172
## Notes
8273

83-
- The function returns `n` and stores the remainder `r` as two numbers in `y`, such that `y[0]+y[1] = r`.
84-
- For input values larger than `2^20*π/2` in magnitude, the function **only** returns the last three binary digits of `n` and not the full result.
74+
- The function returns `n` and stores the remainder `r` as `y[0]`.
75+
- For input values larger than `2^28*π/2` in magnitude, the function **only** returns the last three binary digits of `n` and not the full result.
8576

8677
</section>
8778

@@ -95,16 +86,16 @@ y2 = y[ 1 ];
9586

9687
```javascript
9788
var linspace = require( '@stdlib/array/base/linspace' );
98-
var rempio2 = require( '@stdlib/math/base/special/rempio2' );
89+
var rempio2f = require( '@stdlib/math/base/special/rempio2f' );
9990

10091
var x = linspace( 0.0, 100.0, 100 );
101-
var y = [ 0.0, 0.0 ];
92+
var y = [ 0.0 ];
10293
var n;
10394
var i;
10495

10596
for ( i = 0; i < x.length; i++ ) {
106-
n = rempio2( x[ i ], y );
107-
console.log( '%d - %dπ/2 = %d + %d', x[ i ], n, y[ 0 ], y[ 1 ] );
97+
n = rempio2f( x[ i ], y );
98+
console.log( '%d - %dπ/2 = %d', x[ i ], n, y[ 0 ] );
10899
}
109100
```
110101

@@ -135,30 +126,28 @@ for ( i = 0; i < x.length; i++ ) {
135126
### Usage
136127

137128
```c
138-
#include "stdlib/math/base/special/rempio2.h"
129+
#include "stdlib/math/base/special/rempio2f.h"
139130
```
140131

141-
#### stdlib_base_rempio2( x, &rem1, &rem2 )
132+
#### stdlib_base_rempio2f( x, &rem )
142133

143-
Computes `x - nπ/2 = r`.
134+
Computes `x - nπ/2 = r` (single-precision).
144135

145136
```c
146137
#include <stdint.h>
147138

148-
double rem1;
149-
double rem2;
139+
double rem;
150140

151-
int32_t n = stdlib_base_rempio2( 4.0, &rem1, &rem2 );
141+
int32_t n = stdlib_base_rempio2f( 4.0f, &rem );
152142
```
153143

154144
The function accepts the following arguments:
155145

156-
- **x**: `[in] double` input value.
157-
- **rem1**: `[out] double*` destination for first remainder number.
158-
- **rem2**: `[out] double*` destination for second remainder number.
146+
- **x**: `[in] float` input value.
147+
- **rem**: `[out] double*` destination for the remainder.
159148

160149
```c
161-
int32_t stdlib_base_rempio2( const double x, double *rem1, double *rem2 );
150+
int32_t stdlib_base_rempio2f( const float x, double *rem );
162151
```
163152
164153
</section>
@@ -169,10 +158,6 @@ int32_t stdlib_base_rempio2( const double x, double *rem1, double *rem2 );
169158
170159
<section class="notes">
171160
172-
### Notes
173-
174-
- The function returns `n` and stores the remainder `r` as two numbers in `rem1` and `rem2`, respectively, such that `rem1+rem2 = r`.
175-
176161
</section>
177162
178163
<!-- /.notes -->
@@ -184,21 +169,20 @@ int32_t stdlib_base_rempio2( const double x, double *rem1, double *rem2 );
184169
### Examples
185170
186171
```c
187-
#include "stdlib/math/base/special/rempio2.h"
172+
#include "stdlib/math/base/special/rempio2f.h"
188173
#include <stdio.h>
189174
#include <stdint.h>
190175
#include <inttypes.h>
191176
192177
int main( void ) {
193-
const double x[] = { 0.0, 1.0, 4.0, 128.0 };
178+
const double x[] = { 0.0f, 1.0f, 4.0f, 128.0f };
194179
195-
double rem1;
196-
double rem2;
180+
double rem;
197181
int32_t n;
198182
int i;
199183
for ( i = 0; i < 4; i++ ) {
200-
n = stdlib_base_rempio2( x[ i ], &rem1, &rem2 );
201-
printf( "%lf - %"PRId32"π/2 = %lf + %lf\n", x[ i ], n, rem1, rem2 );
184+
n = stdlib_base_rempio2f( x[ i ], &rem );
185+
printf( "%lf - %"PRId32"π/2 = %lf\n", x[ i ], n, rem );
202186
}
203187
}
204188
```

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

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

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/array/uniform' );
25-
var isnan = require( '@stdlib/math/base/assert/is-nan' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
25+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2626
var pkg = require( './../package.json' ).name;
27-
var rempio2 = require( './../lib' );
27+
var rempio2f = require( './../lib' );
2828

2929

3030
// MAIN //
@@ -35,18 +35,20 @@ bench( pkg, function benchmark( b ) {
3535
var n;
3636
var i;
3737

38-
y = [ 0.0, 0.0 ];
39-
x = randu( 100, -100.0, 100.0 );
38+
y = [ 0.0 ];
39+
x = uniform( 100, -100.0, 100.0, {
40+
'dtype': 'float32'
41+
});
4042

4143
b.tic();
4244
for ( i = 0; i < b.iterations; i++ ) {
43-
n = rempio2( x[ i % x.length ], y );
44-
if ( isnan( n ) ) {
45+
n = rempio2f( x[ i % x.length ], y );
46+
if ( isnanf( n ) || isnanf( y[0] ) ) {
4547
b.fail( 'should not return NaN' );
4648
}
4749
}
4850
b.toc();
49-
if ( isnan( n ) || isnan( y[0] ) || isnan( y[1] ) ) {
51+
if ( isnanf( n ) || isnanf( y[0] ) ) {
5052
b.fail( 'should not return NaN' );
5153
}
5254
b.pass( 'benchmark finished' );

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,18 @@
2222

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var randu = require( '@stdlib/random/array/uniform' );
26-
var isnan = require( '@stdlib/math/base/assert/is-nan' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
26+
var Float64Array = require( '@stdlib/array/float64' );
27+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2728
var tryRequire = require( '@stdlib/utils/try-require' );
2829
var pkg = require( './../package.json' ).name;
2930

3031

3132
// VARIABLES //
3233

33-
var rempio2 = tryRequire( resolve( __dirname, './../lib/native.js' ) );
34+
var rempio2f = tryRequire( resolve( __dirname, './../lib/native.js' ) );
3435
var opts = {
35-
'skip': ( rempio2 instanceof Error )
36+
'skip': ( rempio2f instanceof Error )
3637
};
3738

3839

@@ -44,18 +45,20 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4445
var n;
4546
var i;
4647

47-
y = [ 0.0, 0.0 ];
48-
x = randu( 100, -100.0, 100.0 );
48+
y = new Float64Array( [ 0.0 ] );
49+
x = uniform( 100, -100.0, 100.0, {
50+
'dtype': 'float32'
51+
});
4952

5053
b.tic();
5154
for ( i = 0; i < b.iterations; i++ ) {
52-
n = rempio2( x[ i % x.length ], y );
53-
if ( isnan( n ) ) {
55+
n = rempio2f( x[ i % x.length ], y );
56+
if ( isnanf( n ) || isnanf( y[0] ) ) {
5457
b.fail( 'should not return NaN' );
5558
}
5659
}
5760
b.toc();
58-
if ( isnan( n ) || isnan( y[0] ) || isnan( y[1] ) ) {
61+
if ( isnanf( n ) || isnanf( y[0] ) ) {
5962
b.fail( 'should not return NaN' );
6063
}
6164
b.pass( 'benchmark finished' );

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
* limitations under the License.
1717
*/
1818

19-
#include "stdlib/math/base/special/rempio2.h"
19+
#include "stdlib/math/base/special/rempio2f.h"
2020
#include <stdlib.h>
2121
#include <stdio.h>
2222
#include <math.h>
2323
#include <time.h>
2424
#include <sys/time.h>
2525

26-
#define NAME "rempio2"
26+
#define NAME "rempio2f"
2727
#define ITERATIONS 1000000
2828
#define REPEATS 3
2929

@@ -79,9 +79,9 @@ static double tic( void ) {
7979
*
8080
* @return random number
8181
*/
82-
static double rand_double( void ) {
82+
static float rand_float( void ) {
8383
int r = rand();
84-
return (double)r / ( (double)RAND_MAX + 1.0 );
84+
return (float)r / ( (float)RAND_MAX + 1.0f );
8585
}
8686

8787
/**
@@ -90,28 +90,27 @@ static double rand_double( void ) {
9090
* @return elapsed time in seconds
9191
*/
9292
static double benchmark( void ) {
93-
double x[ 100 ];
93+
float x[ 100 ];
9494
double elapsed;
95-
double rem1;
96-
double rem2;
95+
double rem;
9796
double y;
9897
double t;
9998
int i;
10099

101100
for ( i = 0; i < 100; i++ ) {
102-
x[ i ] = ( rand_double() * 200.0 ) - 100.0;
101+
x[ i ] = ( rand_float() * 200.0f ) - 100.0f;
103102
}
104103

105104
t = tic();
106105
for ( i = 0; i < ITERATIONS; i++ ) {
107-
y = stdlib_base_rempio2( x[ i % 100 ], &rem1, &rem2 );
108-
if ( y != y ) {
106+
y = stdlib_base_rempio2f( x[ i%100 ], &rem );
107+
if ( y != y && rem != rem ) {
109108
printf( "should not return NaN\n" );
110109
break;
111110
}
112111
}
113112
elapsed = tic() - t;
114-
if ( y != y ) {
113+
if ( y != y && rem != rem ) {
115114
printf( "should not return NaN\n" );
116115
}
117116
return elapsed;

lib/node_modules/@stdlib/math/base/special/rempio2f/docs/repl.txt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11

22
{{alias}}( x, y )
3-
Computes `x - nπ/2 = r`.
3+
Computes `x - nπ/2 = r` (single-precision).
44

5-
The function returns `n` and stores the remainder `r` as the two numbers
6-
`y[0]` and `y[1]`, such that `y[0] + y[1] = r`.
5+
The function returns `n` and stores the remainder `r` as `y[0]`.
76

8-
For input values larger than `2^20 * π/2` in magnitude, the function only
7+
For input values larger than `2^28 * π/2` in magnitude, the function only
98
returns the last three binary digits of `n` and not the full result.
109

1110
Parameters
@@ -14,7 +13,7 @@
1413
Input value.
1514

1615
y: Array|TypedArray|Object
17-
Remainder elements.
16+
Remainder element.
1817

1918
Returns
2019
-------
@@ -23,13 +22,11 @@
2322

2423
Examples
2524
--------
26-
> var y = [ 0.0, 0.0 ];
25+
> var y = [ 0.0 ];
2726
> var n = {{alias}}( 128.0, y )
2827
81
2928
> var y1 = y[ 0 ]
3029
~0.765
31-
> var y2 = y[ 1 ]
32-
~3.618e-17
3330

3431

3532
See Also

0 commit comments

Comments
 (0)