X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstdlib%2Flldiv.c;h=731a316223d84c5639d4562963708ee30a140dd9;hb=d02f38605b53cdff5460cc6b9e1b2a80c3a2ba4c;hp=349ff2b0a8b78fa5173100e1a43db79e169c4b7e;hpb=3645cf5a3d3d1344b7863b5202a2d107c0f1964b;p=pdclib diff --git a/functions/stdlib/lldiv.c b/functions/stdlib/lldiv.c index 349ff2b..731a316 100644 --- a/functions/stdlib/lldiv.c +++ b/functions/stdlib/lldiv.c @@ -17,7 +17,7 @@ lldiv_t lldiv( long long int numer, long long int denom ) lldiv_t rc; rc.quot = numer / denom; rc.rem = numer % denom; - /* TODO */ + /* TODO: pre-C99 compilers might require modulus corrections */ return rc; } @@ -26,11 +26,21 @@ lldiv_t lldiv( long long int numer, long long int denom ) #ifdef TEST #include <_PDCLIB_test.h> -int main() +#ifndef _PDCLIB_CONFIG_H +#include <_PDCLIB_config.h> +#endif + +int main( void ) { - int NO_TESTDRIVER = 0; - BEGIN_TESTS; - TESTCASE( NO_TESTDRIVER ); + lldiv_t result; + result = lldiv( 5ll, 2ll ); + TESTCASE( result.quot == 2 && result.rem == 1 ); + result = lldiv( -5ll, 2ll ); + TESTCASE( result.quot == -2 && result.rem == -1 ); + result = lldiv( 5ll, -2ll ); + TESTCASE( result.quot == -2 && result.rem == 1 ); + TESTCASE( sizeof( result.quot ) == _PDCLIB_LLONG_BYTES ); + TESTCASE( sizeof( result.rem ) == _PDCLIB_LLONG_BYTES ); return TEST_RESULTS; }