Skip to content

Commit 06ecf15

Browse files
committed
[ref/mli_math] fix issue in mli_math_asr_rnd_fx function ref version
1 parent ae8c6a7 commit 06ecf15

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/src/pal/ref/mli_math.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ template <typename T>
6868
MLI_FORCE_INLINE T mli_math_asr_rnd_fx(T x, int nbits)
6969
{
7070
T r = 0;
71+
T one = 1u;
7172

7273
if (nbits < 0)
7374
return mli_math_asl_fx<T>(x, (-nbits));
@@ -80,7 +81,7 @@ MLI_FORCE_INLINE T mli_math_asr_rnd_fx(T x, int nbits)
8081
// Rounding up:
8182
// if the most significant deleted bit is 1, add 1 to the remaining bits.
8283
#ifdef ROUND_UP
83-
T round = (T)((1u << nbits) >> 1);
84+
T round = (T)((one << nbits) >> 1);
8485
r = mli_math_add_fx<T>(x, round);
8586
r = mli_math_asr_fx<T>(r, nbits);
8687
#endif
@@ -91,7 +92,7 @@ MLI_FORCE_INLINE T mli_math_asr_rnd_fx(T x, int nbits)
9192
// or at least one other deleted bit is 1, add 1 to the remaining bits.
9293
#ifdef ROUND_CONVERGENT
9394
r = mli_math_asr_fx<T>(x, nbits);
94-
T last_deleted_mask = (T)((1 << nbits) >> 1);
95+
T last_deleted_mask = (T)((one << nbits) >> 1);
9596
if (((x & last_deleted_mask) != (T)0) &&
9697
(((r & (T)1) != (T)0) || ((x & (last_deleted_mask-(T)1))!= (T)0))) {
9798
return mli_math_add_fx<T>(r, 1);

0 commit comments

Comments
 (0)