Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Jul 9, 2024
1 parent b1be26f commit 255b21c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<section class="release" id="unreleased">

## Unreleased (2024-07-08)
## Unreleased (2024-07-09)

<section class="packages">

Expand Down Expand Up @@ -4922,6 +4922,7 @@ A total of 29 people contributed to this release. Thank you to the following con

<details>

- [`ca18359`](https://github.com/stdlib-js/stdlib/commit/ca18359c4b18000828a214bc52a32db7ac6c1121) - **refactor:** update to use stdlib `pow` [(#2539)](https://github.com/stdlib-js/stdlib/pull/2539) _(by Gunj Joshi)_
- [`efc3551`](https://github.com/stdlib-js/stdlib/commit/efc3551764c30c6cae9a48058cae2868d4055190) - **feat:** add C implementation for `math/base/special/round2` [(##2537)](#2537) _(by Gunj Joshi)_
- [`62e703a`](https://github.com/stdlib-js/stdlib/commit/62e703a5eb7df95a40b3592366da89c5ff42a1b1) - **docs:** add missing `@private` in `math/base/special/round/lib/native.js` [(##2536)](#2536) _(by Gunj Joshi)_
- [`659f752`](https://github.com/stdlib-js/stdlib/commit/659f752db18317bf5fc237fdbcad0d74b61e1ed9) - **style:** add missing spaces _(by Philipp Burckhardt)_
Expand Down
18 changes: 12 additions & 6 deletions base/special/roundn/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
{
"task": "build",
"src": [
"./src/roundn.c"
"./src/main.c"
],
"include": [
"./include"
Expand All @@ -41,17 +41,19 @@
"@stdlib/math/base/napi/binary",
"@stdlib/math/base/special/abs",
"@stdlib/math/base/special/round",
"@stdlib/math/base/special/pow",
"@stdlib/constants/float64/max-safe-integer",
"@stdlib/constants/float64/max-base10-exponent",
"@stdlib/constants/float64/min-base10-exponent",
"@stdlib/constants/float64/min-base10-exponent-subnormal",
"@stdlib/math/base/assert/is-infinite"
"@stdlib/math/base/assert/is-infinite",
"@stdlib/math/base/assert/is-nan"
]
},
{
"task": "benchmark",
"src": [
"./src/roundn.c"
"./src/main.c"
],
"include": [
"./include"
Expand All @@ -63,17 +65,19 @@
"dependencies": [
"@stdlib/math/base/special/abs",
"@stdlib/math/base/special/round",
"@stdlib/math/base/special/pow",
"@stdlib/constants/float64/max-safe-integer",
"@stdlib/constants/float64/max-base10-exponent",
"@stdlib/constants/float64/min-base10-exponent",
"@stdlib/constants/float64/min-base10-exponent-subnormal",
"@stdlib/math/base/assert/is-infinite"
"@stdlib/math/base/assert/is-infinite",
"@stdlib/math/base/assert/is-nan"
]
},
{
"task": "examples",
"src": [
"./src/roundn.c"
"./src/main.c"
],
"include": [
"./include"
Expand All @@ -85,11 +89,13 @@
"dependencies": [
"@stdlib/math/base/special/abs",
"@stdlib/math/base/special/round",
"@stdlib/math/base/special/pow",
"@stdlib/constants/float64/max-safe-integer",
"@stdlib/constants/float64/max-base10-exponent",
"@stdlib/constants/float64/min-base10-exponent",
"@stdlib/constants/float64/min-base10-exponent-subnormal",
"@stdlib/math/base/assert/is-infinite"
"@stdlib/math/base/assert/is-infinite",
"@stdlib/math/base/assert/is-nan"
]
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@

#include "stdlib/math/base/special/roundn.h"
#include "stdlib/math/base/assert/is_infinite.h"
#include "stdlib/math/base/assert/is_nan.h"
#include "stdlib/math/base/special/abs.h"
#include "stdlib/math/base/special/round.h"
#include "stdlib/math/base/special/pow.h"
#include "stdlib/constants/float64/max_safe_integer.h"
#include "stdlib/constants/float64/max_base10_exponent.h"
#include "stdlib/constants/float64/min_base10_exponent.h"
#include "stdlib/constants/float64/min_base10_exponent_subnormal.h"
#include <stdint.h>
#include <math.h>

static const double MAX_INT = STDLIB_CONSTANT_FLOAT64_MAX_SAFE_INTEGER + 1.0;
static const double HUGE_VALUE = 1.0e+308;
Expand Down Expand Up @@ -115,7 +116,7 @@ double stdlib_base_roundn( const double x, const int32_t n ) {
double s;
double y;

if ( isnan( x ) ){
if ( stdlib_base_is_nan( x ) ){
return 0.0 / 0.0; // NaN
}

Expand All @@ -140,14 +141,14 @@ double stdlib_base_roundn( const double x, const int32_t n ) {
}
// 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...
if ( n < STDLIB_CONSTANT_FLOAT64_MIN_BASE10_EXPONENT ){
s = pow( 10.0, -( n + STDLIB_CONSTANT_FLOAT64_MAX_BASE10_EXPONENT ) ); // TODO: replace use of `pow` once have stdlib equivalent
s = stdlib_base_pow( 10.0, -( n + STDLIB_CONSTANT_FLOAT64_MAX_BASE10_EXPONENT ) );
y = ( x * HUGE_VALUE ) * s; // order of operation matters!
if ( stdlib_base_is_infinite( y ) ){
return x;
}
return ( stdlib_base_round( y ) / HUGE_VALUE ) / s;
}
s = pow( 10.0, -n ); // TODO: replace use of `pow` once have stdlib equivalent
s = stdlib_base_pow( 10.0, -n );
y = x * s;
if ( stdlib_base_is_infinite( y ) ){
return x;
Expand Down

0 comments on commit 255b21c

Please sign in to comment.