summaryrefslogtreecommitdiff
path: root/src/inttypes/imaxabs.c
blob: 4f8202391c4602be789e55c91a534e36b169a290 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <inttypes.h>

intmax_t imaxabs(intmax_t j)
{
  /* returns the absolute value of j */
  /* if imaxabs(j) can't be representeted (i.e. imaxabs(INTMAX_MIN), behavior is undefined */
/*
  if (j == INTMAX_MIN) {
    __ungol_libc_undefined("Cannot represent absolute value of %" PRIxMAX "\n", j);
  }
*/
	if (j == INTMAX_MIN) {
		/* undefined behavior */
		return INTMAX_MIN;
	}
	
	if (j < 0) {
		return -j;
	}

	return j;
}


/*
STDC(199901)
*/