Skip to content

Commit befe3c6

Browse files
committed
math: Use same logic in exp10 as exp for ki
Signed arithmetic is error prone and it is easier to maintain code if exp10 and exp are consistent.
1 parent 88ffd2e commit befe3c6

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

math/exp10.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ special_case (uint64_t sbits, double_t tmp, uint64_t ki)
2222
{
2323
double_t scale, y;
2424

25-
if (ki - (1ull << 16) < 0x80000000)
25+
if ((ki & 0x80000000) == 0)
2626
{
2727
/* The exponent of scale might have overflowed by 1. */
2828
sbits -= 1ull << 52;
@@ -84,14 +84,14 @@ exp10 (double x)
8484
/* Reduce x: z = x * N / log10(2), k = round(z). */
8585
double_t z = __exp_data.invlog10_2N * x;
8686
double_t kd;
87-
int64_t ki;
87+
uint64_t ki;
8888
#if TOINT_INTRINSICS
8989
kd = roundtoint (z);
9090
ki = converttoint (z);
9191
#else
9292
kd = eval_as_double (z + Shift);
93+
ki = asuint64 (kd);
9394
kd -= Shift;
94-
ki = kd;
9595
#endif
9696

9797
/* r = x - k * log10(2), r in [-0.5, 0.5]. */
@@ -103,7 +103,7 @@ exp10 (double x)
103103
Approximate the two components separately. */
104104

105105
/* s = 2^(k/N), using lookup table. */
106-
uint64_t e = (uint64_t)ki << (52 - EXP_TABLE_BITS);
106+
uint64_t e = ki << (52 - EXP_TABLE_BITS);
107107
uint64_t i = (ki & IndexMask) * 2;
108108
uint64_t u = __exp_data.tab[i + 1];
109109
uint64_t sbits = u + e;

0 commit comments

Comments
 (0)