From: batt Date: Fri, 2 Apr 2010 09:56:44 +0000 (+0000) Subject: DIV_ROUNDUP: new macro. X-Git-Tag: 2.5.0~529 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=cba26286807ebe6b31c31d165677271de0417def;p=bertos.git DIV_ROUNDUP: new macro. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3379 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/cfg/macros.h b/bertos/cfg/macros.h index 4f77b21e..caa2340f 100644 --- a/bertos/cfg/macros.h +++ b/bertos/cfg/macros.h @@ -182,6 +182,13 @@ */ #define DIV_ROUND(dividend, divisor) (((dividend) + (divisor) / 2) / (divisor)) +/** + * Perform an integer division rounding the result to the upper int value. + * \note \a divisor should preferibly be a costant, otherwise this macro generates + * 2 division. Also divisor is evaluated twice. + */ +#define DIV_ROUNDUP(dividend, divisor) (((dividend) + (divisor) - 1) / (divisor)) + /** Round up \a x to an even multiple of the 2's power \a pad. */ #define ROUND_UP2(x, pad) (((x) + ((pad) - 1)) & ~((pad) - 1))