Skip to content

Commit ca18359

Browse files
authored
refactor: update to use stdlib pow
PR-URL: #2539 Reviewed-by: Athan Reines <[email protected]>
1 parent efc3551 commit ca18359

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

lib/node_modules/@stdlib/math/base/special/roundn/manifest.json

+12-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
{
2929
"task": "build",
3030
"src": [
31-
"./src/roundn.c"
31+
"./src/main.c"
3232
],
3333
"include": [
3434
"./include"
@@ -41,17 +41,19 @@
4141
"@stdlib/math/base/napi/binary",
4242
"@stdlib/math/base/special/abs",
4343
"@stdlib/math/base/special/round",
44+
"@stdlib/math/base/special/pow",
4445
"@stdlib/constants/float64/max-safe-integer",
4546
"@stdlib/constants/float64/max-base10-exponent",
4647
"@stdlib/constants/float64/min-base10-exponent",
4748
"@stdlib/constants/float64/min-base10-exponent-subnormal",
48-
"@stdlib/math/base/assert/is-infinite"
49+
"@stdlib/math/base/assert/is-infinite",
50+
"@stdlib/math/base/assert/is-nan"
4951
]
5052
},
5153
{
5254
"task": "benchmark",
5355
"src": [
54-
"./src/roundn.c"
56+
"./src/main.c"
5557
],
5658
"include": [
5759
"./include"
@@ -63,17 +65,19 @@
6365
"dependencies": [
6466
"@stdlib/math/base/special/abs",
6567
"@stdlib/math/base/special/round",
68+
"@stdlib/math/base/special/pow",
6669
"@stdlib/constants/float64/max-safe-integer",
6770
"@stdlib/constants/float64/max-base10-exponent",
6871
"@stdlib/constants/float64/min-base10-exponent",
6972
"@stdlib/constants/float64/min-base10-exponent-subnormal",
70-
"@stdlib/math/base/assert/is-infinite"
73+
"@stdlib/math/base/assert/is-infinite",
74+
"@stdlib/math/base/assert/is-nan"
7175
]
7276
},
7377
{
7478
"task": "examples",
7579
"src": [
76-
"./src/roundn.c"
80+
"./src/main.c"
7781
],
7882
"include": [
7983
"./include"
@@ -85,11 +89,13 @@
8589
"dependencies": [
8690
"@stdlib/math/base/special/abs",
8791
"@stdlib/math/base/special/round",
92+
"@stdlib/math/base/special/pow",
8893
"@stdlib/constants/float64/max-safe-integer",
8994
"@stdlib/constants/float64/max-base10-exponent",
9095
"@stdlib/constants/float64/min-base10-exponent",
9196
"@stdlib/constants/float64/min-base10-exponent-subnormal",
92-
"@stdlib/math/base/assert/is-infinite"
97+
"@stdlib/math/base/assert/is-infinite",
98+
"@stdlib/math/base/assert/is-nan"
9399
]
94100
}
95101
]

lib/node_modules/@stdlib/math/base/special/roundn/src/roundn.c lib/node_modules/@stdlib/math/base/special/roundn/src/main.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818

1919
#include "stdlib/math/base/special/roundn.h"
2020
#include "stdlib/math/base/assert/is_infinite.h"
21+
#include "stdlib/math/base/assert/is_nan.h"
2122
#include "stdlib/math/base/special/abs.h"
2223
#include "stdlib/math/base/special/round.h"
24+
#include "stdlib/math/base/special/pow.h"
2325
#include "stdlib/constants/float64/max_safe_integer.h"
2426
#include "stdlib/constants/float64/max_base10_exponent.h"
2527
#include "stdlib/constants/float64/min_base10_exponent.h"
2628
#include "stdlib/constants/float64/min_base10_exponent_subnormal.h"
2729
#include <stdint.h>
28-
#include <math.h>
2930

3031
static const double MAX_INT = STDLIB_CONSTANT_FLOAT64_MAX_SAFE_INTEGER + 1.0;
3132
static const double HUGE_VALUE = 1.0e+308;
@@ -115,7 +116,7 @@ double stdlib_base_roundn( const double x, const int32_t n ) {
115116
double s;
116117
double y;
117118

118-
if ( isnan( x ) ){
119+
if ( stdlib_base_is_nan( x ) ){
119120
return 0.0 / 0.0; // NaN
120121
}
121122

@@ -140,14 +141,14 @@ double stdlib_base_roundn( const double x, const int32_t n ) {
140141
}
141142
// If we overflow, return `x`, as the number of digits to the right of the decimal is too small (i.e., `x` is too large / lacks sufficient fractional precision) for there to be any effect when rounding...
142143
if ( n < STDLIB_CONSTANT_FLOAT64_MIN_BASE10_EXPONENT ){
143-
s = pow( 10.0, -( n + STDLIB_CONSTANT_FLOAT64_MAX_BASE10_EXPONENT ) ); // TODO: replace use of `pow` once have stdlib equivalent
144+
s = stdlib_base_pow( 10.0, -( n + STDLIB_CONSTANT_FLOAT64_MAX_BASE10_EXPONENT ) );
144145
y = ( x * HUGE_VALUE ) * s; // order of operation matters!
145146
if ( stdlib_base_is_infinite( y ) ){
146147
return x;
147148
}
148149
return ( stdlib_base_round( y ) / HUGE_VALUE ) / s;
149150
}
150-
s = pow( 10.0, -n ); // TODO: replace use of `pow` once have stdlib equivalent
151+
s = stdlib_base_pow( 10.0, -n );
151152
y = x * s;
152153
if ( stdlib_base_is_infinite( y ) ){
153154
return x;

0 commit comments

Comments
 (0)