]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
math: Fix exp10 undefined left shift
authorSzabolcs Nagy <szabolcs.nagy@arm.com>
Wed, 22 May 2024 15:33:43 +0000 (16:33 +0100)
committerSzabolcs Nagy <szabolcs.nagy@arm.com>
Tue, 4 Jun 2024 14:33:26 +0000 (15:33 +0100)
Left shift of ki is undefined when ki<0, copy the logic from exp,
which uses unsigned arithmetics, to fix it.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
sysdeps/ieee754/dbl-64/e_exp10.c

index 225fc74c4c5ed0ff196c795c0828180a7015a10d..7ea8270063aef7a6da7f65f243c6172c9c9ca96f 100644 (file)
@@ -38,7 +38,7 @@ special_case (uint64_t sbits, double_t tmp, uint64_t ki)
 {
   double_t scale, y;
 
-  if (ki - (1ull << 16) < 0x80000000)
+  if ((ki & 0x80000000) == 0)
     {
       /* The exponent of scale might have overflowed by 1.  */
       sbits -= 1ull << 52;
@@ -100,14 +100,14 @@ __exp10 (double x)
   /* Reduce x: z = x * N / log10(2), k = round(z).  */
   double_t z = __exp_data.invlog10_2N * x;
   double_t kd;
-  int64_t ki;
+  uint64_t ki;
 #if TOINT_INTRINSICS
   kd = roundtoint (z);
   ki = converttoint (z);
 #else
   kd = math_narrow_eval (z + Shift);
+  ki = asuint64 (kd);
   kd -= Shift;
-  ki = kd;
 #endif
 
   /* r = x - k * log10(2), r in [-0.5, 0.5].  */