X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Finttypes%2Fimaxabs.c;fp=functions%2Finttypes%2Fimaxabs.c;h=9beda2bb527d04c99a0ca732f0d927ae0224e019;hb=fde75f89eae541144585db53ce3f7c29d069b4d2;hp=0000000000000000000000000000000000000000;hpb=268c42b566c2be8deaf4c9c8571d3d2e23bae92d;p=pdclib diff --git a/functions/inttypes/imaxabs.c b/functions/inttypes/imaxabs.c new file mode 100755 index 0000000..9beda2b --- /dev/null +++ b/functions/inttypes/imaxabs.c @@ -0,0 +1,32 @@ +/* $Id$ */ + +/* imaxabs( intmax_t ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include + +#ifndef REGTEST + +intmax_t imaxabs( intmax_t j ) +{ + return ( j >= 0 ) ? j : -j; +} + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> +#include + +int main( void ) +{ + TESTCASE( imaxabs( (intmax_t)0 ) == 0 ); + TESTCASE( imaxabs( INTMAX_MAX ) == INTMAX_MAX ); + TESTCASE( imaxabs( INTMAX_MIN + 1 ) == -( INTMAX_MIN + 1 ) ); + return TEST_RESULTS; +} + +#endif