1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

Add imaxdiv(3).

This commit is contained in:
Jonas 'Sortie' Termansen 2013-07-19 23:07:09 +02:00
parent a9d8712435
commit 02013158e7
3 changed files with 41 additions and 1 deletions

View file

@ -25,6 +25,7 @@ dirent/alphasort.o \
dirent/dir.o \ dirent/dir.o \
dirent/versionsort.o \ dirent/versionsort.o \
errno/errno.o \ errno/errno.o \
inttypes/imaxdiv.o \
inttypes/strtoimax.o \ inttypes/strtoimax.o \
inttypes/strtoumax.o \ inttypes/strtoumax.o \
inttypes/wcstoimax.o \ inttypes/wcstoimax.o \

View file

@ -200,8 +200,14 @@ __BEGIN_DECLS
@include(wchar_t.h) @include(wchar_t.h)
typedef struct
{
intmax_t quot;
intmax_t rem;
} imaxdiv_t;
intmax_t imaxabs(intmax_t); intmax_t imaxabs(intmax_t);
/* TODO: imaxdiv */ imaxdiv_t imaxdiv(intmax_t, intmax_t);
intmax_t strtoimax(const char* __restrict, char** __restrict, int); intmax_t strtoimax(const char* __restrict, char** __restrict, int);
uintmax_t strtoumax(const char* __restrict, char** __restrict, int); uintmax_t strtoumax(const char* __restrict, char** __restrict, int);
intmax_t wcstoimax(const wchar_t* __restrict, wchar_t** __restrict, int); intmax_t wcstoimax(const wchar_t* __restrict, wchar_t** __restrict, int);

33
libc/inttypes/imaxdiv.cpp Normal file
View file

@ -0,0 +1,33 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2013
This file is part of the Sortix C Library.
The Sortix C Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
The Sortix C Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
inttypes/imaxdiv.cpp
Compute quotient and remainder of integer division.
*******************************************************************************/
#include <inttypes.h>
extern "C" imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom)
{
imaxdiv_t ret;
ret.quot = numer / denom;
ret.rem = numer % denom;
return ret;
}