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

From: Martti Kühne <mysatyre_AT_gmail.com>
Date: Tue, 24 Jun 2014 09:13:11 +0200

On Tue, Jun 24, 2014 at 8:50 AM, Roberto E. Vargas Caballero
<k0ga_AT_shike2.com> wrote:
> CEIL(x) ((int) (x) + ((x) > 0 ? 1.0 : 0.0))
>
> Positive:
> CEIL(3.3) => 3 + (3.3 > 0 ? 1.0 : 0.0) => 4.0
>
> Negative:
> CEIL(-3.3) => -3 + (-3.3 > 0 ? 1.0 : 0.0) => -3
>

here's a shorter equivalent:

#define CEIL(x) ((int)(x) + ((x) > 0))

cheers!
mar77i
Received on Tue Jun 24 2014 - 09:13:11 CEST

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