Skip to content

Commit 0df78ac

Browse files
committed
fix: refactor addon, update docs, and update tests
1 parent 3da67fe commit 0df78ac

File tree

9 files changed

+245
-293
lines changed

9 files changed

+245
-293
lines changed

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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var rempio2 = require( '@stdlib/math/base/special/rempio2' );
3232

3333
#### rempio2( x, y )
3434

35-
Computes `x - nπ/2 = r`. The function returns `n` and stores the remainder `r` as two numbers in `y`, such that `y[0]+y[1] = r`.
35+
Computes `x - nπ/2 = r`.
3636

3737
```javascript
3838
var y = [ 0.0, 0.0 ];
@@ -46,7 +46,7 @@ var y2 = y[ 1 ];
4646
// returns ~3.618e-17
4747
```
4848

49-
When `x` is `NaN` or infinite, the function returns zero and sets the elements of `y` to `NaN`.
49+
When `x` is `NaN` or infinite, the function returns `0` and sets the elements of `y` to `NaN`.
5050

5151
```javascript
5252
var y = [ 0.0, 0.0 ];
@@ -80,6 +80,7 @@ y2 = y[ 1 ];
8080

8181
## Notes
8282

83+
- The function returns `n` and stores the remainder `r` as two numbers in `y`, such that `y[0]+y[1] = r`.
8384
- 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.
8485

8586
</section>
@@ -139,23 +140,25 @@ for ( i = 0; i < x.length; i++ ) {
139140

140141
#### stdlib_base_rempio2( x, &rem1, &rem2 )
141142

142-
Computes `x - nπ/2 = r`. The function returns `n` and stores the remainder `r` as two numbers in `y`, such that `y[0]+y[1] = r`.
143+
Computes `x - nπ/2 = r`.
143144

144145
```c
146+
#include <stdint.h>
147+
145148
double rem1;
146149
double rem2;
147150

