@stdlib/math-base-special-ceilsd 0.2.1 → 0.3.1
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/NOTICE +1 -1
- package/README.md +107 -23
- package/dist/index.js +3 -3
- package/dist/index.js.map +3 -3
- package/docs/types/index.d.ts +5 -5
- package/include/stdlib/math/base/special/ceilsd.h +40 -0
- package/lib/index.js +3 -3
- package/lib/main.js +12 -22
- package/lib/native.js +60 -0
- package/manifest.json +96 -0
- package/package.json +15 -10
- package/src/addon.c +22 -0
- package/src/main.c +81 -0
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -53,25 +53,21 @@ npm install @stdlib/math-base-special-ceilsd
|
|
|
53
53
|
var ceilsd = require( '@stdlib/math-base-special-ceilsd' );
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
-
#### ceilsd( x, n
|
|
56
|
+
#### ceilsd( x, n, b )
|
|
57
57
|
|
|
58
58
|
Rounds a `numeric` value to the nearest `number` toward positive infinity with `n` significant figures.
|
|
59
59
|
|
|
60
60
|
```javascript
|
|
61
|
-
var v = ceilsd( 3.141592653589793, 5 );
|
|
61
|
+
var v = ceilsd( 3.141592653589793, 5, 10 );
|
|
62
62
|
// returns 3.1416
|
|
63
63
|
|
|
64
|
-
v = ceilsd( 3.141592653589793, 1 );
|
|
64
|
+
v = ceilsd( 3.141592653589793, 1, 10 );
|
|
65
65
|
// returns 4.0
|
|
66
66
|
|
|
67
|
-
v = ceilsd( 12368.0, 2 );
|
|
67
|
+
v = ceilsd( 12368.0, 2, 10 );
|
|
68
68
|
// returns 13000.0
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
The default base is `10` (decimal). To round using a different base, provide a third argument.
|
|
72
69
|
|
|
73
|
-
|
|
74
|
-
var v = ceilsd( 0.0313, 2, 2 );
|
|
70
|
+
v = ceilsd( 0.0313, 2, 2 );
|
|
75
71
|
// returns 0.046875
|
|
76
72
|
```
|
|
77
73
|
|
|
@@ -92,17 +88,101 @@ var v = ceilsd( 0.0313, 2, 2 );
|
|
|
92
88
|
<!-- eslint no-undef: "error" -->
|
|
93
89
|
|
|
94
90
|
```javascript
|
|
95
|
-
var
|
|
91
|
+
var uniform = require( '@stdlib/random-array-uniform' );
|
|
92
|
+
var logEachMap = require( '@stdlib/console-log-each-map' );
|
|
96
93
|
var ceilsd = require( '@stdlib/math-base-special-ceilsd' );
|
|
97
94
|
|
|
98
|
-
var
|
|
99
|
-
|
|
100
|
-
|
|
95
|
+
var opts = {
|
|
96
|
+
'dtype': 'float64'
|
|
97
|
+
};
|
|
98
|
+
var x = uniform( 100, -5000.0, 5000.0, opts );
|
|
99
|
+
|
|
100
|
+
logEachMap( 'x: %0.4f. y: %d. z: %d. Rounded: %0.4f.', x, 5, 10, ceilsd );
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
</section>
|
|
104
|
+
|
|
105
|
+
<!-- /.examples -->
|
|
106
|
+
|
|
107
|
+
<!-- C interface documentation. -->
|
|
108
|
+
|
|
109
|
+
* * *
|
|
110
|
+
|
|
111
|
+
<section class="c">
|
|
112
|
+
|
|
113
|
+
## C APIs
|
|
114
|
+
|
|
115
|
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
|
|
116
|
+
|
|
117
|
+
<section class="intro">
|
|
118
|
+
|
|
119
|
+
</section>
|
|
120
|
+
|
|
121
|
+
<!-- /.intro -->
|
|
122
|
+
|
|
123
|
+
<!-- C usage documentation. -->
|
|
124
|
+
|
|
125
|
+
<section class="usage">
|
|
126
|
+
|
|
127
|
+
### Usage
|
|
128
|
+
|
|
129
|
+
```c
|
|
130
|
+
#include "stdlib/math/base/special/ceilsd.h"
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
#### stdlib_base_ceilsd( x, n, b )
|
|
134
|
+
|
|
135
|
+
Rounds a `numeric` value to the nearest `number` toward positive infinity with `n` significant figures.
|
|
101
136
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
137
|
+
```c
|
|
138
|
+
double out = stdlib_base_ceilsd( 0.0313, 2, 2 );
|
|
139
|
+
// returns 0.046875
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
The function accepts the following arguments:
|
|
143
|
+
|
|
144
|
+
- **x**: `[in] double` input value.
|
|
145
|
+
- **n**: `[in] int32_t` number of significant figures.
|
|
146
|
+
- **b**: `[in] int32_t` base.
|
|
147
|
+
|
|
148
|
+
```c
|
|
149
|
+
double stdlib_base_ceilsd( const double x, const int32_t n, const int32_t b );
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
</section>
|
|
153
|
+
|
|
154
|
+
<!-- /.usage -->
|
|
155
|
+
|
|
156
|
+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
157
|
+
|
|
158
|
+
<section class="notes">
|
|
159
|
+
|
|
160
|
+
</section>
|
|
161
|
+
|
|
162
|
+
<!-- /.notes -->
|
|
163
|
+
|
|
164
|
+
<!-- C API usage examples. -->
|
|
165
|
+
|
|
166
|
+
<section class="examples">
|
|
167
|
+
|
|
168
|
+
### Examples
|
|
169
|
+
|
|
170
|
+
```c
|
|
171
|
+
#include "stdlib/math/base/special/ceilsd.h"
|
|
172
|
+
#include <stdio.h>
|
|
173
|
+
#include <stdint.h>
|
|
174
|
+
|
|
175
|
+
int main( void ) {
|
|
176
|
+
const double x[] = { -5.0, -3.89, -2.78, -1.67, -0.56, 0.56, 1.67, 2.78, 3.89, 5.0 };
|
|
177
|
+
const int32_t n[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
|
|
178
|
+
const int32_t b[] = { 20, 19, 18, 17, 16, 15, 14, 13, 12, 11 };
|
|
179
|
+
|
|
180
|
+
double v;
|
|
181
|
+
int i;
|
|
182
|
+
for ( i = 0; i < 10; i++ ) {
|
|
183
|
+
v = stdlib_base_ceilsd( x[ i ], n[ i ], b[ i ] );
|
|
184
|
+
printf( "ceilsd(%lf, %d, %d) = %lf\n", x[ i ], n[ i ], b[ i ], v );
|
|
185
|
+
}
|
|
106
186
|
}
|
|
107
187
|
```
|
|
108
188
|
|
|
@@ -110,6 +190,10 @@ for ( i = 0; i < 100; i++ ) {
|
|
|
110
190
|
|
|
111
191
|
<!-- /.examples -->
|
|
112
192
|
|
|
193
|
+
</section>
|
|
194
|
+
|
|
195
|
+
<!-- /.c -->
|
|
196
|
+
|
|
113
197
|
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
114
198
|
|
|
115
199
|
<section class="related">
|
|
@@ -120,7 +204,7 @@ for ( i = 0; i < 100; i++ ) {
|
|
|
120
204
|
|
|
121
205
|
- <span class="package-name">[`@stdlib/math-base/special/ceil`][@stdlib/math/base/special/ceil]</span><span class="delimiter">: </span><span class="description">round a double-precision floating-point number toward positive infinity.</span>
|
|
122
206
|
- <span class="package-name">[`@stdlib/math-base/special/floorsd`][@stdlib/math/base/special/floorsd]</span><span class="delimiter">: </span><span class="description">round a numeric value to the nearest number toward negative infinity with N significant figures.</span>
|
|
123
|
-
- <span class="package-name">[`@stdlib/math-base/special/roundsd`][@stdlib/math/base/special/roundsd]</span><span class="delimiter">: </span><span class="description">round a
|
|
207
|
+
- <span class="package-name">[`@stdlib/math-base/special/roundsd`][@stdlib/math/base/special/roundsd]</span><span class="delimiter">: </span><span class="description">round a double-precision floating-point number to the nearest value with N significant figures.</span>
|
|
124
208
|
- <span class="package-name">[`@stdlib/math-base/special/truncsd`][@stdlib/math/base/special/truncsd]</span><span class="delimiter">: </span><span class="description">round a numeric value to the nearest number toward zero with N significant figures.</span>
|
|
125
209
|
|
|
126
210
|
</section>
|
|
@@ -153,7 +237,7 @@ See [LICENSE][stdlib-license].
|
|
|
153
237
|
|
|
154
238
|
## Copyright
|
|
155
239
|
|
|
156
|
-
Copyright © 2016-
|
|
240
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
157
241
|
|
|
158
242
|
</section>
|
|
159
243
|
|
|
@@ -166,8 +250,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
166
250
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/math-base-special-ceilsd.svg
|
|
167
251
|
[npm-url]: https://npmjs.org/package/@stdlib/math-base-special-ceilsd
|
|
168
252
|
|
|
169
|
-
[test-image]: https://github.com/stdlib-js/math-base-special-ceilsd/actions/workflows/test.yml/badge.svg?branch=v0.
|
|
170
|
-
[test-url]: https://github.com/stdlib-js/math-base-special-ceilsd/actions/workflows/test.yml?query=branch:v0.
|
|
253
|
+
[test-image]: https://github.com/stdlib-js/math-base-special-ceilsd/actions/workflows/test.yml/badge.svg?branch=v0.3.1
|
|
254
|
+
[test-url]: https://github.com/stdlib-js/math-base-special-ceilsd/actions/workflows/test.yml?query=branch:v0.3.1
|
|
171
255
|
|
|
172
256
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/math-base-special-ceilsd/main.svg
|
|
173
257
|
[coverage-url]: https://codecov.io/github/stdlib-js/math-base-special-ceilsd?branch=main
|
|
@@ -179,8 +263,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
179
263
|
|
|
180
264
|
-->
|
|
181
265
|
|
|
182
|
-
[chat-image]: https://img.shields.io/
|
|
183
|
-
[chat-url]: https://
|
|
266
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
267
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
184
268
|
|
|
185
269
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
186
270
|
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
var
|
|
3
|
-
});var w=
|
|
1
|
+
"use strict";var c=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var o=c(function(I,l){
|
|
2
|
+
var n=require('@stdlib/math-base-assert-is-nan/dist'),s=require('@stdlib/math-base-assert-is-infinite/dist'),p=require('@stdlib/math-base-special-pow/dist'),N=require('@stdlib/math-base-special-log10/dist'),f=require('@stdlib/math-base-special-ln/dist'),v=require('@stdlib/math-base-special-abs/dist'),d=require('@stdlib/math-base-special-floor/dist'),g=require('@stdlib/number-float64-base-exponent/dist'),q=require('@stdlib/math-base-special-ceil/dist');function m(r,e,i){var u,a,t;return n(r)||n(e)||e<1||s(e)||n(i)||i<=0||s(i)?NaN:s(r)||r===0||(i===10?u=N(v(r)):i===2?u=g(v(r)):u=f(v(r))/f(i),u=d(u-e+1),a=p(i,v(u)),s(a))||(u<0?t=q(r*a)/a:t=q(r/a)*a,s(t))?r:t}l.exports=m
|
|
3
|
+
});var w=o();module.exports=w;
|
|
4
4
|
/** @license Apache-2.0 */
|
|
5
5
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../lib/main.js", "../lib/index.js"],
|
|
4
|
-
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar isInfinite = require( '@stdlib/math-base-assert-is-infinite' );\nvar pow = require( '@stdlib/math-base-special-pow' );\nvar log10 = require( '@stdlib/math-base-special-log10' );\nvar ln = require( '@stdlib/math-base-special-ln' );\nvar abs = require( '@stdlib/math-base-special-abs' );\nvar floor = require( '@stdlib/math-base-special-floor' );\nvar exponent = require( '@stdlib/number-float64-base-exponent' );\nvar ceil = require( '@stdlib/math-base-special-ceil' );\n\n\n// MAIN //\n\n/**\n* Rounds a numeric value to the nearest number toward positive infinity with \\\\(n\\\\) significant figures.\n*\n* @param {number} x - input value\n* @param {PositiveInteger} n - number of significant figures\n* @param {PositiveInteger}
|
|
5
|
-
"mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAQ,QAAS,iCAAkC,EACnDC,EAAa,QAAS,sCAAuC,EAC7DC,EAAM,QAAS,+BAAgC,EAC/CC,EAAQ,QAAS,iCAAkC,EACnDC,EAAK,QAAS,8BAA+B,EAC7CC,EAAM,QAAS,+BAAgC,EAC/CC,EAAQ,QAAS,iCAAkC,EACnDC,EAAW,QAAS,sCAAuC,EAC3DC,EAAO,QAAS,gCAAiC,EA6BrD,SAASC,EAAQC,EAAGC,EAAGC,EAAI,CAC1B,IAAIC,EACAC,EACAC,
|
|
6
|
-
"names": ["require_main", "__commonJSMin", "exports", "module", "isnan", "isInfinite", "pow", "log10", "ln", "abs", "floor", "exponent", "ceil", "ceilsd", "x", "n", "b", "
|
|
4
|
+
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar isInfinite = require( '@stdlib/math-base-assert-is-infinite' );\nvar pow = require( '@stdlib/math-base-special-pow' );\nvar log10 = require( '@stdlib/math-base-special-log10' );\nvar ln = require( '@stdlib/math-base-special-ln' );\nvar abs = require( '@stdlib/math-base-special-abs' );\nvar floor = require( '@stdlib/math-base-special-floor' );\nvar exponent = require( '@stdlib/number-float64-base-exponent' );\nvar ceil = require( '@stdlib/math-base-special-ceil' );\n\n\n// MAIN //\n\n/**\n* Rounds a numeric value to the nearest number toward positive infinity with \\\\(n\\\\) significant figures.\n*\n* @param {number} x - input value\n* @param {PositiveInteger} n - number of significant figures\n* @param {PositiveInteger} b - base\n* @returns {number} rounded value\n*\n* @example\n* var v = ceilsd( 3.141592653589793, 5, 10 );\n* // returns 3.1416\n*\n* @example\n* var v = ceilsd( 3.141592653589793, 1, 10 );\n* // returns 4.0\n*\n* @example\n* var v = ceilsd( 12368.0, 2, 10 );\n* // returns 13000.0\n*\n* @example\n* var v = ceilsd( 0.0313, 2, 2 );\n* // returns 0.046875\n*/\nfunction ceilsd( x, n, b ) {\n\tvar exp;\n\tvar s;\n\tvar y;\n\tif (\n\t\tisnan( x ) ||\n\t\tisnan( n ) ||\n\t\tn < 1 ||\n\t\tisInfinite( n ) ||\n\t\tisnan( b ) ||\n\t\tb <= 0 ||\n\t\tisInfinite( b )\n\t) {\n\t\treturn NaN;\n\t}\n\tif ( isInfinite( x ) || x === 0.0 ) {\n\t\treturn x;\n\t}\n\tif ( b === 10 ) {\n\t\texp = log10( abs( x ) );\n\t}\n\telse if ( b === 2 ) {\n\t\texp = exponent( abs( x ) );\n\t}\n\telse {\n\t\texp = ln( abs(x) ) / ln( b );\n\t}\n\texp = floor( exp - n + 1.0 );\n\ts = pow( b, abs( exp ) );\n\n\t// Check for overflow:\n\tif ( isInfinite( s ) ) {\n\t\treturn x;\n\t}\n\t// To avoid numerical stability issues due to floating-point rounding error (e.g., 3.55/0.1-35.5 = -7.105427357601e-15 and 3.55*10-35.5 = 0), we must treat positive and negative exponents separately.\n\tif ( exp < 0 ) {\n\t\ty = ceil( x * s ) / s;\n\t} else {\n\t\ty = ceil( x / s ) * s;\n\t}\n\t// Check for overflow:\n\tif ( isInfinite( y ) ) {\n\t\treturn x;\n\t}\n\treturn y;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ceilsd;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Round a numeric value to the nearest number toward positive infinity with `n` significant figures.\n*\n* @module @stdlib/math-base-special-ceilsd\n*\n* @example\n* var ceilsd = require( '@stdlib/math-base-special-ceilsd' );\n*\n* var v = ceilsd( 3.141592653589793, 5, 10 );\n* // returns 3.1416\n*\n* v = ceilsd( 3.141592653589793, 1, 10 );\n* // returns 4.0\n*\n* v = ceilsd( 12368.0, 2, 10 );\n* // returns 13000.0\n*\n* v = ceilsd( 0.0313, 2, 2 );\n* // returns 0.046875\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
|
|
5
|
+
"mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAQ,QAAS,iCAAkC,EACnDC,EAAa,QAAS,sCAAuC,EAC7DC,EAAM,QAAS,+BAAgC,EAC/CC,EAAQ,QAAS,iCAAkC,EACnDC,EAAK,QAAS,8BAA+B,EAC7CC,EAAM,QAAS,+BAAgC,EAC/CC,EAAQ,QAAS,iCAAkC,EACnDC,EAAW,QAAS,sCAAuC,EAC3DC,EAAO,QAAS,gCAAiC,EA6BrD,SAASC,EAAQC,EAAGC,EAAGC,EAAI,CAC1B,IAAIC,EACAC,EACAC,EACJ,OACCf,EAAOU,CAAE,GACTV,EAAOW,CAAE,GACTA,EAAI,GACJV,EAAYU,CAAE,GACdX,EAAOY,CAAE,GACTA,GAAK,GACLX,EAAYW,CAAE,EAEP,IAEHX,EAAYS,CAAE,GAAKA,IAAM,IAGzBE,IAAM,GACVC,EAAMV,EAAOE,EAAKK,CAAE,CAAE,EAEbE,IAAM,EACfC,EAAMN,EAAUF,EAAKK,CAAE,CAAE,EAGzBG,EAAMT,EAAIC,EAAIK,CAAC,CAAE,EAAIN,EAAIQ,CAAE,EAE5BC,EAAMP,EAAOO,EAAMF,EAAI,CAAI,EAC3BG,EAAIZ,EAAKU,EAAGP,EAAKQ,CAAI,CAAE,EAGlBZ,EAAYa,CAAE,KAIdD,EAAM,EACVE,EAAIP,EAAME,EAAII,CAAE,EAAIA,EAEpBC,EAAIP,EAAME,EAAII,CAAE,EAAIA,EAGhBb,EAAYc,CAAE,GACXL,EAEDK,CACR,CAKAhB,EAAO,QAAUU,IClEjB,IAAIO,EAAO,IAKX,OAAO,QAAUA",
|
|
6
|
+
"names": ["require_main", "__commonJSMin", "exports", "module", "isnan", "isInfinite", "pow", "log10", "ln", "abs", "floor", "exponent", "ceil", "ceilsd", "x", "n", "b", "exp", "s", "y", "main"]
|
|
7
7
|
}
|
package/docs/types/index.d.ts
CHANGED
|
@@ -23,26 +23,26 @@
|
|
|
23
23
|
*
|
|
24
24
|
* @param x - input value
|
|
25
25
|
* @param n - number of significant figures
|
|
26
|
-
* @param b - base
|
|
26
|
+
* @param b - base
|
|
27
27
|
* @returns rounded value
|
|
28
28
|
*
|
|
29
29
|
* @example
|
|
30
|
-
* var v = ceilsd( 3.141592653589793, 5 );
|
|
30
|
+
* var v = ceilsd( 3.141592653589793, 5, 10 );
|
|
31
31
|
* // returns 3.1416
|
|
32
32
|
*
|
|
33
33
|
* @example
|
|
34
|
-
* var v = ceilsd( 3.141592653589793, 1 );
|
|
34
|
+
* var v = ceilsd( 3.141592653589793, 1, 10 );
|
|
35
35
|
* // returns 4.0
|
|
36
36
|
*
|
|
37
37
|
* @example
|
|
38
|
-
* var v = ceilsd( 12368.0, 2 );
|
|
38
|
+
* var v = ceilsd( 12368.0, 2, 10 );
|
|
39
39
|
* // returns 13000.0
|
|
40
40
|
*
|
|
41
41
|
* @example
|
|
42
42
|
* var v = ceilsd( 0.0313, 2, 2 );
|
|
43
43
|
* // returns 0.046875
|
|
44
44
|
*/
|
|
45
|
-
declare function ceilsd( x: number, n: number, b
|
|
45
|
+
declare function ceilsd( x: number, n: number, b: number ): number;
|
|
46
46
|
|
|
47
47
|
|
|
48
48
|
// EXPORTS //
|
|
@@ -0,0 +1,40 @@
|
|
|
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_CEILSD_H
|
|
20
|
+
#define STDLIB_MATH_BASE_SPECIAL_CEILSD_H
|
|
21
|
+
|
|
22
|
+
#include <stdint.h>
|
|
23
|
+
|
|
24
|
+
/*
|
|
25
|
+
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
|
|
26
|
+
*/
|
|
27
|
+
#ifdef __cplusplus
|
|
28
|
+
extern "C" {
|
|
29
|
+
#endif
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Rounds a numeric value to the nearest number toward positive infinity with \\(n\\) significant figures.
|
|
33
|
+
*/
|
|
34
|
+
double stdlib_base_ceilsd( const double x, const int32_t n, const int32_t b );
|
|
35
|
+
|
|
36
|
+
#ifdef __cplusplus
|
|
37
|
+
}
|
|
38
|
+
#endif
|
|
39
|
+
|
|
40
|
+
#endif // !STDLIB_MATH_BASE_SPECIAL_CEILSD_H
|
package/lib/index.js
CHANGED
|
@@ -26,13 +26,13 @@
|
|
|
26
26
|
* @example
|
|
27
27
|
* var ceilsd = require( '@stdlib/math-base-special-ceilsd' );
|
|
28
28
|
*
|
|
29
|
-
* var v = ceilsd( 3.141592653589793, 5 );
|
|
29
|
+
* var v = ceilsd( 3.141592653589793, 5, 10 );
|
|
30
30
|
* // returns 3.1416
|
|
31
31
|
*
|
|
32
|
-
* v = ceilsd( 3.141592653589793, 1 );
|
|
32
|
+
* v = ceilsd( 3.141592653589793, 1, 10 );
|
|
33
33
|
* // returns 4.0
|
|
34
34
|
*
|
|
35
|
-
* v = ceilsd( 12368.0, 2 );
|
|
35
|
+
* v = ceilsd( 12368.0, 2, 10 );
|
|
36
36
|
* // returns 13000.0
|
|
37
37
|
*
|
|
38
38
|
* v = ceilsd( 0.0313, 2, 2 );
|
package/lib/main.js
CHANGED
|
@@ -38,19 +38,19 @@ var ceil = require( '@stdlib/math-base-special-ceil' );
|
|
|
38
38
|
*
|
|
39
39
|
* @param {number} x - input value
|
|
40
40
|
* @param {PositiveInteger} n - number of significant figures
|
|
41
|
-
* @param {PositiveInteger}
|
|
41
|
+
* @param {PositiveInteger} b - base
|
|
42
42
|
* @returns {number} rounded value
|
|
43
43
|
*
|
|
44
44
|
* @example
|
|
45
|
-
* var v = ceilsd( 3.141592653589793, 5 );
|
|
45
|
+
* var v = ceilsd( 3.141592653589793, 5, 10 );
|
|
46
46
|
* // returns 3.1416
|
|
47
47
|
*
|
|
48
48
|
* @example
|
|
49
|
-
* var v = ceilsd( 3.141592653589793, 1 );
|
|
49
|
+
* var v = ceilsd( 3.141592653589793, 1, 10 );
|
|
50
50
|
* // returns 4.0
|
|
51
51
|
*
|
|
52
52
|
* @example
|
|
53
|
-
* var v = ceilsd( 12368.0, 2 );
|
|
53
|
+
* var v = ceilsd( 12368.0, 2, 10 );
|
|
54
54
|
* // returns 13000.0
|
|
55
55
|
*
|
|
56
56
|
* @example
|
|
@@ -58,7 +58,6 @@ var ceil = require( '@stdlib/math-base-special-ceil' );
|
|
|
58
58
|
* // returns 0.046875
|
|
59
59
|
*/
|
|
60
60
|
function ceilsd( x, n, b ) {
|
|
61
|
-
var base;
|
|
62
61
|
var exp;
|
|
63
62
|
var s;
|
|
64
63
|
var y;
|
|
@@ -66,36 +65,27 @@ function ceilsd( x, n, b ) {
|
|
|
66
65
|
isnan( x ) ||
|
|
67
66
|
isnan( n ) ||
|
|
68
67
|
n < 1 ||
|
|
69
|
-
isInfinite( n )
|
|
68
|
+
isInfinite( n ) ||
|
|
69
|
+
isnan( b ) ||
|
|
70
|
+
b <= 0 ||
|
|
71
|
+
isInfinite( b )
|
|
70
72
|
) {
|
|
71
73
|
return NaN;
|
|
72
74
|
}
|
|
73
|
-
if ( arguments.length > 2 ) {
|
|
74
|
-
if (
|
|
75
|
-
isnan( b ) ||
|
|
76
|
-
b <= 0 ||
|
|
77
|
-
isInfinite( b )
|
|
78
|
-
) {
|
|
79
|
-
return NaN;
|
|
80
|
-
}
|
|
81
|
-
base = b;
|
|
82
|
-
} else {
|
|
83
|
-
base = 10;
|
|
84
|
-
}
|
|
85
75
|
if ( isInfinite( x ) || x === 0.0 ) {
|
|
86
76
|
return x;
|
|
87
77
|
}
|
|
88
|
-
if (
|
|
78
|
+
if ( b === 10 ) {
|
|
89
79
|
exp = log10( abs( x ) );
|
|
90
80
|
}
|
|
91
|
-
else if (
|
|
81
|
+
else if ( b === 2 ) {
|
|
92
82
|
exp = exponent( abs( x ) );
|
|
93
83
|
}
|
|
94
84
|
else {
|
|
95
|
-
exp = ln( abs(x) ) / ln(
|
|
85
|
+
exp = ln( abs(x) ) / ln( b );
|
|
96
86
|
}
|
|
97
87
|
exp = floor( exp - n + 1.0 );
|
|
98
|
-
s = pow(
|
|
88
|
+
s = pow( b, abs( exp ) );
|
|
99
89
|
|
|
100
90
|
// Check for overflow:
|
|
101
91
|
if ( isInfinite( s ) ) {
|
package/lib/native.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
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 number toward positive infinity with \\(n\\) significant figures.
|
|
30
|
+
*
|
|
31
|
+
* @private
|
|
32
|
+
* @param {number} x - input value
|
|
33
|
+
* @param {PositiveInteger} n - number of significant figures
|
|
34
|
+
* @param {PositiveInteger} b - base
|
|
35
|
+
* @returns {number} rounded value
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* var v = ceilsd( 3.141592653589793, 5, 10 );
|
|
39
|
+
* // returns 3.1416
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* var v = ceilsd( 3.141592653589793, 1, 10 );
|
|
43
|
+
* // returns 4.0
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* var v = ceilsd( 12368.0, 2, 10 );
|
|
47
|
+
* // returns 13000.0
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* var v = ceilsd( 0.0313, 2, 2 );
|
|
51
|
+
* // returns 0.046875
|
|
52
|
+
*/
|
|
53
|
+
function ceilsd( x, n, b ) {
|
|
54
|
+
return addon( x, n, b );
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
// EXPORTS //
|
|
59
|
+
|
|
60
|
+
module.exports = ceilsd;
|
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-ternary",
|
|
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-log10",
|
|
44
|
+
"@stdlib/math-base-special-ln",
|
|
45
|
+
"@stdlib/math-base-special-abs",
|
|
46
|
+
"@stdlib/math-base-special-floor",
|
|
47
|
+
"@stdlib/math-base-special-ceil",
|
|
48
|
+
"@stdlib/number-float64-base-exponent"
|
|
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-log10",
|
|
66
|
+
"@stdlib/math-base-special-ln",
|
|
67
|
+
"@stdlib/math-base-special-abs",
|
|
68
|
+
"@stdlib/math-base-special-floor",
|
|
69
|
+
"@stdlib/math-base-special-ceil",
|
|
70
|
+
"@stdlib/number-float64-base-exponent"
|
|
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-log10",
|
|
88
|
+
"@stdlib/math-base-special-ln",
|
|
89
|
+
"@stdlib/math-base-special-abs",
|
|
90
|
+
"@stdlib/math-base-special-floor",
|
|
91
|
+
"@stdlib/math-base-special-ceil",
|
|
92
|
+
"@stdlib/number-float64-base-exponent"
|
|
93
|
+
]
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/math-base-special-ceilsd",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Round a numeric value to the nearest number toward positive infinity with N significant figures.",
|
|
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,15 +33,17 @@
|
|
|
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-
|
|
38
|
-
"@stdlib/math-base-special-
|
|
39
|
-
"@stdlib/math-base-special-
|
|
40
|
-
"@stdlib/math-base-special-
|
|
41
|
-
"@stdlib/
|
|
36
|
+
"@stdlib/math-base-assert-is-infinite": "^0.2.3",
|
|
37
|
+
"@stdlib/math-base-assert-is-nan": "^0.2.3",
|
|
38
|
+
"@stdlib/math-base-napi-ternary": "^0.3.2",
|
|
39
|
+
"@stdlib/math-base-special-abs": "^0.2.3",
|
|
40
|
+
"@stdlib/math-base-special-ceil": "^0.2.3",
|
|
41
|
+
"@stdlib/math-base-special-floor": "^0.2.4",
|
|
42
|
+
"@stdlib/math-base-special-ln": "^0.2.5",
|
|
43
|
+
"@stdlib/math-base-special-log10": "^0.3.1",
|
|
44
|
+
"@stdlib/math-base-special-pow": "^0.3.0",
|
|
45
|
+
"@stdlib/number-float64-base-exponent": "^0.2.3",
|
|
46
|
+
"@stdlib/utils-library-manifest": "^0.2.4"
|
|
42
47
|
},
|
|
43
48
|
"devDependencies": {},
|
|
44
49
|
"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/ceilsd.h"
|
|
20
|
+
#include "stdlib/math/base/napi/ternary.h"
|
|
21
|
+
|
|
22
|
+
STDLIB_MATH_BASE_NAPI_MODULE_DII_D( stdlib_base_ceilsd )
|
package/src/main.c
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
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/ceilsd.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/log10.h"
|
|
24
|
+
#include "stdlib/math/base/special/ln.h"
|
|
25
|
+
#include "stdlib/math/base/special/abs.h"
|
|
26
|
+
#include "stdlib/math/base/special/floor.h"
|
|
27
|
+
#include "stdlib/math/base/special/ceil.h"
|
|
28
|
+
#include "stdlib/number/float64/base/exponent.h"
|
|
29
|
+
#include <stdint.h>
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Rounds a numeric value to the nearest number toward positive infinity with \\(n\\) significant figures.
|
|
33
|
+
*
|
|
34
|
+
* @param x input value
|
|
35
|
+
* @param n number of significant figures
|
|
36
|
+
* @param b base
|
|
37
|
+
* @return rounded value
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* double out = stdlib_base_ceilsd( 3.141592653589793, 5, 10 );
|
|
41
|
+
* // returns 3.1416
|
|
42
|
+
*/
|
|
43
|
+
double stdlib_base_ceilsd( const double x, const int32_t n, const int32_t b ) {
|
|
44
|
+
double exp;
|
|
45
|
+
double s;
|
|
46
|
+
double y;
|
|
47
|
+
|
|
48
|
+
if ( stdlib_base_is_nan( x ) || n < 1 || b <= 0 ) {
|
|
49
|
+
return 0.0 / 0.0; // NaN
|
|
50
|
+
}
|
|
51
|
+
if ( stdlib_base_is_infinite( x ) || x == 0.0 ) {
|
|
52
|
+
return x;
|
|
53
|
+
}
|
|
54
|
+
if ( b == 10 ) {
|
|
55
|
+
exp = stdlib_base_log10( stdlib_base_abs( x ) );
|
|
56
|
+
} else if ( b == 2 ) {
|
|
57
|
+
exp = stdlib_base_float64_exponent( stdlib_base_abs( x ) );
|
|
58
|
+
} else {
|
|
59
|
+
exp = stdlib_base_ln( stdlib_base_abs( x ) ) / stdlib_base_ln( (double)b );
|
|
60
|
+
}
|
|
61
|
+
exp = stdlib_base_floor( exp - (double)n + 1.0 );
|
|
62
|
+
s = stdlib_base_pow( (double)b, stdlib_base_abs( exp ) );
|
|
63
|
+
|
|
64
|
+
// Check for overflow:
|
|
65
|
+
if ( stdlib_base_is_infinite( s ) ) {
|
|
66
|
+
return x;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// To avoid numerical stability issues due to floating-point rounding error (e.g., 3.55/0.1-35.5 = -7.105427357601e-15 and 3.55*10-35.5 = 0), we must treat positive and negative exponents separately.
|
|
70
|
+
if ( exp < 0 ) {
|
|
71
|
+
y = stdlib_base_ceil( x * s ) / s;
|
|
72
|
+
} else {
|
|
73
|
+
y = stdlib_base_ceil( x / s ) * s;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Check for overflow:
|
|
77
|
+
if ( stdlib_base_is_infinite( y ) ) {
|
|
78
|
+
return x;
|
|
79
|
+
}
|
|
80
|
+
return y;
|
|
81
|
+
}
|