On Tue, Jun 24, 2014 at 5:03 PM, FRIGN <d...@frign.de> wrote:
> On Tue, 24 Jun 2014 09:46:33 -0500
> Eric Pruitt <eric.pru...@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/

Reply via email to