@@ -49,20 +49,22 @@ static const int32_t HIGH_BIASED_EXP_0 = 0x3f800000;
4949*
5050*/
5151float stdlib_base_log2f ( const float x ) {
52- int32_t hx ;
52+ uint32_t hx ;
5353 int32_t ihx ;
5454 float hfsq ;
5555 float hi ;
5656 int32_t i ;
5757 int32_t k ;
5858 float lo ;
59+ float xc ;
5960 float f ;
6061 float R ;
6162 float y ;
6263
6364 if ( stdlib_base_is_nan ( x ) || x < 0.0 ) {
6465 return 0.0 / 0.0 ; // NaN
6566 }
67+ xc = x ;
6668 stdlib_base_float32_to_word ( x , & hx );
6769 ihx = (int32_t )hx ;
6870 k = 0 ;
@@ -74,8 +76,8 @@ float stdlib_base_log2f( const float x ) {
7476 k -= 25 ;
7577
7678 // Subnormal number, scale up x:
77- x *= TWO25 ;
78- stdlib_base_float32_to_word ( x , & hx );
79+ xc *= TWO25 ;
80+ stdlib_base_float32_to_word ( xc , & hx );
7981 ihx = (int32_t )hx ;
8082 }
8183 if ( ihx >= HIGH_MAX_NORMAL_EXP ) {
@@ -90,10 +92,10 @@ float stdlib_base_log2f( const float x ) {
9092 i = ( ihx + 0x4afb0d ) & HIGH_MIN_NORMAL_EXP ;
9193
9294 // Normalize x or x/2...
93- stdlib_base_float32_from_word ( (uint32_t )( ihx |( i ^HIGH_BIASED_EXP_0 ) ), & x );
95+ stdlib_base_float32_from_word ( (uint32_t )( ihx |( i ^HIGH_BIASED_EXP_0 ) ), & xc );
9496 k += (i >>23 );
9597 y = (float )k ;
96- f = x - 1.0f ;
98+ f = xc - 1.0f ;
9799 hfsq = 0.5f * f * f ;
98100 R = stdlib_base_kernel_log1p ( f );
99101
@@ -111,6 +113,7 @@ float stdlib_base_log2f( const float x ) {
111113
112114 hi = f - hfsq ;
113115 stdlib_base_float32_to_word ( hi , & hx );
116+ ihx = (int32_t )hx ;
114117 stdlib_base_float32_from_word ( hx & STDLIB_CONSTANT_FLOAT64_HIGH_WORD_ABS_MASK , & hi );
115118 lo = ( f - hi ) - hfsq + R ;
116119 return ( ( lo + hi ) * IVLN2LO ) + ( lo * IVLN2HI ) + ( hi * IVLN2HI ) + y ;
0 commit comments