Messages in this thread | | | From | Andrea Merello <> | Date | Mon, 8 Nov 2021 12:05:33 +0100 | Subject | Re: [v2 01/10] utils_macro: introduce find_closest_unsorted() |
| |
Il giorno gio 28 ott 2021 alle ore 12:26 Andy Shevchenko <andy.shevchenko@gmail.com> ha scritto: > > On Thu, Oct 28, 2021 at 1:18 PM Andrea Merello <andrea.merello@gmail.com> wrote: > > > > This is similar to find_closest() and find_closest_descending(), but, it > > doesn't make any assumption about the array being ordered. > > Macros in general are not so welcoming. > Why do you do it as a macro?
Honestly, I did that just because find_closest() and find_closest_descending() are macros (i.e. to be consistent wrt them). I see no drawbacks in making this a regular function indeed; just, do you have any advice about where should it live?
> ... > > > +#include <linux/math.h> > > Wondering if the current header misses other inclusions it's a direct user of.
Looking at it, it seems that also __find_closest() actually needs math.h because it (apparently incorrectly[*]) uses DIV_ROUND_CLOSEST()..
[*]Indeed it seems there is another issue here about find_closest(): for example it picks the 1st element while searching for "2" in an array like this: {1,2,..} ..This needs to be reported/fixed..
> ... > > > +/** > > + * find_closest_unsorted - locate the closest element in a unsorted array > > an > > > + * @x: The reference value. > > + * @a: The array in which to look for the closest element. > > + * @as: Size of 'a'. > > + * > > + * Similar to find_closest() but 'a' has no requirement to being sorted > > + */ > > -- > With Best Regards, > Andy Shevchenko
| |