Skip to content

Commit 74a55fa

Browse files
gunjjoshiaman-095
authored andcommitted
refactor: use signed integers for math/base/special/log2
PR-URL: stdlib-js#2295 Ref: stdlib-js#2294 (review) Reviewed-by: Athan Reines <[email protected]>
1 parent 8b10fb4 commit 74a55fa

File tree

1 file changed

+11
-8
lines changed
  • lib/node_modules/@stdlib/math/base/special/log2/src

1 file changed

+11
-8
lines changed

lib/node_modules/@stdlib/math/base/special/log2/src/main.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ double stdlib_base_log2( const double x ) {
5353
double valHi;
5454
uint32_t hx;
5555
uint32_t lx;
56+
int32_t ihx;
5657
double hfsq;
5758
double hi;
5859
int32_t i;
@@ -69,31 +70,33 @@ double stdlib_base_log2( const double x ) {
6970
}
7071
xc = x;
7172
stdlib_base_float64_to_words( xc, &hx, &lx );
73+
ihx = (int32_t)hx;
7274
k = 0;
73-
if ( hx < HIGH_MIN_NORMAL_EXP ) {
75+
if ( ihx < HIGH_MIN_NORMAL_EXP ) {
7476
// Case: x < 2**-1022
75-
if ( ( ( hx & STDLIB_CONSTANT_FLOAT64_HIGH_WORD_ABS_MASK ) | lx ) == 0 ) {
77+
if ( ( ( ihx & STDLIB_CONSTANT_FLOAT64_HIGH_WORD_ABS_MASK ) | lx ) == 0 ) {
7678
return STDLIB_CONSTANT_FLOAT64_NINF;
7779
}
7880
k -= 54;
7981

8082
// Subnormal number, scale up x:
8183
xc *= TWO54;
8284
stdlib_base_float64_get_high_word( xc, &hx );
85+
ihx = (int32_t)hx;
8386
}
84-
if ( hx >= HIGH_MAX_NORMAL_EXP ) {
87+
if ( ihx >= HIGH_MAX_NORMAL_EXP ) {
8588
return xc + xc;
8689
}
8790
// Case: log(1) = +0
88-
if ( hx == HIGH_BIASED_EXP_0 && lx == 0 ) {
91+
if ( ihx == HIGH_BIASED_EXP_0 && lx == 0 ) {
8992
return 0;
9093
}
91-
k += ( ( hx>>20 ) - STDLIB_CONSTANT_FLOAT64_EXPONENT_BIAS );
92-
hx &= STDLIB_CONSTANT_FLOAT64_HIGH_WORD_SIGNIFICAND_MASK;
93-
i = ( hx+0x95f64 ) & HIGH_MIN_NORMAL_EXP;
94+
k += ( ( ihx>>20 ) - STDLIB_CONSTANT_FLOAT64_EXPONENT_BIAS );
95+
ihx &= STDLIB_CONSTANT_FLOAT64_HIGH_WORD_SIGNIFICAND_MASK;
96+
i = ( ihx+0x95f64 ) & HIGH_MIN_NORMAL_EXP;
9497

9598
// Normalize x or x/2...
96-
stdlib_base_float64_set_high_word( hx|( i^HIGH_BIASED_EXP_0 ), &xc );
99+
stdlib_base_float64_set_high_word( (uint32_t)( ihx|( i^HIGH_BIASED_EXP_0 ) ), &xc );
97100
k += (i>>20);
98101
y = (double)k;
99102
f = xc - 1.0;

0 commit comments

Comments
 (0)