From 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 7 Apr 2024 13:41:34 -0500 Subject: new repository --- devdocs/c/numeric%2Fmath%2Fabs.html | 53 +++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 devdocs/c/numeric%2Fmath%2Fabs.html (limited to 'devdocs/c/numeric%2Fmath%2Fabs.html') diff --git a/devdocs/c/numeric%2Fmath%2Fabs.html b/devdocs/c/numeric%2Fmath%2Fabs.html new file mode 100644 index 00000000..8564aeff --- /dev/null +++ b/devdocs/c/numeric%2Fmath%2Fabs.html @@ -0,0 +1,53 @@ +

abs, labs, llabs, imaxabs

Defined in header <stdlib.h>
int        abs( int n );
+
long       labs( long n );
+
long long llabs( long long n );
+
(since C99)
Defined in header <inttypes.h>
intmax_t imaxabs( intmax_t n );
+
(since C99)

Computes the absolute value of an integer number. The behavior is undefined if the result cannot be represented by the return type.

+

Parameters

+ +
n - integer value

Return value

The absolute value of n (i.e. |n|), if it is representable.

+

Notes

In 2's complement systems, the absolute value of the most-negative value is out of range, e.g. for 32-bit 2's complement type int, INT_MIN is -2147483648, but the would-be result 2147483648 is greater than INT_MAX, which is 2147483647.

+

Example

#include <stdio.h>
+#include <stdlib.h>
+#include <limits.h>
+ 
+int main(void)
+{
+    printf("abs(+3) = %d\n", abs(+3));
+    printf("abs(-3) = %d\n", abs(-3));
+ 
+//  printf("%+d\n", abs(INT_MIN)); // undefined behavior on 2's complement systems
+}

Output:

+
abs(+3) = 3
+abs(-3) = 3

References

See also

+ + +
+
(C99)(C99)
computes absolute value of a floating-point value (\(\small{|x|}\)|x|)
(function)
+
(C99)(C99)(C99)
computes the magnitude of a complex number
(function)
C++ documentation for abs
+

+ © cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
+ https://en.cppreference.com/w/c/numeric/math/abs +

+
-- cgit v1.2.3