Skip to content

Commit 3f7f442

Browse files
committed
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into develop
2 parents 7078536 + e9ae1f4 commit 3f7f442

3 files changed

Lines changed: 23 additions & 12 deletions

File tree

lib/node_modules/@stdlib/constants/float64/max-base10-exponent-subnormal/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ console.log( FLOAT64_MAX_BASE10_EXPONENT_SUBNORMAL );
9191
### Usage
9292

9393
```c
94-
#include "stdlib/constants/float64/max_base10_exponent.h"
94+
#include "stdlib/constants/float64/max_base10_exponent_subnormal.h"
9595
```
9696

97-
#### STDLIB_CONSTANT_FLOAT64_MAX_BASE10_EXPONENT
97+
#### STDLIB_CONSTANT_FLOAT64_MAX_BASE10_EXPONENT_SUBNORMAL
9898

9999
Macro for the maximum base 10 exponent for a subnormal [double-precision floating-point number][ieee754].
100100

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@
4040
"dependencies": [
4141
"@stdlib/math/base/napi/binary",
4242
"@stdlib/math/base/special/abs",
43-
"@stdlib/constants/float64/max",
43+
"@stdlib/math/base/special/round",
44+
"@stdlib/constants/float64/max-safe-integer",
4445
"@stdlib/constants/float64/max-base10-exponent",
4546
"@stdlib/constants/float64/min-base10-exponent",
47+
"@stdlib/constants/float64/min-base10-exponent-subnormal",
4648
"@stdlib/math/base/assert/is-infinite"
4749
]
4850
},
@@ -60,9 +62,11 @@
6062
"libpath": [],
6163
"dependencies": [
6264
"@stdlib/math/base/special/abs",
63-
"@stdlib/constants/float64/max",
65+
"@stdlib/math/base/special/round",
66+
"@stdlib/constants/float64/max-safe-integer",
6467
"@stdlib/constants/float64/max-base10-exponent",
6568
"@stdlib/constants/float64/min-base10-exponent",
69+
"@stdlib/constants/float64/min-base10-exponent-subnormal",
6670
"@stdlib/math/base/assert/is-infinite"
6771
]
6872
},
@@ -80,9 +84,11 @@
8084
"libpath": [],
8185
"dependencies": [
8286
"@stdlib/math/base/special/abs",
83-
"@stdlib/constants/float64/max",
87+
"@stdlib/math/base/special/round",
88+
"@stdlib/constants/float64/max-safe-integer",
8489
"@stdlib/constants/float64/max-base10-exponent",
8590
"@stdlib/constants/float64/min-base10-exponent",
91+
"@stdlib/constants/float64/min-base10-exponent-subnormal",
8692
"@stdlib/math/base/assert/is-infinite"
8793
]
8894
}

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@
1919
#include "stdlib/math/base/special/roundn.h"
2020
#include "stdlib/math/base/assert/is_infinite.h"
2121
#include "stdlib/math/base/special/abs.h"
22-
#include "stdlib/constants/float64/max.h"
22+
#include "stdlib/math/base/special/round.h"
23+
#include "stdlib/constants/float64/max_safe_integer.h"
2324
#include "stdlib/constants/float64/max_base10_exponent.h"
2425
#include "stdlib/constants/float64/min_base10_exponent.h"
26+
#include "stdlib/constants/float64/min_base10_exponent_subnormal.h"
2527
#include <stdint.h>
2628
#include <math.h>
2729

30+
static const double MAX_INT = STDLIB_CONSTANT_FLOAT64_MAX_SAFE_INTEGER + 1.0;
31+
static const double HUGE_VALUE = 1.0e+308;
32+
2833
/**
2934
* Rounds a double-precision floating-point number to the nearest multiple of `10^n`.
3035
*
@@ -111,7 +116,7 @@ double stdlib_base_roundn( const double x, const int32_t n ) {
111116
double y;
112117

113118
if ( isnan( x ) ){
114-
return NAN;
119+
return 0.0 / 0.0; // NaN
115120
}
116121

117122
if (
@@ -122,10 +127,10 @@ double stdlib_base_roundn( const double x, const int32_t n ) {
122127
x == 0.0 ||
123128

124129
// If `n` exceeds the maximum number of feasible decimal places (such as with subnormal numbers), nothing to round...
125-
n < STDLIB_CONSTANT_FLOAT64_MIN_BASE10_EXPONENT ||
130+
n < STDLIB_CONSTANT_FLOAT64_MIN_BASE10_EXPONENT_SUBNORMAL ||
126131

127132
// If `|x|` is large enough, no decimals to round...
128-
( stdlib_base_abs( x ) > STDLIB_CONSTANT_FLOAT64_MAX && n <= 0 )
133+
( stdlib_base_abs( x ) > MAX_INT && n <= 0 )
129134
) {
130135
return x;
131136
}
@@ -136,16 +141,16 @@ double stdlib_base_roundn( const double x, const int32_t n ) {
136141
// 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...
137142
if ( n < STDLIB_CONSTANT_FLOAT64_MIN_BASE10_EXPONENT ){
138143
s = pow( 10.0, -( n + STDLIB_CONSTANT_FLOAT64_MAX_BASE10_EXPONENT ) ); // TODO: replace use of `pow` once have stdlib equivalent
139-
y = ( x * HUGE ) * s; // order of operation matters!
144+
y = ( x * HUGE_VALUE ) * s; // order of operation matters!
140145
if ( stdlib_base_is_infinite( y ) ){
141146
return x;
142147
}
143-
return ( round( y ) / HUGE ) / s; // TODO: replace with stdlib round function once implemented
148+
return ( stdlib_base_round( y ) / HUGE_VALUE ) / s;
144149
}
145150
s = pow( 10.0, -n ); // TODO: replace use of `pow` once have stdlib equivalent
146151
y = x * s;
147152
if ( stdlib_base_is_infinite( y ) ){
148153
return x;
149154
}
150-
return round( y ) / s; // TODO: replace with stdlib round function once implemented
155+
return stdlib_base_round( y ) / s;
151156
}

0 commit comments

Comments
 (0)