[vlc-devel] [PATCH 1/3] vlc_common.h: add helpers to get the upper rounded value of integer divisions
Steve Lhomme
robux4 at gmail.com
Fri Mar 17 10:14:27 CET 2017
On Fri, Mar 17, 2017 at 9:46 AM, Rémi Denis-Courmont <remi at remlab.net> wrote:
> On March 17, 2017 4:36:08 PM GMT+08:00, Steve Lhomme <robux4 at videolabs.io> wrote:
>>---
>> include/vlc_common.h | 5 +++++
>> 1 file changed, 5 insertions(+)
>>
>>diff --git a/include/vlc_common.h b/include/vlc_common.h
>>index 6a75753dbf..b72dbfe689 100644
>>--- a/include/vlc_common.h
>>+++ b/include/vlc_common.h
>>@@ -507,6 +507,11 @@ struct vlc_common_members
>> /* clip v in [min, max] */
>> #define VLC_CLIP(v, min, max) __MIN(__MAX((v), (min)), (max))
>>
>>+/* upper rounded value of the integer division */
>>+#define VLC_UPPER_DIV(v, div) (((v) + (div) - 1) / (div))
>>+/* upper modulo value of the integer */
>>+#define VLC_UPPER_MODULO(v, mod) (VLC_UPPER_DIV(v, mod) * mod)
>>+
>> VLC_USED
>> static inline int64_t GCD ( int64_t a, int64_t b )
>> {
>>--
>>2.11.1
>>
>>_______________________________________________
>>vlc-devel mailing list
>>To unsubscribe or modify your subscription options:
>>https://mailman.videolan.org/listinfo/vlc-devel
>
> I don't like expansion-unsafe functional macros, TBH. They've bitten too many asses too many times, so to speak.
Reading on the subject, it seems the position of the parenthesis
matters (!). Would this be ok ?
#define VLC_UPPER_MODULO(v, mod) ((mod) * VLC_UPPER_DIV(v, mod))
or probably better
#define VLC_UPPER_MODULO(v, mod) ((v) + (v)%(mod))
> --
> Rémi Denis-Courmont
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
More information about the vlc-devel
mailing list