]> pd.if.org Git - pdclib/blob - functions/inttypes/imaxdiv.c
PDCLib includes with quotes, not <>.
[pdclib] / functions / inttypes / imaxdiv.c
1 /* lldiv( long long int, long long int )
2
3    This file is part of the Public Domain C Library (PDCLib).
4    Permission is granted to use, modify, and / or redistribute at will.
5 */
6
7 #include <inttypes.h>
8
9 #ifndef REGTEST
10
11 imaxdiv_t imaxdiv( intmax_t numer, intmax_t denom )
12 {
13     imaxdiv_t rc;
14     rc.quot = numer / denom;
15     rc.rem  = numer % denom;
16     return rc;
17 }
18
19 #endif
20
21 #ifdef TEST
22 #include "_PDCLIB_test.h"
23
24 int main( void )
25 {
26     imaxdiv_t result;
27     result = imaxdiv( (intmax_t)5, (intmax_t)2 );
28     TESTCASE( result.quot == 2 && result.rem == 1 );
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     TESTCASE( sizeof( result.quot ) == sizeof( intmax_t ) );
34     TESTCASE( sizeof( result.rem )  == sizeof( intmax_t ) );
35     return TEST_RESULTS;
36 }
37
38 #endif