Re: [dev] [st] [PATCH] Explicit cast in CEIL macro

From: Martti Kühne <mysatyre_AT_gmail.com>
Date: Tue, 24 Jun 2014 16:08:58 +0200

On Tue, Jun 24, 2014 at 3:19 PM, FRIGN <dev_AT_frign.de> wrote:
> On Tue, 24 Jun 2014 09:13:11 +0200
> Martti Kühne <mysatyre_AT_gmail.com> wrote:
>
>> #define CEIL(x) ((int)(x) + ((x) > 0))
>
> Martti, you definitely are a candidate for the best macro-hack of
> 2014 ;).
>


Here's another one. Non-branching sign extraction...
#define SGN(x) (2 * ((x) > 0) - 1)

More food for thought in [0]

cheers!
mar77i

[0] https://graphics.stanford.edu/~seander/bithacks.html
Received on Tue Jun 24 2014 - 16:08:58 CEST

This archive was generated by hypermail 2.3.0 : Tue Jun 24 2014 - 16:12:06 CEST