linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/6] iio: Introduce and use value of π
@ 2025-11-07 20:02 Andy Shevchenko
  2025-11-07 20:02 ` [PATCH v2 1/6] media: vidtv: Rename PI definition to PI_SAMPLES Andy Shevchenko
                   ` (5 more replies)
  0 siblings, 6 replies; 11+ messages in thread
From: Andy Shevchenko @ 2025-11-07 20:02 UTC (permalink / raw)
  To: Andy Shevchenko, Hans Verkuil, linux-iio, chrome-platform,
	linux-kernel, linux-media
  Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Benson Leung, Guenter Roeck, Lars-Peter Clausen,
	Michael Hennerich, Mauro Carvalho Chehab, Daniel W. S. Almeida

There are a few drivers that use value of π (small Greek PI)
of different precision. Instead of hard coding over and over
convert them to use a defined constant, which one of the patches
in this series introduces. No functional changes involved.

Note, the respective IIO macros are not converted yet by this series.

All of the converted files were checked in disassembled format before
and after the change to see that the value:
a) pre-calculated at compile-time;
b) is the same that is expected.

I didn't put the power-of-10 into the definition names as now they are
the maximum that fits the respective signed type.

Series is supposed to go via IIO tree.

Changelog v2:
- redone to avoid unneeded calculations
- collected tags (Hans)

v1: <20251027143850.2070427-1-andriy.shevchenko@linux.intel.com>

Andy Shevchenko (6):
  media: vidtv: Rename PI definition to PI_SAMPLES
  units: Add 32- and 64-bit signed values of π
  media: dvb-frontends: atbm8830: Convert to use PI definition
  iio: cros_ec_sensors: Convert to use PI definition
  iio: frequency: ad9523: Convert to use PI definition
  iio: position: iqs624-pos: Convert to use PI definition

 drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c | 3 ++-
 drivers/iio/frequency/ad9523.c                       | 5 +++--
 drivers/iio/position/iqs624-pos.c                    | 3 ++-
 drivers/media/dvb-frontends/atbm8830.c               | 5 +++--
 drivers/media/test-drivers/vidtv/vidtv_s302m.c       | 6 +++---
 include/linux/units.h                                | 6 ++++++
 6 files changed, 19 insertions(+), 9 deletions(-)

-- 
2.50.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v2 1/6] media: vidtv: Rename PI definition to PI_SAMPLES
  2025-11-07 20:02 [PATCH v2 0/6] iio: Introduce and use value of π Andy Shevchenko
@ 2025-11-07 20:02 ` Andy Shevchenko
  2025-11-07 20:03 ` [PATCH v2 2/6] units: Add 32- and 64-bit signed values of π Andy Shevchenko
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 11+ messages in thread
From: Andy Shevchenko @ 2025-11-07 20:02 UTC (permalink / raw)
  To: Andy Shevchenko, Hans Verkuil, linux-iio, chrome-platform,
	linux-kernel, linux-media
  Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Benson Leung, Guenter Roeck, Lars-Peter Clausen,
	Michael Hennerich, Mauro Carvalho Chehab, Daniel W. S. Almeida

The definition of PI in the driver is not the actual value in radians,
but rather degrees. Since we are going to have a value in radians
defined in a global header, rename this definition to avoid potential
collisions. No functional changes.

Acked-by: Hans Verkuil <hverkuil+cisco@kernel.org>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/media/test-drivers/vidtv/vidtv_s302m.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/media/test-drivers/vidtv/vidtv_s302m.c b/drivers/media/test-drivers/vidtv/vidtv_s302m.c
index 9da18eac04b5..b3217d643b1e 100644
--- a/drivers/media/test-drivers/vidtv/vidtv_s302m.c
+++ b/drivers/media/test-drivers/vidtv/vidtv_s302m.c
@@ -45,7 +45,7 @@
 #define FF_S302M_DEFAULT_PTS_OFFSET 100000
 
 /* Used by the tone generator: number of samples for PI */
