From: bernie Date: Mon, 27 Jun 2005 21:23:32 +0000 (+0000) Subject: ROUND_DOWN, ROUND_UP, ROUND_NEAREST: New macros. X-Git-Tag: 1.0.0~828 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;ds=inline;h=8c8d2df610762e52e41e7d6f94f0d1c185841ae8;hp=13ec95fc46065b689287f537b61f2e6607be1653;p=bertos.git ROUND_DOWN, ROUND_UP, ROUND_NEAREST: New macros. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@413 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/cfg/macros.h b/cfg/macros.h index 6dd62487..d33ee401 100755 --- a/cfg/macros.h +++ b/cfg/macros.h @@ -14,6 +14,9 @@ /*#* *#* $Log$ + *#* Revision 1.3 2005/06/27 21:23:32 bernie + *#* ROUND_DOWN, ROUND_UP, ROUND_NEAREST: New macros. + *#* *#* Revision 1.2 2005/04/11 19:10:27 bernie *#* Include top-level headers from cfg/ subdir. *#* @@ -139,6 +142,17 @@ /*! Round up \a x to an even multiple of the 2's power \a pad */ #define ROUND2(x, pad) (((x) + ((pad) - 1)) & ~((pad) - 1)) +/*! + * Integer round macros. + * Round \a x to a multiple of \a base. + * \note If \a x is signed these macros generate a lot of code. + * \{ + */ +#define ROUND_DOWN(x, base) ( (x) - ((x) % (base)) ) +#define ROUND_UP(x, base) ( ((x) + (base) - 1) - (((x) + (base) - 1) % (base)) ) +#define ROUND_NEAREST(x, base) ( ((x) + (base) / 2) - (((x) + (base) / 2) % (base)) ) +/* \} */ + //! Check if \a x is an integer power of 2 #define IS_POW2(x) (!(bool)((x) & ((x)-1)))