imaxabs Function

Compute the absolute value.

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

#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