-#define PI		180
+#define PI_SAMPLES		180
 
 static const u8 reverse[256] = {
 	/* from ffmpeg */
@@ -259,10 +259,10 @@ static u16 vidtv_s302m_get_sample(struct vidtv_encoder *e)
 		if (!ctx->last_tone)
 			return 0x8000;
 
-		pos = (2 * PI * ctx->note_offset * ctx->last_tone) / S302M_SAMPLING_RATE_HZ;
+		pos = (2 * PI_SAMPLES * ctx->note_offset * ctx->last_tone) / S302M_SAMPLING_RATE_HZ;
 		ctx->note_offset++;
 
-		return (fixp_sin32(pos % (2 * PI)) >> 16) + 0x8000;
+		return (fixp_sin32(pos % (2 * PI_SAMPLES)) >> 16) + 0x8000;
 	}
 
 	/* bug somewhere */
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 2/6] units: Add 32- and 64-bit signed values of π
  2025-11-07 20:02 [PATCH v2 0/6] iio: Introduce and use value of π Andy Shevchenko
  2025-11-07 20:02 ` [PATCH v2 1/6] media: vidtv: Rename PI definition to PI_SAMPLES Andy Shevchenko
@ 2025-11-07 20:03 ` Andy Shevchenko
  2025-11-07 21:09   ` David Lechner
  2025-11-07 20:03 ` [PATCH v2 3/6] media: dvb-frontends: atbm8830: Convert to use PI definition Andy Shevchenko
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 11+ messages in thread
From: Andy Shevchenko @ 2025-11-07 20:03 UTC (permalink / raw)
  To: Andy Shevchenko, Hans Verkuil, linux-iio, chrome-platform,
	linux-kernel, linux-media
  Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Benson Leung, Guenter Roeck, Lars-Peter Clausen,
	Michael Hennerich, Mauro Carvalho Chehab, Daniel W. S. Almeida

There are a few drivers that want to have these values, and
one more known to come soon. Let's define the values for them.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 include/linux/units.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/include/linux/units.h b/include/linux/units.h
index f626e212d4ca..5b3293bce04c 100644
--- a/include/linux/units.h
+++ b/include/linux/units.h
@@ -21,6 +21,12 @@
 #define PICO	1000000000000ULL
 #define FEMTO	1000000000000000ULL
 
+/* Value of π * 10⁸ (fits s32 or signed int) */
+#define PI	314159265
+
+/* Value of π * 10¹⁸ (fits s64 or signed long long) */
+#define PI_LL	3141592653589793238LL
+
 /* Hz based multipliers */
 #define NANOHZ_PER_HZ		1000000000UL
 #define MICROHZ_PER_HZ		1000000UL
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 3/6] media: dvb-frontends: atbm8830: Convert to use PI definition
  2025-11-07 20:02 [PATCH v2 0/6] iio: Introduce and use value of π Andy Shevchenko
  2025-11-07 20:02 ` [PATCH v2 1/6] media: vidtv: Rename PI definition to PI_SAMPLES Andy Shevchenko
  2025-11-07 20:03 ` [PATCH v2 2/6] units: Add 32- and 64-bit signed values of π Andy Shevchenko
@ 2025-11-07 20:03 ` Andy Shevchenko
  2025-11-07 20:03 ` [PATCH v2 4/6] iio: cros_ec_sensors: " Andy Shevchenko
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 11+ messages in thread
From: Andy Shevchenko @ 2025-11-07 20:03 UTC (permalink / raw)
  To: Andy Shevchenko, Hans Verkuil, linux-iio, chrome-platform,
	linux-kernel, linux-media
  Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Benson Leung, Guenter Roeck, Lars-Peter Clausen,
	Michael Hennerich, Mauro Carvalho Chehab, Daniel W. S. Almeida

Convert to use PI definition instead of open coded value of it.

