From 255b21c6498ff72139727d42fb2fe9c9893972b2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 9 Jul 2024 07:29:34 +0000 Subject: [PATCH] Auto-generated commit --- CHANGELOG.md | 3 ++- base/special/roundn/manifest.json | 18 ++++++++++++------ base/special/roundn/src/{roundn.c => main.c} | 9 +++++---- 3 files changed, 19 insertions(+), 11 deletions(-) rename base/special/roundn/src/{roundn.c => main.c} (95%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 061724232..c05d9c8eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@
-## Unreleased (2024-07-08) +## Unreleased (2024-07-09)
@@ -4922,6 +4922,7 @@ A total of 29 people contributed to this release. Thank you to the following con
+- [`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)_ diff --git a/base/special/roundn/manifest.json b/base/special/roundn/manifest.json index eb9529f7f..68abf0beb 100644 --- a/base/special/roundn/manifest.json +++ b/base/special/roundn/manifest.json @@ -28,7 +28,7 @@ { "task": "build", "src": [ - "./src/roundn.c" + "./src/main.c" ], "include": [ "./include" @@ -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" @@ -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" @@ -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" ] } ] diff --git a/base/special/roundn/src/roundn.c b/base/special/roundn/src/main.c similarity index 95% rename from base/special/roundn/src/roundn.c rename to base/special/roundn/src/main.c index f391f3458..7b1bab64c 100644 --- a/base/special/roundn/src/roundn.c +++ b/base/special/roundn/src/main.c @@ -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 -#include static const double MAX_INT = STDLIB_CONSTANT_FLOAT64_MAX_SAFE_INTEGER + 1.0; static const double HUGE_VALUE = 1.0e+308; @@ -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 } @@ -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;