Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add native addon to ceiln and cceiln #988

Merged
merged 20 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/ceiln/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@
"dependencies": [
"@stdlib/math/base/napi/binary",
"@stdlib/math/base/special/abs",
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/assert/is-infinite",
"@stdlib/constants/float64/max-base10-exponent",
"@stdlib/constants/float64/min-base10-exponent",
"@stdlib/constants/float64/min-base10-exponent-subnormal",
"@stdlib/constants/float64/max-safe-integer",
"@stdlib/constants/float64/max"
]
},
Expand All @@ -59,8 +63,12 @@
"libpath": [],
"dependencies": [
"@stdlib/math/base/special/abs",
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/assert/is-infinite",
"@stdlib/constants/float64/max-base10-exponent",
"@stdlib/constants/float64/min-base10-exponent",
"@stdlib/constants/float64/min-base10-exponent-subnormal",
"@stdlib/constants/float64/max-safe-integer",
"@stdlib/constants/float64/max"
]
},
Expand All @@ -78,8 +86,12 @@
"libpath": [],
"dependencies": [
"@stdlib/math/base/special/abs",
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/assert/is-infinite",
"@stdlib/constants/float64/max-base10-exponent",
"@stdlib/constants/float64/min-base10-exponent",
"@stdlib/constants/float64/min-base10-exponent-subnormal",
"@stdlib/constants/float64/max-safe-integer",
"@stdlib/constants/float64/max"
]
}
Expand Down
18 changes: 11 additions & 7 deletions lib/node_modules/@stdlib/math/base/special/ceiln/src/ceiln.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@

#include "stdlib/math/base/special/ceiln.h"
#include "stdlib/math/base/special/abs.h"
#include "stdlib/math/base/assert/is_nan.h"
#include "stdlib/math/base/assert/is_infinite.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 "stdlib/constants/float64/max_safe_integer.h"
#include "stdlib/constants/float64/max.h"
kgryte marked this conversation as resolved.
Show resolved Hide resolved
#include <stdint.h>
#include <math.h>
Expand Down Expand Up @@ -50,22 +54,22 @@ double stdlib_base_ceiln( const double x, const int32_t n ) {
double s;
steff456 marked this conversation as resolved.
Show resolved Hide resolved
double y;

if ( isnan( x ) ){
if ( stdlib_base_is_nan( x ) ){
return x;
}

if (
// Handle infinities...
isinf( x ) ||
stdlib_base_is_infinite( x ) ||

// Handle +-0...
x == 0.0 ||

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

// If `|x|` is large enough, no decimals to round...
( stdlib_base_abs( x ) > STDLIB_CONSTANT_FLOAT64_MAX && n <= 0 )
( stdlib_base_abs( x ) > STDLIB_CONSTANT_FLOAT64_MAX_SAFE_INTEGER + 1 && n <= 0 )
) {
return x;
}
Expand All @@ -79,17 +83,17 @@ double stdlib_base_ceiln( const double x, const int32_t n ) {
}
steff456 marked this conversation as resolved.
Show resolved Hide resolved

// 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_MAX_BASE10_EXPONENT ) {
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
y = ( x * HUGE ) * s; // order of operation matters!
if ( isinf( y ) ) {
if ( stdlib_base_is_infinite( y ) ) {
return x;
}
return ( ceil( y ) / HUGE ) / s;
steff456 marked this conversation as resolved.
Show resolved Hide resolved
steff456 marked this conversation as resolved.
Show resolved Hide resolved
}
s = pow( 10.0, -n ); // TODO: replace use of `pow` once have stdlib equivalent
y = x * s;
if ( isinf( y ) ) {
if ( stdlib_base_is_infinite( y ) ) {
return x;
}
return ceil( y ) / s;
steff456 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down