aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2015-10-10 21:48:37 +0200
committerMattias Andrée <maandree@operamail.com>2015-10-10 21:48:37 +0200
commit41f350e672007ee64657b4ac67ffc95229ad841d (patch)
tree17d82455a90e1a4604a59638919cb28b893ddadc /include
parentm todo (diff)
downloadslibc-41f350e672007ee64657b4ac67ffc95229ad841d.tar.gz
slibc-41f350e672007ee64657b4ac67ffc95229ad841d.tar.bz2
slibc-41f350e672007ee64657b4ac67ffc95229ad841d.tar.xz
add abs, labs, llabs, and imaxabs
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'include')
-rw-r--r--include/inttypes.h14
-rw-r--r--include/stdlib.h43
2 files changed, 57 insertions, 0 deletions
diff --git a/include/inttypes.h b/include/inttypes.h
index 3f24e9b..4530fef 100644
--- a/include/inttypes.h
+++ b/include/inttypes.h
@@ -40,6 +40,20 @@
imaxdiv_t imaxdiv(intmax_t, intmax_t)
__GCC_ONLY(__attribute__((const)));
+/**
+ * Return the absolute value of an integer.
+ *
+ * Be aware, if the value is `INTMAX_MIN` and
+ * `-INTMAX_MAX != -INTMAX_MIN`, the result will
+ * overflow, and `INTMAX_MIN` will (probably)
+ * be returned.
+ *
+ * @param value The integer.
+ * @return The absolute value of the integer.
+ */
+intmax_t imaxabs(intmax_t)
+ __GCC_ONLY(__attribute__((const)));
+
#endif
diff --git a/include/stdlib.h b/include/stdlib.h
index 8d65597..4fba1a0 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -93,6 +93,49 @@ lldiv_t lldiv(long long, long long)
__GCC_ONLY(__attribute__((const)));
+/**
+ * Return the absolute value of an integer.
+ *
+ * Be aware, if the value is `INT_MIN` and
+ * `-INT_MAX != -INT_MIN`, the result will
+ * overflow, and `INT_MIN` will (probably)
+ * be returned.
+ *
+ * @param value The integer.
+ * @return The absolute value of the integer.
+ */
+int abs(int)
+ __GCC_ONLY(__attribute__((const)));
+
+/**
+ * Return the absolute value of an integer.
+ *
+ * Be aware, if the value is `LONG_MIN` and
+ * `-LONG_MAX != -LONG_MIN`, the result will
+ * overflow, and `LONG_MIN` will (probably)
+ * be returned.
+ *
+ * @param value The integer.
+ * @return The absolute value of the integer.
+ */
+long int labs(long int)
+ __GCC_ONLY(__attribute__((const)));
+
+/**
+ * Return the absolute value of an integer.
+ *
+ * Be aware, if the value is `LLONG_MIN` and
+ * `-LLONG_MAX != -LLONG_MIN`, the result will
+ * overflow, and `LLONG_MIN` will (probably)
+ * be returned.
+ *
+ * @param value The integer.
+ * @return The absolute value of the integer.
+ */
+long long int llabs(long long int)
+ __GCC_ONLY(__attribute__((const)));
+
+
#if !defined(__PORTABLE)
/**
* Get the absolute path of a file.