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

From: Markus Wichmann <nullplan_AT_gmx.net>
Date: Wed, 25 Jun 2014 06:36:26 +0200

On Tue, Jun 24, 2014 at 07:32:10PM +0200, FRIGN wrote:
> We are dealing with floats with at most 2 decimal places. I propose we
> just go for
>
> CEIL(x) ((int)(x) + ((x) > 0 && (int)(x) != (x)))
>

Well, if we know that much already then the easiest to read version
would be:

#define CEIL(x) ((int)(x >= 0? x + .99 : x))

And done! That should returns 3 when anything between 2.01 and 3.01 is
entered (excluding the upper boundary).

Alternatively:

#define INSIGNIFICANT 1e-2 /* values and differences below this don't matter */
#define CEIL(x) ((int)(x >= 0? x + 1 - INSIGNIFICANT : x))

That's easier to adjust.

Ciao,
Markus
Received on Wed Jun 25 2014 - 06:36:26 CEST

This archive was generated by hypermail 2.3.0 : Wed Jun 25 2014 - 06:48:06 CEST