X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstdlib%2Flldiv.c;h=731a316223d84c5639d4562963708ee30a140dd9;hb=12e17136786afb1775c9dc946cbe41f5e230c24a;hp=349ff2b0a8b78fa5173100e1a43db79e169c4b7e;hpb=d46bc9c98e97ede90e62ee31c66951d80a9848f3;p=pdclib.old 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; }