]> pd.if.org Git - pdclib/blob - functions/stdlib/lldiv.c
Removed the $Name$ tags (not supported by SVN). Added $Id$ to Makefile / text files.
[pdclib] / functions / stdlib / lldiv.c
1 /* $Id$ */
2
3 /* lldiv( long long int, long long int )
4
5    This file is part of the Public Domain C Library (PDCLib).
6    Permission is granted to use, modify, and / or redistribute at will.
7 */
8
9 #include <stdlib.h>
10
11 #ifndef REGTEST
12
13 lldiv_t lldiv( long long int numer, long long int denom )
14 {
15     lldiv_t rc;
16     rc.quot = numer / denom;
17     rc.rem  = numer % denom;
18     /* TODO: pre-C99 compilers might require modulus corrections */
19     return rc;
20 }
21
22 #endif
23
24 #ifdef TEST
25 #include <_PDCLIB_test.h>
26
27 #ifndef _PDCLIB_CONFIG_H
28 #include <_PDCLIB_config.h>
29 #endif
30
31 int main( void )
32 {
33     lldiv_t result;
34     result = lldiv( 5ll, 2ll );
35     TESTCASE( result.quot == 2 && result.rem == 1 );
36     result = lldiv( -5ll, 2ll );
37     TESTCASE( result.quot == -2 && result.rem == -1 );
38     result = lldiv( 5ll, -2ll );
39     TESTCASE( result.quot == -2 && result.rem == 1 );
40     TESTCASE( sizeof( result.quot ) == _PDCLIB_LLONG_BYTES );
41     TESTCASE( sizeof( result.rem )  == _PDCLIB_LLONG_BYTES );
42     return TEST_RESULTS;
43 }
44
45 #endif