[PATCH v6 3/5] units: add conversion macros for percentage related units

Jonathan Santos posted 5 patches 3 weeks, 4 days ago
[PATCH v6 3/5] units: add conversion macros for percentage related units
Posted by Jonathan Santos 3 weeks, 4 days ago
Add macros to convert between ratio and percentage related units,
including percent (1/100), permille (1/1,000), permyriad (1/10,000,
also equivalent to one Basis point) and per cent mille (1/100,000).
Those are  Used for precise fractional calculations in engineering,
finance, and measurement applications.

Signed-off-by: Jonathan Santos <Jonathan.Santos@analog.com>
---
v6 Changes:
* Use Pattern PER* for all percentage-related macros. BASIS_POINTS is now
  PERMYRIAD.
* Include macros for Per mille and per cent mille units.

v5 Changes:
* Included PERCENT macro along with BASIS_POINTS.
* Adjusted commit description and comment in the code to add more context and
  examples.

v4 Changes:
* New patch.
---
 include/linux/units.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/include/linux/units.h b/include/linux/units.h
index 00e15de33eca..3471c5a38dcf 100644
--- a/include/linux/units.h
+++ b/include/linux/units.h
@@ -21,6 +21,25 @@
 #define PICO	1000000000000ULL
 #define FEMTO	1000000000000000ULL
 
+/*
+ * Percentage and related scaling units
+ *
+ * These macros define scaling factors used to convert between ratio and
+ * percentage-based representations with different decimal resolutions.
+ * They are used for precise fractional calculations in engineering, finance,
+ * and measurement applications.
+ *
+ * Examples:
+ *   1%     = 0.01    = 1 / PERCENT
+ *   0.1%   = 0.001   = 1 / PERMILLE
+ *   0.01%  = 0.0001  = 1 / PERMYRIAD (1 basis point)
+ *   0.001% = 0.00001 = 1 / PERCENTMILLE
+ */
+#define PERCENT		100
+#define PERMILLE	1000
+#define PERMYRIAD	10000
+#define PERCENTMILLE	100000
+
 #define NANOHZ_PER_HZ		1000000000UL
 #define MICROHZ_PER_HZ		1000000UL
 #define MILLIHZ_PER_HZ		1000UL
-- 
2.34.1
Re: [PATCH v6 3/5] units: add conversion macros for percentage related units
Posted by Andy Shevchenko 2 weeks, 6 days ago
On Wed, Jan 14, 2026 at 06:27:03AM -0300, Jonathan Santos wrote:
> Add macros to convert between ratio and percentage related units,
> including percent (1/100), permille (1/1,000), permyriad (1/10,000,
> also equivalent to one Basis point) and per cent mille (1/100,000).
> Those are  Used for precise fractional calculations in engineering,
> finance, and measurement applications.

This version LGTM,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v6 3/5] units: add conversion macros for percentage related units
Posted by Andy Shevchenko 2 weeks, 6 days ago
On Mon, Jan 19, 2026 at 09:54:42AM +0200, Andy Shevchenko wrote:
> On Wed, Jan 14, 2026 at 06:27:03AM -0300, Jonathan Santos wrote:
> > Add macros to convert between ratio and percentage related units,
> > including percent (1/100), permille (1/1,000), permyriad (1/10,000,
> > also equivalent to one Basis point) and per cent mille (1/100,000).
> > Those are  Used for precise fractional calculations in engineering,
> > finance, and measurement applications.
> 
> This version LGTM,
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>

FWIW, we have one dup
drivers/net/wireless/realtek/rtw89/phy.h:93:#define PERCENT 100

But since the type and value is the same it can be addressed later on.

-- 
With Best Regards,
Andy Shevchenko