Acked-by: Hans Verkuil <hverkuil+cisco@kernel.org>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/media/dvb-frontends/atbm8830.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/media/dvb-frontends/atbm8830.c b/drivers/media/dvb-frontends/atbm8830.c
index 778c865085bf..93181e0eb34f 100644
--- a/drivers/media/dvb-frontends/atbm8830.c
+++ b/drivers/media/dvb-frontends/atbm8830.c
@@ -6,7 +6,8 @@
  *    Copyright (C) 2009 David T.L. Wong <davidtlwong@gmail.com>
  */
 
-#include <asm/div64.h>
+#include <linux/math64.h>
+#include <linux/units.h>
 #include <media/dvb_frontend.h>
 
 #include "atbm8830.h"
@@ -112,7 +113,7 @@ static int set_if_freq(struct atbm_state *priv, u32 freq /*in kHz*/)
 
 	if (freq != 0) {
 		/* 2 * PI * (freq - fs) / fs * (2 ^ 22) */
-		t = (u64) 2 * 31416 * (freq - fs);
+		t = (u64) 2 * DIV_ROUND_UP(PI, 10000) * (freq - fs);
 		t <<= 22;
 		do_div(t, fs);
 		do_div(t, 1000);
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 4/6] iio: cros_ec_sensors: Convert to use PI definition
  2025-11-07 20:02 [PATCH v2 0/6] iio: Introduce and use value of π Andy Shevchenko
                   ` (2 preceding siblings ...)
  2025-11-07 20:03 ` [PATCH v2 3/6] media: dvb-frontends: atbm8830: Convert to use PI definition Andy Shevchenko
