diff --git a/CMakeLists.txt b/CMakeLists.txt index 84fdb18..64155cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,6 +77,9 @@ set(SOURCES src/libc/ctype/toupper.c # errno src/libc/errno/errno.c + # inttypes + src/libc/inttypes/imaxabs.c + src/libc/inttypes/imaxdiv.c # locale src/libc/locale/setlocale.c src/libc/locale/localeconv.c diff --git a/STATUS b/STATUS index 10e883b..99f24af 100644 --- a/STATUS +++ b/STATUS @@ -47,8 +47,8 @@ DONE: Function/symbol/macro is defined, builds, links, and is tested 7.8 7.8.1 PRI* macros: LDEPS(*printf) 7.8.1 SCN* macros: LDEPS(*scanf) - 7.8.2.1 imaxabs: TODO - 7.8.2.2 imaxdiv: TODO + 7.8.2.1 imaxabs: TEST + 7.8.2.2 imaxdiv: TEST 7.8.2.3 strotimax strtoumax: TODO 7.8.2.4 wcstoimax wcstoumax: TODO diff --git a/include/inttypes.h b/include/inttypes.h index d430c36..076b3f0 100644 --- a/include/inttypes.h +++ b/include/inttypes.h @@ -2,6 +2,7 @@ # define __INTTYPES_H__ #include +#include /* Hide by default in C++ (7.8.1ยง1.181) */ #if !defined __cplusplus || defined __STDC_FORMAT_MACROS @@ -231,4 +232,15 @@ #endif /* !defined __cplusplus || defined __STDC_FORMAT_MACROS */ +/* Return type of imaxdiv. */ +typedef lldiv_t imaxdiv_t; + +/* Absolue value of an intmax_t. */ +extern intmax_t imaxabs(intmax_t __j); +#define imaxabs llabs + +/* Integer division of intmax_t. */ +extern imaxdiv_t imaxdiv(intmax_t __num, intmax_t __denom); +#define imaxdiv lldiv + #endif /*__INTTYPES_H__*/ diff --git a/src/libc/inttypes/imaxabs.c b/src/libc/inttypes/imaxabs.c new file mode 100644 index 0000000..4986448 --- /dev/null +++ b/src/libc/inttypes/imaxabs.c @@ -0,0 +1,8 @@ +#include +#include +#undef imaxabs + +intmax_t imaxabs(intmax_t j) +{ + return llabs(j); +} diff --git a/src/libc/inttypes/imaxdiv.c b/src/libc/inttypes/imaxdiv.c new file mode 100644 index 0000000..f009a8a --- /dev/null +++ b/src/libc/inttypes/imaxdiv.c @@ -0,0 +1,8 @@ +#include +#include +#undef imaxdiv + +imaxdiv_t imaxdiv(intmax_t num, intmax_t denom) +{ + return lldiv(num, denom); +}