This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 3/3] Add ffsl(), ffsll(), fls(), flsl(), flsll()


On 04/07/17 15:34, Sebastian Huber wrote:

+int
+fls(int i)
+{
+
+	return (sizeof(i) * CHAR_BIT - __builtin_clz(i));
+}

I just realized that the result of __builtin_clz(i) is undefined if i == 0. However, fls(0) should return 0. So this must be changed to:

int
fls(int i)
{

    if (i == 0)
        return (0);

    return (sizeof(i) * CHAR_BIT - __builtin_clz(i));
}

Similar for flsl() and flsll().

--
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.huber@embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]