]> pd.if.org Git - pdclib/blob - functions/stdlib/ldiv.c
Removed the $Name$ tags (not supported by SVN). Added $Id$ to Makefile / text files.
[pdclib] / functions / stdlib / ldiv.c
1 /* $Id$ */
2
3 /* ldiv( long int, 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 ldiv_t ldiv( long int numer, long int denom )
14 {
15     ldiv_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     ldiv_t result;
34     result = ldiv( 5, 2 );
35     TESTCASE( result.quot == 2 && result.rem == 1 );
36     result = ldiv( -5, 2 );
37     TESTCASE( result.quot == -2 && result.rem == -1 );
38     result = ldiv( 5, -2 );
39     TESTCASE( result.quot == -2 && result.rem == 1 );
40     TESTCASE( sizeof( result.quot ) == _PDCLIB_LONG_BYTES );
41     TESTCASE( sizeof( result.rem )  == _PDCLIB_LONG_BYTES );
42     return TEST_RESULTS;
43 }
44
45 #endif