@ 2025-11-07 20:03 ` Andy Shevchenko
  2025-11-07 20:03 ` [PATCH v2 5/6] iio: frequency: ad9523: " Andy Shevchenko
  2025-11-07 20:03 ` [PATCH v2 6/6] iio: position: iqs624-pos: " Andy Shevchenko
  5 siblings, 0 replies; 11+ messages in thread
From: Andy Shevchenko @ 2025-11-07 20:03 UTC (permalink / raw)
  To: Andy Shevchenko, Hans Verkuil, linux-iio, chrome-platform,
	linux-kernel, linux-media
  Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Benson Leung, Guenter Roeck, Lars-Peter Clausen,
	Michael Hennerich, Mauro Carvalho Chehab, Daniel W. S. Almeida

Convert to use PI definition instead of open coded value of it.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
index 82cef4a12442..e248ba1eb3f9 100644
--- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
+++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
@@ -21,6 +21,7 @@
 #include <linux/platform_data/cros_ec_commands.h>
 #include <linux/platform_data/cros_ec_proto.h>
 #include <linux/platform_device.h>
+#include <linux/units.h>
 #include <linux/slab.h>
 
 #define CROS_EC_SENSORS_MAX_CHANNELS 4
@@ -120,7 +121,7 @@ static int cros_ec_sensors_read(struct iio_dev *indio_dev,
 			 * loss. Round to the nearest integer.
 			 */
 			*val = 0;
-			*val2 = div_s64(val64 * 3141592653ULL,
+			*val2 = div_s64(val64 * DIV_ROUND_UP_ULL(PI_LL, GIGA),
 					180 << (CROS_EC_SENSOR_BITS - 1));
 			ret = IIO_VAL_INT_PLUS_NANO;
 			break;
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 5/6] iio: frequency: ad9523: Convert to use PI definition
  2025-11-07 20:02 [PATCH v2 0/6] iio: Introduce and use value of π Andy Shevchenko
                   ` (3 preceding siblings ...)
  2025-11-07 20:03 ` [PATCH v2 4/6] iio: cros_ec_sensors: " Andy Shevchenko
@ 2025-11-07 20:03 ` Andy Shevchenko
  2025-11-07 20:03 ` [PATCH v2 6/6] iio: position: iqs624-pos: " Andy Shevchenko
  5 siblings, 0 replies; 11+ messages in thread
From: Andy Shevchenko @ 2025-11-07 20:03 UTC (permalink / raw)
  To: Andy Shevchenko, Hans Verkuil, linux-iio, chrome-platform,
	linux-kernel, linux-media
  Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Benson Leung, Guenter Roeck, Lars-Peter Clausen,
	Michael Hennerich, Mauro Carvalho Chehab, Daniel W. S. Almeida

Convert to use PI definition instead of open coded value of it.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/iio/frequency/ad9523.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/frequency/ad9523.c b/drivers/iio/frequency/ad9523.c
index 63c485e9e44c..781e0ada75d9 100644
--- a/drivers/iio/frequency/ad9523.c
+++ b/drivers/iio/frequency/ad9523.c
@@ -15,6 +15,7 @@
 #include <linux/err.h>
 #include <linux/module.h>
 #include <linux/delay.h>
+#include <linux/units.h>
 
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
@@ -652,7 +653,7 @@ static int ad9523_read_raw(struct iio_dev *indio_dev,
 			AD9523_CLK_DIST_DIV_REV(ret);
 		return IIO_VAL_INT;
 	case IIO_CHAN_INFO_PHASE:
-		code = (AD9523_CLK_DIST_DIV_PHASE_REV(ret) * 3141592) /
+		code = (AD9523_CLK_DIST_DIV_PHASE_REV(ret) * DIV_ROUND_UP(PI, 100)) /
 			AD9523_CLK_DIST_DIV_REV(ret);
 		*val = code / 1000000;
 		*val2 = code % 1000000;
@@ -701,7 +702,7 @@ static int ad9523_write_raw(struct iio_dev *indio_dev,
 		break;
 	case IIO_CHAN_INFO_PHASE:
 		code = val * 1000000 + val2 % 1000000;
-		tmp = (code * AD9523_CLK_DIST_DIV_REV(ret)) / 3141592;
+		tmp = (code * AD9523_CLK_DIST_DIV_REV(reg)) / DIV_ROUND_UP(PI, 100);
 		tmp = clamp(tmp, 0, 63);
 		reg &= ~AD9523_CLK_DIST_DIV_PHASE(~0);
 		reg |= AD9523_CLK_DIST_DIV_PHASE(tmp);
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 6/6] iio: position: iqs624-pos: Convert to use PI definition
  2025-11-07 20:02 [PATCH v2 0/6] iio: Introduce and use value of π Andy Shevchenko
                   ` (4 preceding siblings ...)
  2025-11-07 20:03 ` [PATCH v2 5/6] iio: frequency: ad9523: " Andy Shevchenko
@ 2025-11-07 20:03 ` Andy Shevchenko
  5 siblings, 0 replies; 11+ messages in thread
From: Andy Shevchenko @ 2025-11-07 20:03 UTC (permalink / raw)
  To: Andy Shevchenko, Hans Verkuil, linux-iio, chrome-platform,
	linux-kernel, linux-media
  Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
	Benson Leung, Guenter Roeck, Lars-Peter Clausen,
	Michael Hennerich, Mauro Carvalho Chehab, Daniel W. S. Almeida

Convert to use PI definition instead of open coded value of it.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/iio/position/iqs624-pos.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/position/iqs624-pos.c b/drivers/iio/position/iqs624-pos.c
index 8239239c6ee2..24d7a2591858 100644
--- a/drivers/iio/position/iqs624-pos.c
+++ b/drivers/iio/position/iqs624-pos.c
@@ -15,10 +15,11 @@
 #include <linux/notifier.h>
 #include <linux/platform_device.h>
 #include <linux/regmap.h>
+#include <linux/units.h>
 
 #define IQS624_POS_DEG_OUT			0x16
 
