Skip to content

Commit 8dceccc

Browse files
gunjjoshikgryte
andauthored
refactor: use signed integers for math/base/special/log10
PR-URL: #2294 Ref: #2215 (comment) Co-authored-by: Athan Reines <[email protected]> Reviewed-by: Athan Reines <[email protected]> Signed-off-by: GUNJ JOSHI <[email protected]> Signed-off-by: Athan Reines <[email protected]>
1 parent 34ef42e commit 8dceccc

File tree

1 file changed

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

1 file changed

+11
-8
lines changed

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

+11-8
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ double stdlib_base_log10( const double x ) {
7373
double valHi;
7474
uint32_t hx;
7575
uint32_t lx;
76+
int32_t ihx;
7677
double hfsq;
7778
double hi;
7879
int32_t i;
@@ -90,31 +91,33 @@ double stdlib_base_log10( const double x ) {
9091
}
9192
xc = x;
9293
stdlib_base_float64_to_words( xc, &hx, &lx );
94+
ihx = (int32_t)hx;
9395
k = 0;
94-
if ( hx < HIGH_MIN_NORMAL_EXP ) {
96+
if ( ihx < HIGH_MIN_NORMAL_EXP ) {
9597
// Case: x < 2**-1022
96-
if ( ( ( hx & STDLIB_CONSTANT_FLOAT64_HIGH_WORD_ABS_MASK ) | lx ) == 0 ) {
98+
if ( ( ( ihx & STDLIB_CONSTANT_FLOAT64_HIGH_WORD_ABS_MASK ) | lx ) == 0 ) {
9799
return STDLIB_CONSTANT_FLOAT64_NINF;
98100
}
99101
k -= 54;
100102

101103
// Subnormal number, scale up x:
102104
xc *= TWO54;
103105
stdlib_base_float64_get_high_word( xc, &hx );
106+
ihx = (int32_t)hx;
104107
}
105-
if ( hx >= HIGH_MAX_NORMAL_EXP ) {
108+
if ( ihx >= HIGH_MAX_NORMAL_EXP ) {
106109
return xc + xc;
107110
}
108111
// Case: log(1) = +0
109-
if ( hx == HIGH_BIASED_EXP_0 && lx == 0 ) {
112+
if ( ihx == HIGH_BIASED_EXP_0 && lx == 0 ) {
110113
return 0;
111114
}
112-
k += ( ( hx >> 20 ) - STDLIB_CONSTANT_FLOAT64_EXPONENT_BIAS );
113-
hx &= STDLIB_CONSTANT_FLOAT64_HIGH_WORD_SIGNIFICAND_MASK;
114-
i = ( hx + 0x95f64 ) & HIGH_MIN_NORMAL_EXP;
115+
k += ( ( ihx >> 20 ) - STDLIB_CONSTANT_FLOAT64_EXPONENT_BIAS );
116+
ihx &= STDLIB_CONSTANT_FLOAT64_HIGH_WORD_SIGNIFICAND_MASK;
117+
i = ( ihx + 0x95f64 ) & HIGH_MIN_NORMAL_EXP;
115118

116119
// Normalize x or x/2...
117-
stdlib_base_float64_set_high_word( hx | ( i ^ HIGH_BIASED_EXP_0 ), &xc );
120+
stdlib_base_float64_set_high_word( (uint32_t)( ihx | ( i ^ HIGH_BIASED_EXP_0 ) ), &xc );
118121
k += ( i >> 20 );
119122
y = (double)k;
120123
f = xc - 1.0;

0 commit comments

Comments
 (0)