lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 22 Dec 2021 13:50:57 -0500
From:   Liam Beguin <liambeguin@...il.com>
To:     Andy Shevchenko <andy.shevchenko@...il.com>
Cc:     Peter Rosin <peda@...ntia.se>, Jonathan Cameron <jic23@...nel.org>,
        Lars-Peter Clausen <lars@...afoo.de>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        linux-iio <linux-iio@...r.kernel.org>,
        devicetree <devicetree@...r.kernel.org>,
        Rob Herring <robh+dt@...nel.org>
Subject: Re: [PATCH v11 10/15] iio: afe: rescale: make use of units.h

On Wed, Dec 22, 2021 at 02:33:52PM +0200, Andy Shevchenko wrote:
> On Wed, Dec 22, 2021 at 5:47 AM Liam Beguin <liambeguin@...il.com> wrote:
> >
> > From: Liam Beguin <lvb@...hos.com>
> >
> > Make use of well-defined SI metric prefixes to improve code readability.
> 
> ...
> 
> >         case IIO_VAL_FRACTIONAL_LOG2:
> > -               tmp = (s64)*val * 1000000000LL;
> > +               tmp = (s64)*val * NANO;
> >                 tmp = div_s64(tmp, rescale->denominator);
> >                 tmp *= rescale->numerator;
> >
> > -               tmp = div_s64_rem(tmp, 1000000000LL, &rem);
> > +               tmp = div_s64_rem(tmp, NANO, &rem);
> >                 *val = tmp;
> 
> Thanks! The important part of this conversion is to get one trick,
> i.e. NANO and GIGA are both represented by 10^9. We need to be sure
> that here we use the proper sign of the power of these numbers. So
> please double check in all cases that the chosen SI prefixes are
> correct from the power sign point of view, e.g. it is 10^-9 and not
> 10^9 or otherwise.

I get the difference, but I guess I'm not sure I understand how you want me to
use them. I was using NANO here as that made most sense for me.

If we go by the positive vs. negative powers of ten, I should always use
GIGA as we're multiplying by 10^9 and dividing by 10^9. Is that what you
expected?

IMO, that wouldn't be as clear, but I believe you know better.

Cheers,
Liam

> ...
> 
> >                 *val2 = rem / (int)tmp;
> >                 if (rem2)
> > -                       *val2 += div_s64((s64)rem2 * 1000000000LL, tmp);
> > +                       *val2 += div_s64((s64)rem2 * NANO, tmp);
> 
> Ditto here and for the rest
> 
> -- 
> With Best Regards,
> Andy Shevchenko

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