-#define IQS624_POS_SCALE1			(314159 / 180)
+#define IQS624_POS_SCALE1			(PI / 180000)
 #define IQS624_POS_SCALE2			100000
 
 struct iqs624_pos_private {
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 2/6] units: Add 32- and 64-bit signed values of π
  2025-11-07 20:03 ` [PATCH v2 2/6] units: Add 32- and 64-bit signed values of π Andy Shevchenko
@ 2025-11-07 21:09   ` David Lechner
  2025-11-07 21:14     ` David Lechner
       [not found]     ` <CAHp75VexvdYyjt1GkbfqOotkFpLeb=io6outJ5dpRqBv2qPNng@mail.gmail.com>
  0 siblings, 2 replies; 11+ messages in thread
From: David Lechner @ 2025-11-07 21:09 UTC (permalink / raw)
  To: Andy Shevchenko, Hans Verkuil, linux-iio, chrome-platform,
	linux-kernel, linux-media
  Cc: Jonathan Cameron, Nuno Sá, Andy Shevchenko, Benson Leung,
	Guenter Roeck, Lars-Peter Clausen, Michael Hennerich,
	Mauro Carvalho Chehab, Daniel W. S. Almeida

On 11/7/25 2:03 PM, Andy Shevchenko wrote:
> There are a few drivers that want to have these values, and
> one more known to come soon. Let's define the values for them.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  include/linux/units.h | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/include/linux/units.h b/include/linux/units.h
> index f626e212d4ca..5b3293bce04c 100644
> --- a/include/linux/units.h
> +++ b/include/linux/units.h
> @@ -21,6 +21,12 @@
>  #define PICO	1000000000000ULL
>  #define FEMTO	1000000000000000ULL
>  
> +/* Value of π * 10⁸ (fits s32 or signed int) */
> +#define PI	314159265

It isn't clear to me at all in the other patches that e.g.
DIV_ROUND_UP(PI, 1000) would be π ✕ 10⁴ (rounded to nearest
integer, of course).

Calling these PI_E8 and PI_E18 or PI_x10_8 and PI_x10_18
would help to clear that up.

> +
> +/* Value of π * 10¹⁸ (fits s64 or signed long long) */
> +#define PI_LL	3141592653589793238LL
> +
>  /* Hz based multipliers */
>  #define NANOHZ_PER_HZ		1000000000UL
>  #define MICROHZ_PER_HZ		1000000UL


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 2/6] units: Add 32- and 64-bit signed values of π
  2025-11-07 21:09   ` David Lechner
@ 2025-11-07 21:14     ` David Lechner
       [not found]     ` <CAHp75VexvdYyjt1GkbfqOotkFpLeb=io6outJ5dpRqBv2qPNng@mail.gmail.com>
  1 sibling, 0 replies; 11+ messages in thread
From: David Lechner @ 2025-11-07 21:14 UTC (permalink / raw)
  To: Andy Shevchenko, Hans Verkuil, linux-iio, chrome-platform,
	linux-kernel, linux-media
  Cc: Jonathan Cameron, Nuno Sá, Andy Shevchenko, Benson Leung,
	Guenter Roeck, Lars-Peter Clausen, Michael Hennerich,
	Mauro Carvalho Chehab, Daniel W. S. Almeida

On 11/7/25 3:09 PM, David Lechner wrote:
> On 11/7/25 2:03 PM, Andy Shevchenko wrote:
>> There are a few drivers that want to have these values, and
>> one more known to come soon. Let's define the values for them.
>>
>> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>> ---
>>  include/linux/units.h | 6 ++++++
>>  1 file changed, 6 insertions(+)
>>
>> diff --git a/include/linux/units.h b/include/linux/units.h
>> index f626e212d4ca..5b3293bce04c 100644
>> --- a/include/linux/units.h
>> +++ b/include/linux/units.h
>> @@ -21,6 +21,12 @@
>>  #define PICO	1000000000000ULL
>>  #define FEMTO	1000000000000000ULL
>>  
>> +/* Value of π * 10⁸ (fits s32 or signed int) */
>> +#define PI	314159265
> 
> It isn't clear to me at all in the other patches that e.g.
> DIV_ROUND_UP(PI, 1000) would be π ✕ 10⁴ (rounded to nearest

Typo. Should be DIV_ROUND_UP(PI, 10000) or  DIV_ROUND_UP(PI, 10 * KILO).

> integer, of course).
> 
> Calling these PI_E8 and PI_E18 or PI_x10_8 and PI_x10_18
> would help to clear that up.
> 
>> +
>> +/* Value of π * 10¹⁸ (fits s64 or signed long long) */
>> +#define PI_LL	3141592653589793238LL
>> +
>>  /* Hz based multipliers */
>>  #define NANOHZ_PER_HZ		1000000000UL
>>  #define MICROHZ_PER_HZ		1000000UL
> 


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 2/6] units: Add 32- and 64-bit signed values of π
       [not found]     ` <CAHp75VexvdYyjt1GkbfqOotkFpLeb=io6outJ5dpRqBv2qPNng@mail.gmail.com>