148-
stdlib_base_rempio2( 4.0, &rem1, &rem2 );
151+
int32_t n = stdlib_base_rempio2( 4.0, &rem1, &rem2 );
149152
```
150153

151154
The function accepts the following arguments:
152155

153156
- **x**: `[in] double` input value.
154-
- **rem1**: `[out] double*` destination for rem1.
155-
- **rem2**: `[out] double*` destination for rem2.
157+
- **rem1**: `[out] double*` destination for first remainder number.
158+
- **rem2**: `[out] double*` destination for second remainder number.
156159

157160
```c
158-
void stdlib_base_rempio2( const double x, double *rem1, double *rem2 );
161+
int32_t stdlib_base_rempio2( const double x, double *rem1, double *rem2 );
159162
```
160163
161164
</section>
@@ -166,6 +169,10 @@ void stdlib_base_rempio2( const double x, double *rem1, double *rem2 );
166169
167170
<section class="notes">
168171
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+
169176
</section>
170177
171178
<!-- /.notes -->
@@ -179,17 +186,19 @@ void stdlib_base_rempio2( const double x, double *rem1, double *rem2 );
179186
```c
180187
#include "stdlib/math/base/special/rempio2.h"
181188
#include <stdio.h>
189+
#include <stdint.h>
190+
#include <inttypes.h>
182191
183192
int main( void ) {
184193
const double x[] = { 0.0, 1.0, 4.0, 128.0 };
185194
186195
double rem1;
187196
double rem2;
188-
double n;
197+
int32_t n;
189198
int i;
190199
for ( i = 0; i < 4; i++ ) {
191-
stdlib_base_rempio2( x[ i ], &rem1, &rem2 );
192-
printf( "%lf - %lfπ/2 = %lf + %lf", x[ i ], n, rem1, rem2 );
200+
n = stdlib_base_rempio2( x[ i ], &rem1, &rem2 );
201+
printf( "%lf - %"PRId32"π/2 = %lf + %lf\n", x[ i ], n, rem1, rem2 );
193202
}
194203
}
195204
```

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,18 @@
1818

1919
#include "stdlib/math/base/special/rempio2.h"
2020
#include <stdio.h>
21+
#include <stdint.h>
22+
#include <inttypes.h>
2123

2224
int main( void ) {
2325
const double x[] = { 0.0, 1.0, 4.0, 128.0 };
2426

2527
double rem1;
2628
double rem2;
27-
double n;
29+
int32_t n;
2830
int i;
2931
for ( i = 0; i < 4; i++ ) {
3032
n = stdlib_base_rempio2( x[ i ], &rem1, &rem2 );
31-
printf( "%lf - %lfπ/2 = %lf + %lf", x[ i ], n, rem1, rem2 );
33+
printf( "%lf - %"PRId32/2 = %lf + %lf\n", x[ i ], n, rem1, rem2 );
3234
}
3335
}

lib/node_modules/@stdlib/math/base/special/rempio2/include/stdlib/math/base/special/rempio2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extern "C" {
3434
/**
3535
* Computes `x - nπ/2 = r`.
3636
*/
37-
double stdlib_base_rempio2( const double x, double* rem1, double* rem2 );
37+
int32_t stdlib_base_rempio2( const double x, double *rem1, double *rem2 );
3838

3939
#ifdef __cplusplus
4040
}

lib/node_modules/@stdlib/math/base/special/rempio2/lib/native.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
// MODULES //
2222

23-
var Float64Array = require( '@stdlib/array/float64' );
2423
var addon = require( './../src/addon.node' );
2524

2625

@@ -31,11 +30,13 @@ var addon = require( './../src/addon.node' );
3130
*
3231
* @private
3332
* @param {number} x - input value
34-
* @param {(Array|TypedArray|Object)} y - remainder elements
33+
* @param {Float64Array} y - remainder elements
3534
* @returns {integer} factor of `π/2`
3635
*
3736
* @example
38-
* var y = [ 0.0, 0.0 ];
37+
* var Float64Array = require( '@stdlib/array/float64' );
38+
*
39+
* var y = new Float64Array( [ 0.0, 0.0 ] );
3940
* var n = rempio2( 128.0, y );
4041
* // returns 81
4142
*
@@ -45,9 +46,8 @@ var addon = require( './../src/addon.node' );
4546
* var y2 = y[ 1 ];
4647
* // returns ~3.618e-17
4748
*/
48-
function rempio2( x ) {
49-
var out = new Float64Array( 2 );
50-
return addon( out, x );
49+
function rempio2( x, y ) {
50+
return addon( x, y );
5151
}
5252

5353

Lines changed: 98 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,100 @@
11
{
2-
"options": {
3-
"task": "build"
4-
},
5-
"fields": [
6-
{
7-
"field": "src",
8-
"resolve": true,
9-
"relative": true
10-
},
11-
{
12-
"field": "include",
13-
"resolve": true,
14-
"relative": true
15-
},
16-
{
17-
"field": "libraries",
18-
"resolve": false,
19-
"relative": false
20-
},
21-
{
22-
"field": "libpath",
23-
"resolve": true,
24-
"relative": false
25-
}
26-
],
27-
"confs": [
28-
{
29-
"task": "build",
30-
"src": [
31-
"./src/main.c"
32-
],
33-
"include": [
34-
"./include"
35-
],
36-
"libraries": [],
37-
"libpath": [],
38-
"dependencies": [
39-
"@stdlib/math/base/special/round",
40-
"@stdlib/math/base/special/floor",
41-
"@stdlib/math/base/special/ldexp",
42-
"@stdlib/number/float64/base/get-high-word",
43-
"@stdlib/number/float64/base/get-low-word",
44-
"@stdlib/number/float64/base/from-words"
45-
]
46-
},
47-
{
48-
"task": "benchmark",
49-
"src": [
50-
"./src/main.c"
51-
],
52-
"include": [
53-
"./include"
54-
],
55-
"libraries": [],
56-
"libpath": [],
57-
"dependencies": [
58-
"@stdlib/math/base/special/round",
59-
"@stdlib/math/base/special/floor",
60-
"@stdlib/math/base/special/ldexp",
61-
"@stdlib/number/float64/base/get-high-word",
62-
"@stdlib/number/float64/base/get-low-word",
63-
"@stdlib/number/float64/base/from-words"
64-
]
65-
},
66-
{
67-
"task": "examples",
68-
"src": [
69-
"./src/main.c"
70-
],
71-
"include": [
72-
"./include"
73-
],
74-
"libraries": [],
75-
"libpath": [],
76-
"dependencies": [
77-
"@stdlib/math/base/special/round",
78-
"@stdlib/math/base/special/floor",
79-
"@stdlib/math/base/special/ldexp",
80-
"@stdlib/number/float64/base/get-high-word",
81-
"@stdlib/number/float64/base/get-low-word",
82-
"@stdlib/number/float64/base/from-words"
83-
]
84-
}
85-
]
2+
"options": {
3+
"task": "build"
4+
},
5+
"fields": [
6+
{
7+
"field": "src",
8+
"resolve": true,
9+
"relative": true
10+
},
11+
{
12+
"field": "include",
13+
"resolve": true,
14+
"relative": true
15+
},
16+
{
17+
"field": "libraries",
18+
"resolve": false,
19+
"relative": false
20+
},
21+
{
22+
"field": "libpath",
23+
"resolve": true,
24+
"relative": false
25+
}
26+
],
27+
"confs": [
28+
{
29+
"task": "build",
30+
"src": [
31+
"./src/main.c"
32+
],
33+
"include": [
34+
"./include"
35+
],
36+
"libraries": [],
37+
"libpath": [],
38+
"dependencies": [
39+
"@stdlib/napi/argv",
40+
"@stdlib/napi/argv-double",
41+
"@stdlib/napi/argv-float64array",
42+
"@stdlib/napi/create-double",
43+
"@stdlib/napi/export",
44+
"@stdlib/math/base/special/round",
45+
"@stdlib/math/base/special/floor",
46+
"@stdlib/math/base/special/ldexp",
47+
"@stdlib/number/float64/base/get-high-word",
48+
"@stdlib/number/float64/base/get-low-word",
49+
"@stdlib/number/float64/base/from-words",
50+
"@stdlib/constants/float64/high-word-abs-mask",
51+
"@stdlib/constants/float64/high-word-exponent-mask",
52+
"@stdlib/constants/float64/high-word-sign-mask"
53+
]
54+
},
55+
{
56+
"task": "benchmark",
57+
"src": [
58+
"./src/main.c"
59+
],
60+
"include": [
61+
"./include"
62+
],
63+
"libraries": [],
64+
"libpath": [],
65+
"dependencies": [
66+
"@stdlib/math/base/special/round",
67+
"@stdlib/math/base/special/floor",
68+
"@stdlib/math/base/special/ldexp",
69+
"@stdlib/number/float64/base/get-high-word",
70+
"@stdlib/number/float64/base/get-low-word",
71+
"@stdlib/number/float64/base/from-words",
72+
"@stdlib/constants/float64/high-word-abs-mask",
73+
"@stdlib/constants/float64/high-word-exponent-mask",
74+
"@stdlib/constants/float64/high-word-sign-mask"
75+
]
76+
},
77+
{
78+
"task": "examples",
79+
"src": [
80+
"./src/main.c"
81+
],
82+
"include": [
83+
"./include"
84+
],
85+
"libraries": [],
86+
"libpath": [],
87+
"dependencies": [
88+
"@stdlib/math/base/special/round",
89+
"@stdlib/math/base/special/floor",
90+
"@stdlib/math/base/special/ldexp",
91+
"@stdlib/number/float64/base/get-high-word",
92+
"@stdlib/number/float64/base/get-low-word",
93+
"@stdlib/number/float64/base/from-words",
94+
"@stdlib/constants/float64/high-word-abs-mask",
95+
"@stdlib/constants/float64/high-word-exponent-mask",
96+
"@stdlib/constants/float64/high-word-sign-mask"
97+
]
98+
}
99+
]
86100
}

0 commit comments

Comments
 (0)