[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20251028092723.3403d122@pumpkin>
Date: Tue, 28 Oct 2025 09:27:23 +0000
From: David Laight <david.laight.linux@...il.com>
To: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Cc: linux-iio@...r.kernel.org, chrome-platform@...ts.linux.dev,
linux-kernel@...r.kernel.org, linux-media@...r.kernel.org, Jonathan Cameron
<jic23@...nel.org>, David Lechner <dlechner@...libre.com>, Nuno
Sá <nuno.sa@...log.com>, Andy Shevchenko <andy@...nel.org>,
Benson Leung <bleung@...omium.org>, Guenter Roeck <groeck@...omium.org>,
Lars-Peter Clausen <lars@...afoo.de>, Michael Hennerich
<Michael.Hennerich@...log.com>, Mauro Carvalho Chehab <mchehab@...nel.org>,
"Daniel W. S. Almeida" <dwlsalmeida@...il.com>
Subject: Re: [PATCH v1 2/6] units: Add value of π *
10⁹
On Tue, 28 Oct 2025 10:08:04 +0200
Andy Shevchenko <andriy.shevchenko@...ux.intel.com> wrote:
> On Mon, Oct 27, 2025 at 07:30:33PM +0000, David Laight wrote:
> > On Mon, 27 Oct 2025 15:34:51 +0100
> > Andy Shevchenko <andriy.shevchenko@...ux.intel.com> wrote:
> >
> > > There are a few drivers that want to have this value, and at least one
> > > known to come soon. Let's define a value for them.
>
> > > +/* Value of π * 10⁹ */
Thinks - should non-ascii characters be allowed in comments.
They can cause grief.
> > > +#define PI 3141592653LL
> >
> > Is that the right value?
> > IIRC the next digits are 58979 (I used to know the next few as well)
> > which means it should be rounded up.
>
> Right, today I have the same thought that actually ChromeOS driver has a
> off-by-one issue there.
Not as though it is likely to make a difference.
If any code needs anything more accurate than 3.1416 it probably cares
whether the value is rounded down or up.
> Btw, do you know if we can have compile-time divisions that can make 32-bit
> constants out of the 64-bit input? DIV_ROUND_CLOSEST_ULL() doesn't seem allow
> that.
Not sure, I did wonder how much thought had gone into the LL suffix.
The value used will fit in u32 - but then any maths becomes unsigned.
OTOH using LL forces 64bit maths on 32bit - not good.
I suspect it would be better to drop a digit so the value fits in a
signed 32bit variable.
The other issue is whether scaling by a power of 10 is even right.
If the code has to rescale the value using divides you really want
to divide by a big power of 2 not 10.
So multiplying by 2**29 may be more useful.
David
Powered by blists - more mailing lists