@ 2025-11-09 17:00       ` Jonathan Cameron
  2025-11-09 17:09         ` Andy Shevchenko
  0 siblings, 1 reply; 11+ messages in thread
From: Jonathan Cameron @ 2025-11-09 17:00 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: David Lechner, Andy Shevchenko, Hans Verkuil,
	linux-iio@vger.kernel.org, chrome-platform@lists.linux.dev,
	linux-kernel@vger.kernel.org, linux-media@vger.kernel.org,
	Nuno Sá, Andy Shevchenko, Benson Leung, Guenter Roeck,
	Lars-Peter Clausen, Michael Hennerich, Mauro Carvalho Chehab,
	Daniel W. S. Almeida

On Sat, 8 Nov 2025 21:02:54 +0200
Andy Shevchenko <andy.shevchenko@gmail.com> wrote:

> пʼятниця, 7 листопада 2025 р. David Lechner <dlechner@baylibre.com> пише:
> 
> > On 11/7/25 2:03 PM, Andy Shevchenko wrote:  
> > > There are a few drivers that want to have these values, and
> > > one more known to come soon. Let's define the values for them.
> > >  
> 
> 
> 
> 
> 
> > > @@ -21,6 +21,12 @@
> > >  #define PICO 1000000000000ULL
> > >  #define FEMTO        1000000000000000ULL
> > >
> > > +/* Value of π * 10⁸ (fits s32 or signed int) */
> > > +#define PI   314159265  
> >
> > It isn't clear to me at all in the other patches that e.g.
> > DIV_ROUND_UP(PI, 1000) would be π ✕ 10⁴ (rounded to nearest
> > integer, of course).
> >
> > Calling these PI_E8 and PI_E18 or PI_x10_8 and PI_x10_18
> > would help to clear that up.  
> 
> 
> 
> This will be an awful and ugly name(s). I fully disagree on such a
> proposal. The power is chosen to fit the type with maximum precision, no
> need to explain this in the name.
With no indicate of the multiplier we have to check it every time wwe
use it which isn't ideal either.

So I agree with David that we have to indicate this somewhere. Maybe hold the
multiplier in a separate define
#define PI_MUL
#define PI_MUL_LL

Then compute the divisions by (PI_MUL) / KILO or something along those lines?
> 
> >  
> > > +
> > > +/* Value of π * 10¹⁸ (fits s64 or signed long long) */
> > > +#define PI_LL        3141592653589793238LL
> > > +
> > >  /* Hz based multipliers */
> > >  #define NANOHZ_PER_HZ                1000000000UL
> > >  #define MICROHZ_PER_HZ               1000000UL  
> >
> >  


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 2/6] units: Add 32- and 64-bit signed values of π
  2025-11-09 17:00       ` Jonathan Cameron
@ 2025-11-09 17:09         ` Andy Shevchenko
  0 siblings, 0 replies; 11+ messages in thread
