1/*
2** Copyright 2004, Axel D��rfler, axeld@pinc-software.de. All rights reserved.
3** Distributed under the terms of the MIT License.
4*/
5
6
7#include <inttypes.h>
8#include <stdlib.h>
9
10
11intmax_t
12imaxabs(intmax_t number)
13{
14	return number > 0 ? number : -number;
15}
16
17
18imaxdiv_t
19imaxdiv(intmax_t numer, intmax_t denom)
20{
21	imaxdiv_t result;
22
23	result.quot = numer / denom;
24	result.rem = numer % denom;
25
26	if (numer >= 0 && result.rem < 0) {
27		result.quot++;
28		result.rem -= denom;
29	}
30
31	return result;
32}
33
34
35intmax_t
36strtoimax(const char *string, char **_end, int base)
37{
38	return (intmax_t)strtoll(string, _end, base);
39}
40
41
42uintmax_t
43strtoumax(const char *string, char **_end, int base)
44{
45	return (intmax_t)strtoull(string, _end, base);
46}
47
48