@stdlib/math-base-special-trunc10 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +87 -2
- package/include/stdlib/math/base/special/trunc10.h +38 -0
- package/lib/native.js +54 -0
- package/manifest.json +90 -0
- package/package.json +11 -6
- package/src/addon.c +22 -0
- package/src/main.c +51 -0
package/README.md
CHANGED
|
@@ -139,6 +139,91 @@ for ( i = 0; i < 100; i++ ) {
|
|
|
139
139
|
|
|
140
140
|
<!-- /.examples -->
|
|
141
141
|
|
|
142
|
+
<!-- C interface documentation. -->
|
|
143
|
+
|
|
144
|
+
* * *
|
|
145
|
+
|
|
146
|
+
<section class="c">
|
|
147
|
+
|
|
148
|
+
## C APIs
|
|
149
|
+
|
|
150
|
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
|
|
151
|
+
|
|
152
|
+
<section class="intro">
|
|
153
|
+
|
|
154
|
+
</section>
|
|
155
|
+
|
|
156
|
+
<!-- /.intro -->
|
|
157
|
+
|
|
158
|
+
<!-- C usage documentation. -->
|
|
159
|
+
|
|
160
|
+
<section class="usage">
|
|
161
|
+
|
|
162
|
+
### Usage
|
|
163
|
+
|
|
164
|
+
```c
|
|
165
|
+
#include "stdlib/math/base/special/trunc10.h"
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
#### stdlib_base_trunc10( x )
|
|
169
|
+
|
|
170
|
+
Rounds a `numeric` value to the nearest power of 10 toward zero.
|
|
171
|
+
|
|
172
|
+
```c
|
|
173
|
+
double y = stdlib_base_trunc10( -4.2 );
|
|
174
|
+
// returns -1.0
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
The function accepts the following arguments:
|
|
178
|
+
|
|
179
|
+
- **x**: `[in] double` input value.
|
|
180
|
+
|
|
181
|
+
```c
|
|
182
|
+
double stdlib_base_trunc10( const double x );
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
</section>
|
|
186
|
+
|
|
187
|
+
<!-- /.usage -->
|
|
188
|
+
|
|
189
|
+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
190
|
+
|
|
191
|
+
<section class="notes">
|
|
192
|
+
|
|
193
|
+
</section>
|
|
194
|
+
|
|
195
|
+
<!-- /.notes -->
|
|
196
|
+
|
|
197
|
+
<!-- C API usage examples. -->
|
|
198
|
+
|
|
199
|
+
<section class="examples">
|
|
200
|
+
|
|
201
|
+
### Examples
|
|
202
|
+
|
|
203
|
+
```c
|
|
204
|
+
#include "stdlib/math/base/special/trunc10.h"
|
|
205
|
+
#include <stdio.h>
|
|
206
|
+
|
|
207
|
+
int main( void ) {
|
|
208
|
+
const double x[] = { 3.14, -3.14, 0.0, 0.0 / 0.0 };
|
|
209
|
+
|
|
210
|
+
double y;
|
|
211
|
+
int i;
|
|
212
|
+
for ( i = 0; i < 4; i++ ) {
|
|
213
|
+
y = stdlib_base_trunc10( x[ i ] );
|
|
214
|
+
printf( "trunc10(%lf) = %lf\n", x[ i ], y );
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
</section>
|
|
220
|
+
|
|
221
|
+
<!-- /.examples -->
|
|
222
|
+
|
|
223
|
+
</section>
|
|
224
|
+
|
|
225
|
+
<!-- /.c -->
|
|
226
|
+
|
|
142
227
|
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
143
228
|
|
|
144
229
|
<section class="related">
|
|
@@ -196,8 +281,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
196
281
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/math-base-special-trunc10.svg
|
|
197
282
|
[npm-url]: https://npmjs.org/package/@stdlib/math-base-special-trunc10
|
|
198
283
|
|
|
199
|
-
[test-image]: https://github.com/stdlib-js/math-base-special-trunc10/actions/workflows/test.yml/badge.svg?branch=v0.
|
|
200
|
-
[test-url]: https://github.com/stdlib-js/math-base-special-trunc10/actions/workflows/test.yml?query=branch:v0.
|
|
284
|
+
[test-image]: https://github.com/stdlib-js/math-base-special-trunc10/actions/workflows/test.yml/badge.svg?branch=v0.3.0
|
|
285
|
+
[test-url]: https://github.com/stdlib-js/math-base-special-trunc10/actions/workflows/test.yml?query=branch:v0.3.0
|
|
201
286
|
|
|
202
287
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/math-base-special-trunc10/main.svg
|
|
203
288
|
[coverage-url]: https://codecov.io/github/stdlib-js/math-base-special-trunc10?branch=main
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
#ifndef STDLIB_MATH_BASE_SPECIAL_TRUNC10_H
|
|
20
|
+
#define STDLIB_MATH_BASE_SPECIAL_TRUNC10_H
|
|
21
|
+
|
|
22
|
+
/*
|
|
23
|
+
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
|
|
24
|
+
*/
|
|
25
|
+
#ifdef __cplusplus
|
|
26
|
+
extern "C" {
|
|
27
|
+
#endif
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Rounds a numeric value to the nearest power of `10` toward zero.
|
|
31
|
+
*/
|
|
32
|
+
double stdlib_base_trunc10( const double x );
|
|
33
|
+
|
|
34
|
+
#ifdef __cplusplus
|
|
35
|
+
}
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
#endif // !STDLIB_MATH_BASE_SPECIAL_TRUNC10_H
|
package/lib/native.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
// MODULES //
|
|
22
|
+
|
|
23
|
+
var addon = require( './../src/addon.node' );
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
// MAIN //
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Rounds a numeric value to the nearest power of `10` toward zero.
|
|
30
|
+
*
|
|
31
|
+
* @private
|
|
32
|
+
* @param {number} x - input value
|
|
33
|
+
* @returns {number} rounded value
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* var v = trunc10( 3.141592653589793 );
|
|
37
|
+
* // returns 1.0
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* var v = trunc10( 13.0 );
|
|
41
|
+
* // returns 10.0
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* var v = trunc10( -0.314 );
|
|
45
|
+
* // returns -0.1
|
|
46
|
+
*/
|
|
47
|
+
function trunc10( x ) {
|
|
48
|
+
return addon( x );
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
// EXPORTS //
|
|
53
|
+
|
|
54
|
+
module.exports = trunc10;
|
package/manifest.json
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
{
|
|
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
|
+
"-lm"
|
|
38
|
+
],
|
|
39
|
+
"libpath": [],
|
|
40
|
+
"dependencies": [
|
|
41
|
+
"@stdlib/math-base-napi-unary",
|
|
42
|
+
"@stdlib/math-base-special-pow",
|
|
43
|
+
"@stdlib/math-base-special-floor",
|
|
44
|
+
"@stdlib/math-base-special-log10",
|
|
45
|
+
"@stdlib/math-base-assert-is-nan",
|
|
46
|
+
"@stdlib/math-base-assert-is-infinite"
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"task": "benchmark",
|
|
51
|
+
"src": [
|
|
52
|
+
"./src/main.c"
|
|
53
|
+
],
|
|
54
|
+
"include": [
|
|
55
|
+
"./include"
|
|
56
|
+
],
|
|
57
|
+
"libraries": [
|
|
58
|
+
"-lm"
|
|
59
|
+
],
|
|
60
|
+
"libpath": [],
|
|
61
|
+
"dependencies": [
|
|
62
|
+
"@stdlib/math-base-special-pow",
|
|
63
|
+
"@stdlib/math-base-special-floor",
|
|
64
|
+
"@stdlib/math-base-special-log10",
|
|
65
|
+
"@stdlib/math-base-assert-is-nan",
|
|
66
|
+
"@stdlib/math-base-assert-is-infinite"
|
|
67
|
+
]
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"task": "examples",
|
|
71
|
+
"src": [
|
|
72
|
+
"./src/main.c"
|
|
73
|
+
],
|
|
74
|
+
"include": [
|
|
75
|
+
"./include"
|
|
76
|
+
],
|
|
77
|
+
"libraries": [
|
|
78
|
+
"-lm"
|
|
79
|
+
],
|
|
80
|
+
"libpath": [],
|
|
81
|
+
"dependencies": [
|
|
82
|
+
"@stdlib/math-base-special-pow",
|
|
83
|
+
"@stdlib/math-base-special-floor",
|
|
84
|
+
"@stdlib/math-base-special-log10",
|
|
85
|
+
"@stdlib/math-base-assert-is-nan",
|
|
86
|
+
"@stdlib/math-base-assert-is-infinite"
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
]
|
|
90
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/math-base-special-trunc10",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Round a numeric value to the nearest power of 10 toward zero.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -14,9 +14,12 @@
|
|
|
14
14
|
}
|
|
15
15
|
],
|
|
16
16
|
"main": "./lib",
|
|
17
|
+
"gypfile": false,
|
|
17
18
|
"directories": {
|
|
18
19
|
"doc": "./docs",
|
|
20
|
+
"include": "./include",
|
|
19
21
|
"lib": "./lib",
|
|
22
|
+
"src": "./src",
|
|
20
23
|
"dist": "./dist"
|
|
21
24
|
},
|
|
22
25
|
"types": "./docs/types",
|
|
@@ -30,11 +33,13 @@
|
|
|
30
33
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
31
34
|
},
|
|
32
35
|
"dependencies": {
|
|
33
|
-
"@stdlib/math-base-assert-is-infinite": "^0.2.
|
|
34
|
-
"@stdlib/math-base-assert-is-nan": "^0.2.
|
|
35
|
-
"@stdlib/math-base-
|
|
36
|
-
"@stdlib/math-base-special-
|
|
37
|
-
"@stdlib/math-base-special-
|
|
36
|
+
"@stdlib/math-base-assert-is-infinite": "^0.2.2",
|
|
37
|
+
"@stdlib/math-base-assert-is-nan": "^0.2.2",
|
|
38
|
+
"@stdlib/math-base-napi-unary": "^0.2.3",
|
|
39
|
+
"@stdlib/math-base-special-floor": "^0.2.3",
|
|
40
|
+
"@stdlib/math-base-special-log10": "^0.3.0",
|
|
41
|
+
"@stdlib/math-base-special-pow": "^0.3.0",
|
|
42
|
+
"@stdlib/utils-library-manifest": "^0.2.2"
|
|
38
43
|
},
|
|
39
44
|
"devDependencies": {},
|
|
40
45
|
"engines": {
|
package/src/addon.c
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
#include "stdlib/math/base/special/trunc10.h"
|
|
20
|
+
#include "stdlib/math/base/napi/unary.h"
|
|
21
|
+
|
|
22
|
+
STDLIB_MATH_BASE_NAPI_MODULE_D_D( stdlib_base_trunc10 )
|
package/src/main.c
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
#include "stdlib/math/base/special/trunc10.h"
|
|
20
|
+
#include "stdlib/math/base/special/pow.h"
|
|
21
|
+
#include "stdlib/math/base/special/floor.h"
|
|
22
|
+
#include "stdlib/math/base/special/log10.h"
|
|
23
|
+
#include "stdlib/math/base/assert/is_nan.h"
|
|
24
|
+
#include "stdlib/math/base/assert/is_infinite.h"
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Rounds a numeric value to the nearest power of `10` toward zero.
|
|
28
|
+
*
|
|
29
|
+
* @param x input value
|
|
30
|
+
* @return rounded value
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* double y = stdlib_base_trunc2( 13.0 );
|
|
34
|
+
* // returns 10.0
|
|
35
|
+
*/
|
|
36
|
+
double stdlib_base_trunc10( const double x ) {
|
|
37
|
+
double sign;
|
|
38
|
+
double xc;
|
|
39
|
+
|
|
40
|
+
if ( stdlib_base_is_nan( x ) || stdlib_base_is_infinite( x ) || x == 0.0 ) {
|
|
41
|
+
return x;
|
|
42
|
+
}
|
|
43
|
+
xc = x;
|
|
44
|
+
if( xc < 0 ) {
|
|
45
|
+
xc = -xc;
|
|
46
|
+
sign = -1.0;
|
|
47
|
+
} else {
|
|
48
|
+
sign = 1.0;
|
|
49
|
+
}
|
|
50
|
+
return sign * stdlib_base_pow( 10.0, stdlib_base_floor( stdlib_base_log10( xc ) ) );
|
|
51
|
+
}
|