@stdlib/math-base-special-floor10 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 +96 -13
- package/include/stdlib/math/base/special/floor10.h +38 -0
- package/lib/native.js +54 -0
- package/manifest.json +102 -0
- package/package.json +15 -10
- package/src/addon.c +22 -0
- package/src/main.c +76 -0
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -121,17 +121,96 @@ v = floor10( NaN );
|
|
|
121
121
|
<!-- eslint no-undef: "error" -->
|
|
122
122
|
|
|
123
123
|
```javascript
|
|
124
|
-
var
|
|
124
|
+
var uniform = require( '@stdlib/random-array-uniform' );
|
|
125
|
+
var logEachMap = require( '@stdlib/console-log-each-map' );
|
|
125
126
|
var floor10 = require( '@stdlib/math-base-special-floor10' );
|
|
126
127
|
|
|
127
|
-
var
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
var opts = {
|
|
129
|
+
'dtype': 'float64'
|
|
130
|
+
};
|
|
131
|
+
var x = uniform( 100, -50.0, 50.0, opts );
|
|
130
132
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
133
|
+
logEachMap( 'x: %0.4f. Rounded: %d.', x, floor10 );
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
</section>
|
|
137
|
+
|
|
138
|
+
<!-- /.examples -->
|
|
139
|
+
|
|
140
|
+
<!-- C interface documentation. -->
|
|
141
|
+
|
|
142
|
+
* * *
|
|
143
|
+
|
|
144
|
+
<section class="c">
|
|
145
|
+
|
|
146
|
+
## C APIs
|
|
147
|
+
|
|
148
|
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
|
|
149
|
+
|
|
150
|
+
<section class="intro">
|
|
151
|
+
|
|
152
|
+
</section>
|
|
153
|
+
|
|
154
|
+
<!-- /.intro -->
|
|
155
|
+
|
|
156
|
+
<!-- C usage documentation. -->
|
|
157
|
+
|
|
158
|
+
<section class="usage">
|
|
159
|
+
|
|
160
|
+
### Usage
|
|
161
|
+
|
|
162
|
+
```c
|
|
163
|
+
#include "stdlib/math/base/special/floor10.h"
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
#### stdlib_base_floor10( x )
|
|
167
|
+
|
|
168
|
+
Rounds a `numeric` value to the nearest power of `10` toward negative infinity.
|
|
169
|
+
|
|
170
|
+
```c
|
|
171
|
+
double y = stdlib_base_floor10( -4.2 );
|
|
172
|
+
// returns -10.0
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
The function accepts the following arguments:
|
|
176
|
+
|
|
177
|
+
- **x**: `[in] double` input value.
|
|
178
|
+
|
|
179
|
+
```c
|
|
180
|
+
double stdlib_base_floor10( const double x );
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
</section>
|
|
184
|
+
|
|
185
|
+
<!-- /.usage -->
|
|
186
|
+
|
|
187
|
+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
188
|
+
|
|
189
|
+
<section class="notes">
|
|
190
|
+
|
|
191
|
+
</section>
|
|
192
|
+
|
|
193
|
+
<!-- /.notes -->
|
|
194
|
+
|
|
195
|
+
<!-- C API usage examples. -->
|
|
196
|
+
|
|
197
|
+
<section class="examples">
|
|
198
|
+
|
|
199
|
+
### Examples
|
|
200
|
+
|
|
201
|
+
```c
|
|
202
|
+
#include "stdlib/math/base/special/floor10.h"
|
|
203
|
+
#include <stdio.h>
|
|
204
|
+
|
|
205
|
+
int main( void ) {
|
|
206
|
+
const double x[] = { 3.14, -3.14, 0.0, 9.0 / 0.0 };
|
|
207
|
+
|
|
208
|
+
double y;
|
|
209
|
+
int i;
|
|
210
|
+
for ( i = 0; i < 4; i++ ) {
|
|
211
|
+
y = stdlib_base_floor10( x[ i ] );
|
|
212
|
+
printf( "floor10(%lf) = %lf\n", x[ i ], y );
|
|
213
|
+
}
|
|
135
214
|
}
|
|
136
215
|
```
|
|
137
216
|
|
|
@@ -139,6 +218,10 @@ for ( i = 0; i < 100; i++ ) {
|
|
|
139
218
|
|
|
140
219
|
<!-- /.examples -->
|
|
141
220
|
|
|
221
|
+
</section>
|
|
222
|
+
|
|
223
|
+
<!-- /.c -->
|
|
224
|
+
|
|
142
225
|
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
143
226
|
|
|
144
227
|
<section class="related">
|
|
@@ -182,7 +265,7 @@ See [LICENSE][stdlib-license].
|
|
|
182
265
|
|
|
183
266
|
## Copyright
|
|
184
267
|
|
|
185
|
-
Copyright © 2016-
|
|
268
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
186
269
|
|
|
187
270
|
</section>
|
|
188
271
|
|
|
@@ -195,8 +278,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
195
278
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/math-base-special-floor10.svg
|
|
196
279
|
[npm-url]: https://npmjs.org/package/@stdlib/math-base-special-floor10
|
|
197
280
|
|
|
198
|
-
[test-image]: https://github.com/stdlib-js/math-base-special-floor10/actions/workflows/test.yml/badge.svg?branch=v0.
|
|
199
|
-
[test-url]: https://github.com/stdlib-js/math-base-special-floor10/actions/workflows/test.yml?query=branch:v0.
|
|
281
|
+
[test-image]: https://github.com/stdlib-js/math-base-special-floor10/actions/workflows/test.yml/badge.svg?branch=v0.3.1
|
|
282
|
+
[test-url]: https://github.com/stdlib-js/math-base-special-floor10/actions/workflows/test.yml?query=branch:v0.3.1
|
|
200
283
|
|
|
201
284
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/math-base-special-floor10/main.svg
|
|
202
285
|
[coverage-url]: https://codecov.io/github/stdlib-js/math-base-special-floor10?branch=main
|
|
@@ -208,8 +291,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
208
291
|
|
|
209
292
|
-->
|
|
210
293
|
|
|
211
|
-
[chat-image]: https://img.shields.io/
|
|
212
|
-
[chat-url]: https://
|
|
294
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
295
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
213
296
|
|
|
214
297
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
215
298
|
|
|
@@ -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_FLOOR10_H
|
|
20
|
+
#define STDLIB_MATH_BASE_SPECIAL_FLOOR10_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 negative infinity.
|
|
31
|
+
*/
|
|
32
|
+
double stdlib_base_floor10( const double x );
|
|
33
|
+
|
|
34
|
+
#ifdef __cplusplus
|
|
35
|
+
}
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
#endif // !STDLIB_MATH_BASE_SPECIAL_FLOOR10_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 negative infinity.
|
|
30
|
+
*
|
|
31
|
+
* @private
|
|
32
|
+
* @param {number} x - input value
|
|
33
|
+
* @returns {number} rounded value
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* var v = floor10( 3.141592653589793 );
|
|
37
|
+
* // returns 1.0
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* var v = floor10( 9.0 );
|
|
41
|
+
* // returns 1.0
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* var v = floor10( -0.314 );
|
|
45
|
+
* // returns -1.0
|
|
46
|
+
*/
|
|
47
|
+
function floor10( x ) {
|
|
48
|
+
return addon( x );
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
// EXPORTS //
|
|
53
|
+
|
|
54
|
+
module.exports = floor10;
|
package/manifest.json
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
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-assert-is-nan",
|
|
43
|
+
"@stdlib/math-base-assert-is-infinite",
|
|
44
|
+
"@stdlib/math-base-special-pow",
|
|
45
|
+
"@stdlib/math-base-special-floor",
|
|
46
|
+
"@stdlib/math-base-special-ceil",
|
|
47
|
+
"@stdlib/math-base-special-log10",
|
|
48
|
+
"@stdlib/constants-float64-max-base10-exponent",
|
|
49
|
+
"@stdlib/constants-float64-min-base10-exponent-subnormal",
|
|
50
|
+
"@stdlib/constants-float64-ninf"
|
|
51
|
+
]
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"task": "benchmark",
|
|
55
|
+
"src": [
|
|
56
|
+
"./src/main.c"
|
|
57
|
+
],
|
|
58
|
+
"include": [
|
|
59
|
+
"./include"
|
|
60
|
+
],
|
|
61
|
+
"libraries": [
|
|
62
|
+
"-lm"
|
|
63
|
+
],
|
|
64
|
+
"libpath": [],
|
|
65
|
+
"dependencies": [
|
|
66
|
+
"@stdlib/math-base-assert-is-nan",
|
|
67
|
+
"@stdlib/math-base-assert-is-infinite",
|
|
68
|
+
"@stdlib/math-base-special-pow",
|
|
69
|
+
"@stdlib/math-base-special-floor",
|
|
70
|
+
"@stdlib/math-base-special-ceil",
|
|
71
|
+
"@stdlib/math-base-special-log10",
|
|
72
|
+
"@stdlib/constants-float64-max-base10-exponent",
|
|
73
|
+
"@stdlib/constants-float64-min-base10-exponent-subnormal",
|
|
74
|
+
"@stdlib/constants-float64-ninf"
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"task": "examples",
|
|
79
|
+
"src": [
|
|
80
|
+
"./src/main.c"
|
|
81
|
+
],
|
|
82
|
+
"include": [
|
|
83
|
+
"./include"
|
|
84
|
+
],
|
|
85
|
+
"libraries": [
|
|
86
|
+
"-lm"
|
|
87
|
+
],
|
|
88
|
+
"libpath": [],
|
|
89
|
+
"dependencies": [
|
|
90
|
+
"@stdlib/math-base-assert-is-nan",
|
|
91
|
+
"@stdlib/math-base-assert-is-infinite",
|
|
92
|
+
"@stdlib/math-base-special-pow",
|
|
93
|
+
"@stdlib/math-base-special-floor",
|
|
94
|
+
"@stdlib/math-base-special-ceil",
|
|
95
|
+
"@stdlib/math-base-special-log10",
|
|
96
|
+
"@stdlib/constants-float64-max-base10-exponent",
|
|
97
|
+
"@stdlib/constants-float64-min-base10-exponent-subnormal",
|
|
98
|
+
"@stdlib/constants-float64-ninf"
|
|
99
|
+
]
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/math-base-special-floor10",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Round a numeric value to the nearest power of 10 toward negative infinity.",
|
|
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/constants-float64-max-base10-exponent": "^0.2.
|
|
34
|
-
"@stdlib/constants-float64-min-base10-exponent-subnormal": "^0.2.
|
|
35
|
-
"@stdlib/constants-float64-ninf": "^0.2.
|
|
36
|
-
"@stdlib/math-base-assert-is-infinite": "^0.2.
|
|
37
|
-
"@stdlib/math-base-assert-is-nan": "^0.2.
|
|
38
|
-
"@stdlib/math-base-
|
|
39
|
-
"@stdlib/math-base-special-
|
|
40
|
-
"@stdlib/math-base-special-
|
|
41
|
-
"@stdlib/math-base-special-
|
|
36
|
+
"@stdlib/constants-float64-max-base10-exponent": "^0.2.3",
|
|
37
|
+
"@stdlib/constants-float64-min-base10-exponent-subnormal": "^0.2.1",
|
|
38
|
+
"@stdlib/constants-float64-ninf": "^0.2.3",
|
|
39
|
+
"@stdlib/math-base-assert-is-infinite": "^0.2.3",
|
|
40
|
+
"@stdlib/math-base-assert-is-nan": "^0.2.3",
|
|
41
|
+
"@stdlib/math-base-napi-unary": "^0.2.7",
|
|
42
|
+
"@stdlib/math-base-special-ceil": "^0.2.3",
|
|
43
|
+
"@stdlib/math-base-special-floor": "^0.2.4",
|
|
44
|
+
"@stdlib/math-base-special-log10": "^0.3.1",
|
|
45
|
+
"@stdlib/math-base-special-pow": "^0.3.0",
|
|
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/floor10.h"
|
|
20
|
+
#include "stdlib/math/base/napi/unary.h"
|
|
21
|
+
|
|
22
|
+
STDLIB_MATH_BASE_NAPI_MODULE_D_D( stdlib_base_floor10 )
|
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/floor10.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/log10.h"
|
|
26
|
+
#include "stdlib/constants/float64/max_base10_exponent.h"
|
|
27
|
+
#include "stdlib/constants/float64/min_base10_exponent_subnormal.h"
|
|
28
|
+
#include "stdlib/constants/float64/ninf.h"
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Rounds a numeric value to the nearest power of `10` toward negative infinity.
|
|
32
|
+
*
|
|
33
|
+
* @param x input value
|
|
34
|
+
* @return rounded value
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* double y = stdlib_base_floor10( 3.141592653589793 );
|
|
38
|
+
* // returns 1.0
|
|
39
|
+
*/
|
|
40
|
+
double stdlib_base_floor10( const double x ) {
|
|
41
|
+
double sign;
|
|
42
|
+
double xc;
|
|
43
|
+
double p;
|
|
44
|
+
|
|
45
|
+
if ( stdlib_base_is_nan( x ) || stdlib_base_is_infinite( x ) || x == 0.0 ) {
|
|
46
|
+
return x;
|
|
47
|
+
}
|
|
48
|
+
xc = x;
|
|
49
|
+
if ( x < 0 ) {
|
|
50
|
+
xc = -xc;
|
|
51
|
+
sign = -1.0;
|
|
52
|
+
} else {
|
|
53
|
+
sign = 1.0;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Solve the equation `10^p = x` for `p`:
|
|
57
|
+
p = stdlib_base_log10( xc );
|
|
58
|
+
|
|
59
|
+
// Determine a power of `10` which rounds the input value toward negative infinity:
|
|
60
|
+
if ( sign == 1.0 ) {
|
|
61
|
+
p = stdlib_base_floor( p );
|
|
62
|
+
} else {
|
|
63
|
+
p = stdlib_base_ceil( p );
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Handle underflow:
|
|
67
|
+
if ( p <= STDLIB_CONSTANT_FLOAT64_MIN_BASE10_EXPONENT_SUBNORMAL ) {
|
|
68
|
+
return sign * 0.0; // sign-preserving
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Handle overflow:
|
|
72
|
+
if ( p > STDLIB_CONSTANT_FLOAT64_MAX_BASE10_EXPONENT ) {
|
|
73
|
+
return STDLIB_CONSTANT_FLOAT64_NINF;
|
|
74
|
+
}
|
|
75
|
+
return sign * stdlib_base_pow( 10.0, p );
|
|
76
|
+
}
|