From 56f09fa03da99cc34620c9d3569a3d06e5c95c11 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 16 Jun 2019 18:22:45 +0200 Subject: common: add macro for checking whether a value is a power of two I think I repeated this inline in some places (or maybe not), and some experimental but discarded code used it. Add it anyway, maybe it'll be useful. Or it'll give someone a chance to get a contribution into mpv by removing an unused macro. --- common/common.h | 1 + 1 file changed, 1 insertion(+) diff --git a/common/common.h b/common/common.h index f5392fc575..16e1ec4cfd 100644 --- a/common/common.h +++ b/common/common.h @@ -44,6 +44,7 @@ #define MP_ALIGN_UP(x, align) (((x) + (align) - 1) & ~((align) - 1)) #define MP_ALIGN_DOWN(x, align) ((x) & ~((align) - 1)) #define MP_IS_ALIGNED(x, align) (!((x) & ((align) - 1))) +#define MP_IS_POWER_OF_2(x) ((x) > 0 && !((x) & ((x) - 1))) // Return "a", or if that is NOPTS, return "def". #define MP_PTS_OR_DEF(a, def) ((a) == MP_NOPTS_VALUE ? (def) : (a)) -- cgit v1.2.3