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