]> pd.if.org Git - pdclib/blob - functions/inttypes/imaxdiv.c
94e69e23f93c30cd4e1bf19c8ec01c1053a133e4
[pdclib] / functions / inttypes / imaxdiv.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 <inttypes.h>
10
11 #ifndef REGTEST
12
13 imaxdiv_t imaxdiv( intmax_t numer, intmax_t denom )
14 {
15     imaxdiv_t rc;
16     rc.quot = numer / denom;
17     rc.rem  = numer % denom;
18     return rc;
19 }
20
21 #endif
22
23 #ifdef TEST
24 #include <_PDCLIB_test.h>
25
26 int main( void )
27 {
28     imaxdiv_t result;
29     result = imaxdiv( (intmax_t)5, (intmax_t)2 );
30     TESTCASE( result.quot == 2 && result.rem == 1 );
31     result = imaxdiv( (intmax_t)-5, (intmax_t)2 );
32     TESTCASE( result.quot == -2 && result.rem == -1 );
33     result = imaxdiv( (intmax_t)5, (intmax_t)-2 );
34     TESTCASE( result.quot == -2 && result.rem == 1 );
35     TESTCASE( sizeof( result.quot ) == sizeof( intmax_t ) );
36     TESTCASE( sizeof( result.rem )  == sizeof( intmax_t ) );
37     return TEST_RESULTS;
38 }
39
40 #endif