Add div(3), ldiv(3) and lldiv(3).
This commit is contained in:
parent
c26cb897a0
commit
2630c7cb4e
|
@ -30,6 +30,7 @@ c++.o \
|
||||||
ctime.o \
|
ctime.o \
|
||||||
ctype.o \
|
ctype.o \
|
||||||
dir.o \
|
dir.o \
|
||||||
|
div.o \
|
||||||
errno.o \
|
errno.o \
|
||||||
fabs.o \
|
fabs.o \
|
||||||
fbufsize.o \
|
fbufsize.o \
|
||||||
|
@ -69,6 +70,8 @@ gmtime.o \
|
||||||
gmtime_r.o \
|
gmtime_r.o \
|
||||||
heap.o \
|
heap.o \
|
||||||
integer.o \
|
integer.o \
|
||||||
|
ldiv.o \
|
||||||
|
lldiv.o \
|
||||||
localtime.o \
|
localtime.o \
|
||||||
localtime_r.o \
|
localtime_r.o \
|
||||||
mbrtowc.o \
|
mbrtowc.o \
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -39,8 +39,23 @@ __BEGIN_DECLS
|
||||||
/* TODO: This is just a value. It's not a compile time constant! */
|
/* TODO: This is just a value. It's not a compile time constant! */
|
||||||
#define MB_CUR_MAX 16
|
#define MB_CUR_MAX 16
|
||||||
|
|
||||||
/* TODO: div_t, ldiv_t, and lldiv_t is missing here */
|
typedef struct
|
||||||
typedef int div_t, ldiv_t, lldiv_t;
|
{
|
||||||
|
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(NULL.h)
|
||||||
@include(size_t.h)
|
@include(size_t.h)
|
||||||
|
@ -54,11 +69,14 @@ long atol(const char*);
|
||||||
long long atoll(const char*);
|
long long atoll(const char*);
|
||||||
void* bsearch(const void*, const void*, size_t, size_t, int (*)(const void*, const void*));
|
void* bsearch(const void*, const void*, size_t, size_t, int (*)(const void*, const void*));
|
||||||
void* calloc(size_t, size_t);
|
void* calloc(size_t, size_t);
|
||||||
|
div_t div(int, int);
|
||||||
void exit(int) __attribute__ ((noreturn));
|
void exit(int) __attribute__ ((noreturn));
|
||||||
void _Exit(int status) __attribute__ ((noreturn));
|
void _Exit(int status) __attribute__ ((noreturn));
|
||||||
void free(void*);
|
void free(void*);
|
||||||
long labs(long);
|
long labs(long);
|
||||||
|
ldiv_t ldiv(long, long);
|
||||||
long long llabs(long long);
|
long long llabs(long long);
|
||||||
|
lldiv_t lldiv(long long, long long);
|
||||||
void* malloc(size_t);
|
void* malloc(size_t);
|
||||||
int mbtowc(wchar_t *restrict, const char* restrict, size_t);
|
int mbtowc(wchar_t *restrict, const char* restrict, size_t);
|
||||||
#if !defined(_SORTIX_SOURCE)
|
#if !defined(_SORTIX_SOURCE)
|
||||||
|
@ -99,7 +117,6 @@ int clearenv(void);
|
||||||
#if defined(__SORTIX_SHOW_UNIMPLEMENTED)
|
#if defined(__SORTIX_SHOW_UNIMPLEMENTED)
|
||||||
long a64l(const char* s);
|
long a64l(const char* s);
|
||||||
double atof(const char* value);
|
double atof(const char* value);
|
||||||
div_t div(int, int);
|
|
||||||
double drand48(void);
|
double drand48(void);
|
||||||
double erand48(unsigned short [3]);
|
double erand48(unsigned short [3]);
|
||||||
int getsubopt(char**, char* const *, char**);
|
int getsubopt(char**, char* const *, char**);
|
||||||
|
@ -108,8 +125,6 @@ char* initstate(unsigned, char*, size_t);
|
||||||
long jrand48(unsigned short [3]);
|
long jrand48(unsigned short [3]);
|
||||||
char* l64a(long);
|
char* l64a(long);
|
||||||
void lcong48(unsigned short [7]);
|
void lcong48(unsigned short [7]);
|
||||||
ldiv_t ldiv(long, long);
|
|
||||||
lldiv_t lldiv(long long, long long);
|
|
||||||
long lrand48(void);
|
long lrand48(void);
|
||||||
int mblen(const char*, size_t);
|
int mblen(const char*, size_t);
|
||||||
size_t mbstowcs(wchar_t *restrict, const char* restrict, size_t);
|
size_t mbstowcs(wchar_t *restrict, const char* restrict, size_t);
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
Loading…
Reference in New Issue