Skip to content

Commit

Permalink
refactor: reduce code complexity
Browse files Browse the repository at this point in the history
PR-URL: #2632
Co-authored-by: Athan Reines <kgryte@gmail.com>
Reviewed-by: Athan Reines <kgryte@gmail.com> 
Signed-off-by: Athan Reines <kgryte@gmail.com>
  • Loading branch information
gunjjoshi and kgryte authored Jul 20, 2024
1 parent 4345839 commit b063947
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ function floorsd( x, n, b ) {
isnan( x ) ||
isnan( n ) ||
n < 1 ||
isInfinite( n )
) {
return NaN;
}
if (
isInfinite( n ) ||
isnan( b ) ||
b <= 0 ||
isInfinite( b )
Expand Down
10 changes: 4 additions & 6 deletions lib/node_modules/@stdlib/math/base/special/floorsd/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,25 @@
* // returns 0.03125
*/
double stdlib_base_floorsd( const double x, const int32_t n, const int32_t b ) {
int32_t base;
double exp;
double s;
double y;

if ( stdlib_base_is_nan( x ) || n < 1 || b <= 0 ) {
return 0.0 / 0.0; // NaN
}
base = b;
if ( stdlib_base_is_infinite( x ) || x == 0.0 ) {
return x;
}
if ( base == 10 ) {
if ( b == 10 ) {
exp = stdlib_base_log10( stdlib_base_abs( x ) );
} else if ( base == 2 ) {
} else if ( b == 2 ) {
exp = stdlib_base_float64_exponent( stdlib_base_abs( x ) );
} else {
exp = stdlib_base_ln( stdlib_base_abs( x ) ) / stdlib_base_ln( base );
exp = stdlib_base_ln( stdlib_base_abs( x ) ) / stdlib_base_ln( (double)b );
}
exp = stdlib_base_floor( exp - n + 1.0 );
s = stdlib_base_pow( base, stdlib_base_abs( exp ) );
s = stdlib_base_pow( (double)b, stdlib_base_abs( exp ) );

// Check for overflow:
if ( stdlib_base_is_infinite( s ) ) {
Expand Down

1 comment on commit b063947

@stdlib-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage Report

Package Statements Branches Functions Lines
math/base/special/floorsd $\color{green}218/218$
$\color{green}+100.00\%$
$\color{green}27/27$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}218/218$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this push.

Please sign in to comment.