inttypes: add imaxabs and imaxdiv (TEST)

This commit is contained in:
Lephenixnoir 2021-05-18 21:30:14 +02:00
parent 73b536bbb6
commit 36b4854137
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
5 changed files with 33 additions and 2 deletions

View File

@ -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

4
STATUS
View File

@ -47,8 +47,8 @@ DONE: Function/symbol/macro is defined, builds, links, and is tested
7.8 <inttypes.h>
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

View File

@ -2,6 +2,7 @@
# define __INTTYPES_H__
#include <stdint.h>
#include <stdlib.h>
/* 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__*/

View File

@ -0,0 +1,8 @@
#include <inttypes.h>
#include <stdlib.h>
#undef imaxabs
intmax_t imaxabs(intmax_t j)
{
return llabs(j);
}

View File

@ -0,0 +1,8 @@
#include <inttypes.h>
#include <stdlib.h>
#undef imaxdiv
imaxdiv_t imaxdiv(intmax_t num, intmax_t denom)
{
return lldiv(num, denom);
}