@stdlib/math-base-special-ceil2 0.2.0 → 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 CHANGED
@@ -124,6 +124,91 @@ for ( i = 0; i < 100; i++ ) {
124
124
 
125
125
  <!-- /.examples -->
126
126
 
127
+ <!-- C interface documentation. -->
128
+
129
+ * * *
130
+
131
+ <section class="c">
132
+
133
+ ## C APIs
134
+
135
+ <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
136
+
137
+ <section class="intro">
138
+
139
+ </section>
140
+
141
+ <!-- /.intro -->
142
+
143
+ <!-- C usage documentation. -->
144
+
145
+ <section class="usage">
146
+
147
+ ### Usage
148
+
149
+ ```c
150
+ #include "stdlib/math/base/special/ceil2.h"
151
+ ```
152
+
153
+ #### stdlib_base_ceil2( x )
154
+
155
+ Rounds a `numeric` value to the nearest power of two toward positive infinity.
156
+
157
+ ```c
158
+ double y = stdlib_base_ceil2( 3.14 );
159
+ // returns 4.0
160
+ ```
161
+
162
+ The function accepts the following arguments:
163
+
164
+ - **x**: `[in] double` input value.
165
+
166
+ ```c
167
+ double stdlib_base_ceil2( const double x );
168
+ ```
169
+
170
+ </section>
171
+
172
+ <!-- /.usage -->
173
+
174
+ <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
175
+
176
+ <section class="notes">
177
+
178
+ </section>
179
+
180
+ <!-- /.notes -->
181
+
182
+ <!-- C API usage examples. -->
183
+
184
+ <section class="examples">
185
+
186
+ ### Examples
187
+
188
+ ```c
189
+ #include "stdlib/math/base/special/ceil2.h"
190
+ #include <stdio.h>
191
+
192
+ int main( void ) {
193
+ const double x[] = { 3.14, -3.14, 0.5, 0.0 / 0.0 };
194
+
195
+ double y;
196
+ int i;
197
+ for ( i = 0; i < 4; i++ ) {
198
+ y = stdlib_base_ceil2( x[ i ] );
199
+ printf( "ceil2(%lf) = %lf\n", x[ i ], y );
200
+ }
201
+ }
202
+ ```
203
+
204
+ </section>
205
+
206
+ <!-- /.examples -->
207
+
208
+ </section>
209
+
210
+ <!-- /.c -->
211
+
127
212
  <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
128
213
 
129
214
  <section class="related">
@@ -180,8 +265,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
180
265
  [npm-image]: http://img.shields.io/npm/v/@stdlib/math-base-special-ceil2.svg
181
266
  [npm-url]: https://npmjs.org/package/@stdlib/math-base-special-ceil2
182
267
 
183
- [test-image]: https://github.com/stdlib-js/math-base-special-ceil2/actions/workflows/test.yml/badge.svg?branch=v0.2.0
184
- [test-url]: https://github.com/stdlib-js/math-base-special-ceil2/actions/workflows/test.yml?query=branch:v0.2.0
268
+ [test-image]: https://github.com/stdlib-js/math-base-special-ceil2/actions/workflows/test.yml/badge.svg?branch=v0.3.0
269
+ [test-url]: https://github.com/stdlib-js/math-base-special-ceil2/actions/workflows/test.yml?query=branch:v0.3.0
185
270
 
186
271
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/math-base-special-ceil2/main.svg
187
272
  [coverage-url]: https://codecov.io/github/stdlib-js/math-base-special-ceil2?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_CEIL2_H
20
+ #define STDLIB_MATH_BASE_SPECIAL_CEIL2_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 two toward positive infinity.
31
+ */
32
+ double stdlib_base_ceil2( const double x );
33
+
34
+ #ifdef __cplusplus
35
+ }
36
+ #endif
37
+
38
+ #endif // !STDLIB_MATH_BASE_SPECIAL_CEIL2_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 two toward positive infinity.
30
+ *
31
+ * @private
32
+ * @param {number} x - input value
33
+ * @returns {number} rounded value
34
+ *
35
+ * @example
36
+ * var v = ceil2( 3.141592653589793 );
37
+ * // returns 4.0
38
+ *
39
+ * @example
40
+ * var v = ceil2( 9.0 );
41
+ * // returns 16.0
42
+ *
43
+ * @example
44
+ * var v = ceil2( -0.314 );
45
+ * // returns -0.25
46
+ */
47
+ function ceil2( x ) {
48
+ return addon( x );
49
+ }
50
+
51
+
52
+ // EXPORTS //
53
+
54
+ module.exports = ceil2;
package/manifest.json ADDED
@@ -0,0 +1,96 @@
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
+ "libpath": [],
38
+ "dependencies": [
39
+ "@stdlib/math-base-napi-unary",
40
+ "@stdlib/math-base-assert-is-nan",
41
+ "@stdlib/math-base-assert-is-infinite",
42
+ "@stdlib/math-base-special-pow",
43
+ "@stdlib/math-base-special-floor",
44
+ "@stdlib/math-base-special-ceil",
45
+ "@stdlib/math-base-special-log2",
46
+ "@stdlib/constants-float64-max-base2-exponent",
47
+ "@stdlib/constants-float64-min-base2-exponent-subnormal",
48
+ "@stdlib/constants-float64-pinf"
49
+ ]
50
+ },
51
+ {
52
+ "task": "benchmark",
53
+ "src": [
54
+ "./src/main.c"
55
+ ],
56
+ "include": [
57
+ "./include"
58
+ ],
59
+ "libraries": [],
60
+ "libpath": [],
61
+ "dependencies": [
62
+ "@stdlib/math-base-assert-is-nan",
63
+ "@stdlib/math-base-assert-is-infinite",
64
+ "@stdlib/math-base-special-pow",
65
+ "@stdlib/math-base-special-floor",
66
+ "@stdlib/math-base-special-ceil",
67
+ "@stdlib/math-base-special-log2",
68
+ "@stdlib/constants-float64-max-base2-exponent",
69
+ "@stdlib/constants-float64-min-base2-exponent-subnormal",
70
+ "@stdlib/constants-float64-pinf"
71
+ ]
72
+ },
73
+ {
74
+ "task": "examples",
75
+ "src": [
76
+ "./src/main.c"
77
+ ],
78
+ "include": [
79
+ "./include"
80
+ ],
81
+ "libraries": [],
82
+ "libpath": [],
83
+ "dependencies": [
84
+ "@stdlib/math-base-assert-is-nan",
85
+ "@stdlib/math-base-assert-is-infinite",
86
+ "@stdlib/math-base-special-pow",
87
+ "@stdlib/math-base-special-floor",
88
+ "@stdlib/math-base-special-ceil",
89
+ "@stdlib/math-base-special-log2",
90
+ "@stdlib/constants-float64-max-base2-exponent",
91
+ "@stdlib/constants-float64-min-base2-exponent-subnormal",
92
+ "@stdlib/constants-float64-pinf"
93
+ ]
94
+ }
95
+ ]
96
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/math-base-special-ceil2",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Round a numeric value to the nearest power of two toward positive infinity.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -14,20 +14,16 @@
14
14
  }
