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

refactor: use signed integers for math/base/special/log2, as per FreeBSD #2295

Merged
merged 1 commit into from
Jun 2, 2024
Merged
Changes from all commits
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
19 changes: 11 additions & 8 deletions lib/node_modules/@stdlib/math/base/special/log2/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ double stdlib_base_log2( const double x ) {
double valHi;
uint32_t hx;
uint32_t lx;
int32_t ihx;
double hfsq;
double hi;
int32_t i;
Expand All @@ -69,31 +70,33 @@ double stdlib_base_log2( const double x ) {
}
xc = x;
stdlib_base_float64_to_words( xc, &hx, &lx );
ihx = (int32_t)hx;
k = 0;
if ( hx < HIGH_MIN_NORMAL_EXP ) {
if ( ihx < HIGH_MIN_NORMAL_EXP ) {
// Case: x < 2**-1022
if ( ( ( hx & STDLIB_CONSTANT_FLOAT64_HIGH_WORD_ABS_MASK ) | lx ) == 0 ) {
if ( ( ( ihx & STDLIB_CONSTANT_FLOAT64_HIGH_WORD_ABS_MASK ) | lx ) == 0 ) {
return STDLIB_CONSTANT_FLOAT64_NINF;
}
k -= 54;

// Subnormal number, scale up x:
xc *= TWO54;
stdlib_base_float64_get_high_word( xc, &hx );
ihx = (int32_t)hx;
}
if ( hx >= HIGH_MAX_NORMAL_EXP ) {
if ( ihx >= HIGH_MAX_NORMAL_EXP ) {
return xc + xc;
}
// Case: log(1) = +0
if ( hx == HIGH_BIASED_EXP_0 && lx == 0 ) {
if ( ihx == HIGH_BIASED_EXP_0 && lx == 0 ) {
return 0;
}
k += ( ( hx>>20 ) - STDLIB_CONSTANT_FLOAT64_EXPONENT_BIAS );
hx &= STDLIB_CONSTANT_FLOAT64_HIGH_WORD_SIGNIFICAND_MASK;
i = ( hx+0x95f64 ) & HIGH_MIN_NORMAL_EXP;
k += ( ( ihx>>20 ) - STDLIB_CONSTANT_FLOAT64_EXPONENT_BIAS );
ihx &= STDLIB_CONSTANT_FLOAT64_HIGH_WORD_SIGNIFICAND_MASK;
i = ( ihx+0x95f64 ) & HIGH_MIN_NORMAL_EXP;

// Normalize x or x/2...
stdlib_base_float64_set_high_word( hx|( i^HIGH_BIASED_EXP_0 ), &xc );
stdlib_base_float64_set_high_word( (uint32_t)( ihx|( i^HIGH_BIASED_EXP_0 ) ), &xc );
k += (i>>20);
y = (double)k;
f = xc - 1.0;
Expand Down
Loading