From: Andy Shevchenko @ 2025-11-09 17:09 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Andy Shevchenko, David Lechner, Hans Verkuil,
	linux-iio@vger.kernel.org, chrome-platform@lists.linux.dev,
	linux-kernel@vger.kernel.org, linux-media@vger.kernel.org,
	Nuno Sá, Andy Shevchenko, Benson Leung, Guenter Roeck,
	Lars-Peter Clausen, Michael Hennerich, Mauro Carvalho Chehab,
	Daniel W. S. Almeida

On Sun, Nov 09, 2025 at 05:00:32PM +0000, Jonathan Cameron wrote:
> On Sat, 8 Nov 2025 21:02:54 +0200
> Andy Shevchenko <andy.shevchenko@gmail.com> wrote:
> > пʼятниця, 7 листопада 2025 р. David Lechner <dlechner@baylibre.com> пише:
> > > On 11/7/25 2:03 PM, Andy Shevchenko wrote:  
> > > > There are a few drivers that want to have these values, and
> > > > one more known to come soon. Let's define the values for them.

...

> > > > +/* Value of π * 10⁸ (fits s32 or signed int) */
> > > > +#define PI   314159265  
> > >
> > > It isn't clear to me at all in the other patches that e.g.
> > > DIV_ROUND_UP(PI, 1000) would be π ✕ 10⁴ (rounded to nearest
> > > integer, of course).
> > >
> > > Calling these PI_E8 and PI_E18 or PI_x10_8 and PI_x10_18
> > > would help to clear that up.  
> > 
> > This will be an awful and ugly name(s). I fully disagree on such a
> > proposal. The power is chosen to fit the type with maximum precision, no
> > need to explain this in the name.
> With no indicate of the multiplier we have to check it every time wwe
> use it which isn't ideal either.
> 
> So I agree with David that we have to indicate this somewhere. Maybe hold the
> multiplier in a separate define
> #define PI_MUL
> #define PI_MUL_LL
> 
> Then compute the divisions by (PI_MUL) / KILO or something along those lines?

I see, we have a disagreement here, because I don't like to uglify the pure PI
definition. So, please abandon this series then.

> > > > +/* Value of π * 10¹⁸ (fits s64 or signed long long) */
> > > > +#define PI_LL        3141592653589793238LL

Note, this constant is used a lot in the tests (3+ modules), so if you go with
your version, take this into account.

> > > >  /* Hz based multipliers */
> > > >  #define NANOHZ_PER_HZ                1000000000UL
> > > >  #define MICROHZ_PER_HZ               1000000UL  

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2025-11-09 17:09 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-07 20:02 [PATCH v2 0/6] iio: Introduce and use value of π Andy Shevchenko
2025-11-07 20:02 ` [PATCH v2 1/6] media: vidtv: Rename PI definition to PI_SAMPLES Andy Shevchenko
2025-11-07 20:03 ` [PATCH v2 2/6] units: Add 32- and 64-bit signed values of π Andy Shevchenko
2025-11-07 21:09   ` David Lechner
2025-11-07 21:14     ` David Lechner
     [not found]     ` <CAHp75VexvdYyjt1GkbfqOotkFpLeb=io6outJ5dpRqBv2qPNng@mail.gmail.com>
2025-11-09 17:00       ` Jonathan Cameron
2025-11-09 17:09         ` Andy Shevchenko
2025-11-07 20:03 ` [PATCH v2 3/6] media: dvb-frontends: atbm8830: Convert to use PI definition Andy Shevchenko
2025-11-07 20:03 ` [PATCH v2 4/6] iio: cros_ec_sensors: " Andy Shevchenko
2025-11-07 20:03 ` [PATCH v2 5/6] iio: frequency: ad9523: " Andy Shevchenko
2025-11-07 20:03 ` [PATCH v2 6/6] iio: position: iqs624-pos: " Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).