Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/waterbox/libc/functions/stdlib/ldiv.c
2 views
1
/* ldiv( long int, 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 <stdlib.h>
8
9
#ifndef REGTEST
10
11
ldiv_t ldiv( long int numer, long int denom )
12
{
13
ldiv_t rc;
14
rc.quot = numer / denom;
15
rc.rem = numer % denom;
16
/* TODO: pre-C99 compilers might require modulus corrections */
17
return rc;
18
}
19
20
#endif
21
22
#ifdef TEST
23
#include "_PDCLIB_test.h"
24
25
int main( void )
26
{
27
ldiv_t result;
28
result = ldiv( 5, 2 );
29
TESTCASE( result.quot == 2 && result.rem == 1 );
30
result = ldiv( -5, 2 );
31
TESTCASE( result.quot == -2 && result.rem == -1 );
32
result = ldiv( 5, -2 );
33
TESTCASE( result.quot == -2 && result.rem == 1 );
34
TESTCASE( sizeof( result.quot ) == sizeof( long ) );
35
TESTCASE( sizeof( result.rem ) == sizeof( long ) );
36
return TEST_RESULTS;
37
}
38
39
#endif
40
41