6.7.6 imaxabs Function
Calculate the absolute value of a greatest-width integer.
Include
<inttypes.h>
Prototype
intmax_t imaxabs(intmax_t j);
Argument
j
- The value whose absolute value is required.
Return Value
The imaxabs
function computes the absolute value of an integer
j
.
Remarks
If the result cannot be represented, the behavior is undefined. The absolute value of the most negative number cannot be represented in two's compliment.
Example
See the notes at the beginning of this chapter or section for
information on using printf()
or scanf()
(and other functions reading and writing the stdin
or
stdout
streams) in the example code.
#include <inttypes.h>
#include <stdio.h>
int main(void)
{
intmax_t val;
val = -10000;
printf("The absolute value of %" PRIdMAX " is %" PRIdMAX "\n", val, imaxabs(val));
}
Example Output
The absolute value of -10000 is 10000