15
15
  ],
16
16
  "main": "./lib",
17
+ "gypfile": false,
17
18
  "directories": {
18
- "benchmark": "./benchmark",
19
19
  "doc": "./docs",
20
- "example": "./examples",
20
+ "include": "./include",
21
21
  "lib": "./lib",
22
- "test": "./test"
22
+ "src": "./src",
23
+ "dist": "./dist"
23
24
  },
24
25
  "types": "./docs/types",
25
- "scripts": {
26
- "test": "make test",
27
- "test-cov": "make test-cov",
28
- "examples": "make examples",
29
- "benchmark": "make benchmark"
30
- },
26
+ "scripts": {},
31
27
  "homepage": "https://stdlib.io",
32
28
  "repository": {
33
29
  "type": "git",
@@ -37,29 +33,19 @@
37
33
  "url": "https://github.com/stdlib-js/stdlib/issues"
38
34
  },
39
35
  "dependencies": {
40
- "@stdlib/constants-float64-max-base2-exponent": "^0.2.0",
41
- "@stdlib/constants-float64-min-base2-exponent-subnormal": "^0.2.0",
42
- "@stdlib/constants-float64-pinf": "^0.2.0",
43
- "@stdlib/math-base-assert-is-infinite": "^0.2.0",
44
- "@stdlib/math-base-assert-is-nan": "^0.2.0",
45
- "@stdlib/math-base-special-ceil": "^0.2.0",
46
- "@stdlib/math-base-special-floor": "^0.2.0",
47
- "@stdlib/math-base-special-log2": "^0.2.0",
48
- "@stdlib/math-base-special-pow": "^0.2.0"
49
- },
50
- "devDependencies": {
51
- "@stdlib/constants-float64-ninf": "^0.1.1",
52
- "@stdlib/constants-float64-smallest-subnormal": "^0.2.0",
53
- "@stdlib/math-base-assert-is-negative-zero": "^0.1.1",
54
- "@stdlib/math-base-assert-is-positive-zero": "^0.1.1",
55
- "@stdlib/math-base-special-exp2": "^0.1.0",
56
- "@stdlib/random-base-randu": "^0.1.0",
57
- "tape": "git+https://github.com/kgryte/tape.git#fix/globby",
58
- "istanbul": "^0.4.1",
59
- "tap-min": "git+https://github.com/Planeshifter/tap-min.git",
60
- "@stdlib/bench-harness": "^0.2.0",
61
- "@stdlib/bench": "^0.3.1"
36
+ "@stdlib/constants-float64-max-base2-exponent": "^0.2.2",
37
+ "@stdlib/constants-float64-min-base2-exponent-subnormal": "^0.2.1",
38
+ "@stdlib/constants-float64-pinf": "^0.2.2",
39
+ "@stdlib/math-base-assert-is-infinite": "^0.2.2",
40
+ "@stdlib/math-base-assert-is-nan": "^0.2.2",
41
+ "@stdlib/math-base-napi-unary": "^0.2.3",
42
+ "@stdlib/math-base-special-ceil": "^0.2.2",
43
+ "@stdlib/math-base-special-floor": "^0.2.3",
44
+ "@stdlib/math-base-special-log2": "^0.3.0",
45
+ "@stdlib/math-base-special-pow": "^0.3.0",
46
+ "@stdlib/utils-library-manifest": "^0.2.2"
62
47
  },
