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

Add div(3), ldiv(3) and lldiv(3).

This commit is contained in:
Jonas 'Sortie' Termansen 2013-03-19 08:59:26 +01:00
parent c26cb897a0
commit 2630c7cb4e
5 changed files with 122 additions and 5 deletions

View file

@ -30,6 +30,7 @@ c++.o \
ctime.o \
ctype.o \
dir.o \
div.o \
errno.o \
fabs.o \
fbufsize.o \
@ -69,6 +70,8 @@ gmtime.o \
gmtime_r.o \
heap.o \
integer.o \
ldiv.o \
lldiv.o \
localtime.o \
localtime_r.o \
mbrtowc.o \

33
libc/div.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/>.
div.cpp
Compute quotient and remainder of integer division.
*******************************************************************************/
#include <stdlib.h>
extern "C" div_t div(int numer, int denom)
{
div_t ret;
ret.quot = numer / denom;
ret.rem = numer % denom;
return ret;
}

View file

@ -39,8 +39,23 @@ __BEGIN_DECLS
/* TODO: This is just a value. It's not a compile time constant! */
#define MB_CUR_MAX 16
/* TODO: div_t, ldiv_t, and lldiv_t is missing here */
typedef int div_t, ldiv_t, lldiv_t;
typedef struct
{
int quot;
int rem;
} div_t;
typedef struct
{
long quot;
long rem;
} ldiv_t;
typedef struct
{
long long quot;
long long rem;
} lldiv_t;
@include(NULL.h)
@include(size_t.h)
@ -54,11 +69,14 @@ long atol(const char*);
long long atoll(const char*);
void* bsearch(const void*, const void*, size_t, size_t, int (*)(const void*, const void*));
void* calloc(size_t, size_t);
div_t div(int, int);
void exit(int) __attribute__ ((noreturn));
void _Exit(int status) __attribute__ ((noreturn));
void free(void*);
long labs(long);
ldiv_t ldiv(long, long);
long long llabs(long long);
lldiv_t lldiv(long long, long long);
void* malloc(size_t);
int mbtowc(wchar_t *restrict, const char* restrict, size_t);
#if !defined(_SORTIX_SOURCE)
@ -99,7 +117,6 @@ int clearenv(void);
#if defined(__SORTIX_SHOW_UNIMPLEMENTED)
long a64l(const char* s);
double atof(const char* value);
div_t div(int, int);
double drand48(void);
double erand48(unsigned short [3]);
int getsubopt(char**, char* const *, char**);
@ -108,8 +125,6 @@ char* initstate(unsigned, char*, size_t);
long jrand48(unsigned short [3]);
char* l64a(long);
void lcong48(unsigned short [7]);
ldiv_t ldiv(long, long);
lldiv_t lldiv(long long, long long);
long lrand48(void);
int mblen(const char*, size_t);
size_t mbstowcs(wchar_t *restrict, const char* restrict, size_t);

33
libc/ldiv.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/>.
ldiv.cpp
Compute quotient and remainder of integer division.
*******************************************************************************/
#include <stdlib.h>
extern "C" ldiv_t ldiv(long numer, long denom)
{
ldiv_t ret;
ret.quot = numer / denom;
ret.rem = numer % denom;
return ret;
}

33
libc/lldiv.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/>.
lldiv.cpp
Compute quotient and remainder of integer division.
*******************************************************************************/
#include <stdlib.h>
extern "C" lldiv_t lldiv(long long numer, long long denom)
{
lldiv_t ret;
ret.quot = numer / denom;
ret.rem = numer % denom;
return ret;
}