Skip to contentSkip to conversation

math.h: Document abs_diff()

PATCH In review Andy Shevchenko 2 participants 3 messages Aug 4, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 math.h: Document abs_diff()

Initially abs_diff() has lack of documentation. Add it.

---
 include/linux/math.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)
include/linux/math.h +12 -0
index 336e3e3678e7..dfba59b59998 100644
@@ -155,6 +155,18 @@ __STRUCT_FRACT(u32)
 	__builtin_types_compatible_p(typeof(x), unsigned type),		\
 	({ signed type __x = (x); __x < 0 ? -__x : __x; }), other)
 
+/**
+ * abs_diff - return absolute value of the difference between the arguments
+ * @a: the first argument
+ * @b: the second argument
+ *
+ * @a and @b has to be of the same type. With this restriction we compare
+ * signed to signed and unsigned to unsigned. The result is the subtraction
+ * the smaller of the two from the bigger, hence result is always a positive
+ * value.
+ *
+ * Return: an absolute value of the difference between the @a and @b.
+ */
 #define abs_diff(a, b) ({			\
 	typeof(a) __a = (a);			\
 	typeof(b) __b = (b);			\
Signature · 1 line
2.40.0.1.gaa8946217a0b
#1 lore raw
Quoted 13 lines · Andy Shevchenko

Initially abs_diff() has lack of documentation. Add it.

---
 include/linux/math.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)
include/linux/math.h +0 -0
index 336e3e3678e7..dfba59b59998 100644

include/linux/math.h __STRUCT_FRACT(u32) · line 163

Quoted 9 lines
include/linux/math.h +6 -0
@@ -155,6 +155,18 @@ __STRUCT_FRACT(u32)
 	__builtin_types_compatible_p(typeof(x), unsigned type),		\
 	({ signed type __x = (x); __x < 0 ? -__x : __x; }), other)
 
+/**
+ * abs_diff - return absolute value of the difference between the arguments
+ * @a: the first argument
+ * @b: the second argument
+ *
+ * @a and @b has to be of the same type. With this restriction we compare

Preferably s/has/have/.

Quoted 9 lines
include/linux/math.h +6 -0
+ * signed to signed and unsigned to unsigned. The result is the subtraction
+ * the smaller of the two from the bigger, hence result is always a positive
+ * value.
+ *
+ * Return: an absolute value of the difference between the @a and @b.
+ */
 #define abs_diff(a, b) ({			\
 	typeof(a) __a = (a);			\
 	typeof(b) __b = (b);			\
Signature · 1 line
~Randy
#2 lore raw
Quoted 1 line · Randy Dunlap

On 8/3/23 22:09, Andy Shevchenko wrote:

...

Quoted 8 lines
Quoted 6 lines

+/**
+ * abs_diff - return absolute value of the difference between the arguments
+ * @a: the first argument
+ * @b: the second argument
+ *
+ * @a and @b has to be of the same type. With this restriction we compare

Preferably s/has/have/.

Thank you! I fixed it locally, I hope Andrew can update this, but if needed I will send a v2 with the proposed correction.

Quoted 6 lines
Quoted 6 lines

+ * signed to signed and unsigned to unsigned. The result is the subtraction
+ * the smaller of the two from the bigger, hence result is always a positive
+ * value.
+ *
+ * Return: an absolute value of the difference between the @a and @b.
+ */

Signature · 2 lines
With Best Regards,
Andy Shevchenko