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

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

On Tue, Jun 24, 2014 at 5:03 PM, FRIGN <dev_AT_frign.de> wrote:
> On Tue, 24 Jun 2014 09:46:33 -0500
> Eric Pruitt <eric.pruitt_AT_gmail.com> wrote:
>
>> CEIL(x) ((int)(x) + ((x) > 0))
>>
>> Perhaps I'm missing something here, but this completely fails whenever
>> (x) is already a whole number; CEIL(3.0) => 4.0 which is not the correct
>> behaviour.
>
> Damn, you are right -.-. Back to the drawing board.
>

True.
Hence, and following other sources about this topic [0], I suggest

#define CEIL(x) ((int)(x) + ((int)(x) > 0) * ((x - (int)(x)) > FLT_EPSILON))

cheers!
mar77i

[0] http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
Received on Tue Jun 24 2014 - 17:16:08 CEST

This archive was generated by hypermail 2.3.0 : Tue Jun 24 2014 - 17:24:11 CEST