48
+ "devDependencies": {},
63
49
  "engines": {
64
50
  "node": ">=0.10.0",
65
51
  "npm": ">2.7.0"
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/ceil2.h"
20
+ #include "stdlib/math/base/napi/unary.h"
21
+
22
+ STDLIB_MATH_BASE_NAPI_MODULE_D_D( stdlib_base_ceil2 )
package/src/main.c ADDED
@@ -0,0 +1,76 @@
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/ceil2.h"
20
+ #include "stdlib/math/base/assert/is_nan.h"
21
+ #include "stdlib/math/base/assert/is_infinite.h"
22
+ #include "stdlib/math/base/special/pow.h"
23
+ #include "stdlib/math/base/special/floor.h"
24
+ #include "stdlib/math/base/special/ceil.h"
25
+ #include "stdlib/math/base/special/log2.h"
26
+ #include "stdlib/constants/float64/max_base2_exponent.h"
27
+ #include "stdlib/constants/float64/min_base2_exponent_subnormal.h"
28
+ #include "stdlib/constants/float64/pinf.h"
29
+
30
+ /**
31
+ * Rounds a numeric value to the nearest power of two toward positive infinity.
32
+ *
33
+ * @param x input value
34
+ * @return rounded value
35
+ *
36
+ * @example
37
+ * double y = stdlib_base_ceil2( 3.141592653589793 );
38
+ * // returns 4.0
39
+ */
40
+ double stdlib_base_ceil2( const double x ) {
41
+ double sign;
42
+ double xc;
43
+ double p;
44
+
45
+ xc = x;
46
+ if ( stdlib_base_is_nan( xc ) || stdlib_base_is_infinite( xc ) || xc == 0.0 ) {
47
+ return xc;
48
+ }
49
+ if ( xc < 0.0 ) {
50
+ xc = -xc;
51
+ sign = -1.0;
52
+ } else {
53
+ sign = 1.0;
54
+ }
55
+
56
+ // Solve the equation `2^p = x` for `p`:
57
+ p = stdlib_base_log2( xc );
58
+
59
+ // If provided the smallest subnormal, no rounding possible:
60
+ if ( p == STDLIB_CONSTANT_FLOAT64_MIN_BASE2_EXPONENT_SUBNORMAL ) {
61
+ return xc;
62
+ }
63
+
64
+ // Determine a power of two which rounds the input value toward positive infinity:
65
+ if ( sign == -1.0 ) {
66
+ p = stdlib_base_floor( p );
67
+ } else {
68
+ p = stdlib_base_ceil( p );
69
+ }
70
+
71
+ // Handle overflow:
72
+ if ( p > STDLIB_CONSTANT_FLOAT64_MAX_BASE2_EXPONENT ) {
73
+ return STDLIB_CONSTANT_FLOAT64_PINF;
74
+ }
75
+ return sign * stdlib_base_pow( 2.0, p );
76
+ }